9
9
10
10
use Magento \Authorization \Model \UserContextInterface ;
11
11
use Magento \Catalog \Api \Data \ProductCustomOptionInterface ;
12
+ use Magento \Catalog \Model \Config \Source \ProductPriceOptionsInterface ;
12
13
use Magento \Catalog \Model \Product \Option \Type \DefaultType as DefaultOptionType ;
13
14
use Magento \Catalog \Model \Product \Option \Type \Select as SelectOptionType ;
14
15
use Magento \Catalog \Model \Product \Option \Type \Text as TextOptionType ;
18
19
use Magento \Framework \GraphQl \Query \ResolverInterface ;
19
20
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
20
21
use Magento \Quote \Model \Quote \Item as QuoteItem ;
22
+ use Magento \Store \Api \Data \StoreInterface ;
23
+ use Magento \Store \Model \Store ;
24
+ use Magento \Store \Model \StoreManagerInterface ;
21
25
22
26
/**
23
27
* {@inheritdoc}
24
28
*/
25
29
class CustomizableOptions implements ResolverInterface
26
30
{
31
+ /**
32
+ * @var StoreManagerInterface
33
+ */
34
+ private $ storeManager ;
35
+
27
36
/**
28
37
* @var ValueFactory
29
38
*/
@@ -37,13 +46,16 @@ class CustomizableOptions implements ResolverInterface
37
46
/**
38
47
* @param ValueFactory $valueFactory
39
48
* @param UserContextInterface $userContext
49
+ * @param StoreManagerInterface $storeManager
40
50
*/
41
51
public function __construct (
42
52
ValueFactory $ valueFactory ,
43
- UserContextInterface $ userContext
53
+ UserContextInterface $ userContext ,
54
+ StoreManagerInterface $ storeManager
44
55
) {
45
56
$ this ->valueFactory = $ valueFactory ;
46
57
$ this ->userContext = $ userContext ;
58
+ $ this ->storeManager = $ storeManager ;
47
59
}
48
60
49
61
/**
@@ -134,9 +146,11 @@ private function getOptionData($cartItem, int $optionId): array
134
146
|| ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX == $ option ->getType ()
135
147
) {
136
148
$ optionValue = $ option ->getValueById ($ itemOption ->getValue ());
149
+ $ priceValueUnits = $ this ->getPriceValueUnits ($ optionValue ->getPriceType ());
150
+
137
151
$ selectedOptionValueData ['price ' ] = [
138
152
'type ' => strtoupper ($ optionValue ->getPriceType ()),
139
- 'units ' => ' $ ' ,
153
+ 'units ' => $ priceValueUnits ,
140
154
'value ' => $ optionValue ->getPrice (),
141
155
];
142
156
@@ -148,9 +162,11 @@ private function getOptionData($cartItem, int $optionId): array
148
162
|| ProductCustomOptionInterface::OPTION_GROUP_DATE == $ option ->getType ()
149
163
|| ProductCustomOptionInterface::OPTION_TYPE_TIME == $ option ->getType ()
150
164
) {
165
+ $ priceValueUnits = $ this ->getPriceValueUnits ($ option ->getPriceType ());
166
+
151
167
$ selectedOptionValueData ['price ' ] = [
152
168
'type ' => strtoupper ($ option ->getPriceType ()),
153
- 'units ' => ' $ ' ,
169
+ 'units ' => $ priceValueUnits ,
154
170
'value ' => $ option ->getPrice (),
155
171
];
156
172
@@ -163,13 +179,14 @@ private function getOptionData($cartItem, int $optionId): array
163
179
164
180
foreach ($ optionIds as $ optionId ) {
165
181
$ optionValue = $ option ->getValueById ($ optionId );
182
+ $ priceValueUnits = $ this ->getPriceValueUnits ($ optionValue ->getPriceType ());
166
183
167
184
$ selectedOptionValueData [] = [
168
185
'id ' => $ itemOption ->getId (),
169
186
'label ' => $ optionValue ->getTitle (),
170
187
'price ' => [
171
188
'type ' => strtoupper ($ optionValue ->getPriceType ()),
172
- 'units ' => ' $ ' ,
189
+ 'units ' => $ priceValueUnits ,
173
190
'value ' => $ optionValue ->getPrice (),
174
191
],
175
192
];
@@ -184,4 +201,29 @@ private function getOptionData($cartItem, int $optionId): array
184
201
'sort_order ' => $ option ->getSortOrder (),
185
202
];
186
203
}
204
+
205
+ /**
206
+ * @param string $priceType
207
+ */
208
+ private function getPriceValueUnits (string $ priceType ): string
209
+ {
210
+ if (ProductPriceOptionsInterface::VALUE_PERCENT == $ priceType ) {
211
+ return '% ' ;
212
+ }
213
+
214
+ return $ this ->getCurrencySymbol ();
215
+ }
216
+
217
+ /**
218
+ * Get currency symbol
219
+ *
220
+ * @return string
221
+ */
222
+ private function getCurrencySymbol (): string
223
+ {
224
+ /** @var Store|StoreInterface $store */
225
+ $ store = $ this ->storeManager ->getStore ();
226
+
227
+ return $ store ->getBaseCurrency ()->getCurrencySymbol ();
228
+ }
187
229
}
0 commit comments