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