99
1010use Magento \ConfigurableProduct \Model \ConfigurableAttributeData ;
1111use Magento \Customer \Helper \Session \CurrentCustomer ;
12+ use Magento \Framework \App \ObjectManager ;
13+ use Magento \Framework \Locale \Format ;
1214use Magento \Framework \Pricing \PriceCurrencyInterface ;
1315
1416/**
@@ -59,6 +61,11 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
5961 */
6062 protected $ configurableAttributeData ;
6163
64+ /**
65+ * @var Format
66+ */
67+ private $ localeFormat ;
68+
6269 /**
6370 * @param \Magento\Catalog\Block\Product\Context $context
6471 * @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
@@ -69,6 +76,8 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
6976 * @param PriceCurrencyInterface $priceCurrency
7077 * @param ConfigurableAttributeData $configurableAttributeData
7178 * @param array $data
79+ * @param Format|null $localeFormat
80+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
7281 */
7382 public function __construct (
7483 \Magento \Catalog \Block \Product \Context $ context ,
@@ -79,14 +88,17 @@ public function __construct(
7988 CurrentCustomer $ currentCustomer ,
8089 PriceCurrencyInterface $ priceCurrency ,
8190 ConfigurableAttributeData $ configurableAttributeData ,
82- array $ data = []
91+ array $ data = [],
92+ Format $ localeFormat = null
8393 ) {
8494 $ this ->priceCurrency = $ priceCurrency ;
8595 $ this ->helper = $ helper ;
8696 $ this ->jsonEncoder = $ jsonEncoder ;
8797 $ this ->catalogProduct = $ catalogProduct ;
8898 $ this ->currentCustomer = $ currentCustomer ;
8999 $ this ->configurableAttributeData = $ configurableAttributeData ;
100+ $ this ->localeFormat = $ localeFormat ?: ObjectManager::getInstance ()->get (Format::class);
101+
90102 parent ::__construct (
91103 $ context ,
92104 $ arrayUtils ,
@@ -197,17 +209,16 @@ public function getJsonConfig()
197209 'template ' => str_replace ('%s ' , '<%- data.price %> ' , $ store ->getCurrentCurrency ()->getOutputFormat ()),
198210 'currencyFormat ' => $ store ->getCurrentCurrency ()->getOutputFormat (),
199211 'optionPrices ' => $ this ->getOptionPrices (),
212+ 'priceFormat ' => $ this ->localeFormat ->getPriceFormat (),
200213 'prices ' => [
201214 'oldPrice ' => [
202- 'amount ' => $ this ->_registerJsPrice ($ regularPrice ->getAmount ()->getValue ()),
215+ 'amount ' => $ this ->localeFormat -> getNumber ($ regularPrice ->getAmount ()->getValue ()),
203216 ],
204217 'basePrice ' => [
205- 'amount ' => $ this ->_registerJsPrice (
206- $ finalPrice ->getAmount ()->getBaseAmount ()
207- ),
218+ 'amount ' => $ this ->localeFormat ->getNumber ($ finalPrice ->getAmount ()->getBaseAmount ()),
208219 ],
209220 'finalPrice ' => [
210- 'amount ' => $ this ->_registerJsPrice ($ finalPrice ->getAmount ()->getValue ()),
221+ 'amount ' => $ this ->localeFormat -> getNumber ($ finalPrice ->getAmount ()->getValue ()),
211222 ],
212223 ],
213224 'productId ' => $ currentProduct ->getId (),
@@ -238,26 +249,28 @@ protected function getOptionPrices()
238249 $ tierPricesList = $ tierPriceModel ->getTierPriceList ();
239250 foreach ($ tierPricesList as $ tierPrice ) {
240251 $ 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+ ),
244257 ];
245258 }
246259
247260 $ prices [$ product ->getId ()] =
248261 [
249262 'oldPrice ' => [
250- 'amount ' => $ this ->_registerJsPrice (
263+ 'amount ' => $ this ->localeFormat -> getNumber (
251264 $ priceInfo ->getPrice ('regular_price ' )->getAmount ()->getValue ()
252265 ),
253266 ],
254267 'basePrice ' => [
255- 'amount ' => $ this ->_registerJsPrice (
268+ 'amount ' => $ this ->localeFormat -> getNumber (
256269 $ priceInfo ->getPrice ('final_price ' )->getAmount ()->getBaseAmount ()
257270 ),
258271 ],
259272 'finalPrice ' => [
260- 'amount ' => $ this ->_registerJsPrice (
273+ 'amount ' => $ this ->localeFormat -> getNumber (
261274 $ priceInfo ->getPrice ('final_price ' )->getAmount ()->getValue ()
262275 ),
263276 ],
@@ -270,6 +283,7 @@ protected function getOptionPrices()
270283 /**
271284 * Replace ',' on '.' for js
272285 *
286+ * @deprecated Will be removed in major release
273287 * @param float $price
274288 * @return string
275289 */
0 commit comments