9
9
10
10
use Magento \ConfigurableProduct \Model \ConfigurableAttributeData ;
11
11
use Magento \Customer \Helper \Session \CurrentCustomer ;
12
+ use Magento \Framework \App \ObjectManager ;
13
+ use Magento \Framework \Locale \Format ;
12
14
use Magento \Framework \Pricing \PriceCurrencyInterface ;
13
15
14
16
/**
@@ -59,6 +61,11 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
59
61
*/
60
62
protected $ configurableAttributeData ;
61
63
64
+ /**
65
+ * @var Format
66
+ */
67
+ private $ localeFormat ;
68
+
62
69
/**
63
70
* @param \Magento\Catalog\Block\Product\Context $context
64
71
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
@@ -69,6 +76,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
69
76
* @param PriceCurrencyInterface $priceCurrency
70
77
* @param ConfigurableAttributeData $configurableAttributeData
71
78
* @param array $data
79
+ * @param Format|null $localeFormat
72
80
*/
73
81
public function __construct (
74
82
\Magento \Catalog \Block \Product \Context $ context ,
@@ -79,14 +87,17 @@ public function __construct(
79
87
CurrentCustomer $ currentCustomer ,
80
88
PriceCurrencyInterface $ priceCurrency ,
81
89
ConfigurableAttributeData $ configurableAttributeData ,
82
- array $ data = []
90
+ array $ data = [],
91
+ Format $ localeFormat = null
83
92
) {
84
93
$ this ->priceCurrency = $ priceCurrency ;
85
94
$ this ->helper = $ helper ;
86
95
$ this ->jsonEncoder = $ jsonEncoder ;
87
96
$ this ->catalogProduct = $ catalogProduct ;
88
97
$ this ->currentCustomer = $ currentCustomer ;
89
98
$ this ->configurableAttributeData = $ configurableAttributeData ;
99
+ $ this ->localeFormat = $ localeFormat ?: ObjectManager::getInstance ()->get (Format::class);
100
+
90
101
parent ::__construct (
91
102
$ context ,
92
103
$ arrayUtils ,
@@ -197,17 +208,16 @@ public function getJsonConfig()
197
208
'template ' => str_replace ('%s ' , '<%- data.price %> ' , $ store ->getCurrentCurrency ()->getOutputFormat ()),
198
209
'currencyFormat ' => $ store ->getCurrentCurrency ()->getOutputFormat (),
199
210
'optionPrices ' => $ this ->getOptionPrices (),
211
+ 'priceFormat ' => $ this ->localeFormat ->getPriceFormat (),
200
212
'prices ' => [
201
213
'oldPrice ' => [
202
- 'amount ' => $ this ->_registerJsPrice ($ regularPrice ->getAmount ()->getValue ()),
214
+ 'amount ' => $ this ->localeFormat -> getNumber ($ regularPrice ->getAmount ()->getValue ()),
203
215
],
204
216
'basePrice ' => [
205
- 'amount ' => $ this ->_registerJsPrice (
206
- $ finalPrice ->getAmount ()->getBaseAmount ()
207
- ),
217
+ 'amount ' => $ this ->localeFormat ->getNumber ($ finalPrice ->getAmount ()->getBaseAmount ()),
208
218
],
209
219
'finalPrice ' => [
210
- 'amount ' => $ this ->_registerJsPrice ($ finalPrice ->getAmount ()->getValue ()),
220
+ 'amount ' => $ this ->localeFormat -> getNumber ($ finalPrice ->getAmount ()->getValue ()),
211
221
],
212
222
],
213
223
'productId ' => $ currentProduct ->getId (),
@@ -238,26 +248,28 @@ protected function getOptionPrices()
238
248
$ tierPricesList = $ tierPriceModel ->getTierPriceList ();
239
249
foreach ($ tierPricesList as $ tierPrice ) {
240
250
$ tierPrices [] = [
241
- 'qty ' => $ this ->_registerJsPrice ($ tierPrice ['price_qty ' ]),
242
- 'price ' => $ this ->_registerJsPrice ($ tierPrice ['price ' ]->getValue ()),
243
- 'percentage ' => $ this ->_registerJsPrice ($ tierPriceModel ->getSavePercent ($ tierPrice ['price ' ])),
251
+ 'qty ' => $ this ->localeFormat ->getNumber ($ tierPrice ['price_qty ' ]),
252
+ 'price ' => $ this ->localeFormat ->getNumber ($ tierPrice ['price ' ]->getValue ()),
253
+ 'percentage ' => $ this ->localeFormat ->getNumber (
254
+ $ tierPriceModel ->getSavePercent ($ tierPrice ['price ' ])
255
+ ),
244
256
];
245
257
}
246
258
247
259
$ prices [$ product ->getId ()] =
248
260
[
249
261
'oldPrice ' => [
250
- 'amount ' => $ this ->_registerJsPrice (
262
+ 'amount ' => $ this ->localeFormat -> getNumber (
251
263
$ priceInfo ->getPrice ('regular_price ' )->getAmount ()->getValue ()
252
264
),
253
265
],
254
266
'basePrice ' => [
255
- 'amount ' => $ this ->_registerJsPrice (
267
+ 'amount ' => $ this ->localeFormat -> getNumber (
256
268
$ priceInfo ->getPrice ('final_price ' )->getAmount ()->getBaseAmount ()
257
269
),
258
270
],
259
271
'finalPrice ' => [
260
- 'amount ' => $ this ->_registerJsPrice (
272
+ 'amount ' => $ this ->localeFormat -> getNumber (
261
273
$ priceInfo ->getPrice ('final_price ' )->getAmount ()->getValue ()
262
274
),
263
275
],
@@ -270,6 +282,7 @@ protected function getOptionPrices()
270
282
/**
271
283
* Replace ',' on '.' for js
272
284
*
285
+ * @deprecated Will be removed in major release
273
286
* @param float $price
274
287
* @return string
275
288
*/
0 commit comments