Skip to content

Commit ff460af

Browse files
author
Sergey Semenov
committed
MAGETWO-47017: [Github] Add Configurable Product To Cart from Category Page #2574 #5850 #5882 #6572 #5558 #4184
1 parent e8397f2 commit ff460af

File tree

3 files changed

+421
-24
lines changed

3 files changed

+421
-24
lines changed

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Magento\ConfigurableProduct\Model\ConfigurableAttributeData;
1111
use Magento\Customer\Helper\Session\CurrentCustomer;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\Locale\Format;
1214
use 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,7 @@ 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
7280
*/
7381
public function __construct(
7482
\Magento\Catalog\Block\Product\Context $context,
@@ -79,14 +87,17 @@ public function __construct(
7987
CurrentCustomer $currentCustomer,
8088
PriceCurrencyInterface $priceCurrency,
8189
ConfigurableAttributeData $configurableAttributeData,
82-
array $data = []
90+
array $data = [],
91+
Format $localeFormat = null
8392
) {
8493
$this->priceCurrency = $priceCurrency;
8594
$this->helper = $helper;
8695
$this->jsonEncoder = $jsonEncoder;
8796
$this->catalogProduct = $catalogProduct;
8897
$this->currentCustomer = $currentCustomer;
8998
$this->configurableAttributeData = $configurableAttributeData;
99+
$this->localeFormat = $localeFormat ?: ObjectManager::getInstance()->get(Format::class);
100+
90101
parent::__construct(
91102
$context,
92103
$arrayUtils,
@@ -197,17 +208,16 @@ public function getJsonConfig()
197208
'template' => str_replace('%s', '<%- data.price %>', $store->getCurrentCurrency()->getOutputFormat()),
198209
'currencyFormat' => $store->getCurrentCurrency()->getOutputFormat(),
199210
'optionPrices' => $this->getOptionPrices(),
211+
'priceFormat' => $this->localeFormat->getPriceFormat(),
200212
'prices' => [
201213
'oldPrice' => [
202-
'amount' => $this->_registerJsPrice($regularPrice->getAmount()->getValue()),
214+
'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getValue()),
203215
],
204216
'basePrice' => [
205-
'amount' => $this->_registerJsPrice(
206-
$finalPrice->getAmount()->getBaseAmount()
207-
),
217+
'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getBaseAmount()),
208218
],
209219
'finalPrice' => [
210-
'amount' => $this->_registerJsPrice($finalPrice->getAmount()->getValue()),
220+
'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getValue()),
211221
],
212222
],
213223
'productId' => $currentProduct->getId(),
@@ -238,26 +248,28 @@ protected function getOptionPrices()
238248
$tierPricesList = $tierPriceModel->getTierPriceList();
239249
foreach ($tierPricesList as $tierPrice) {
240250
$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+
),
244256
];
245257
}
246258

247259
$prices[$product->getId()] =
248260
[
249261
'oldPrice' => [
250-
'amount' => $this->_registerJsPrice(
262+
'amount' => $this->localeFormat->getNumber(
251263
$priceInfo->getPrice('regular_price')->getAmount()->getValue()
252264
),
253265
],
254266
'basePrice' => [
255-
'amount' => $this->_registerJsPrice(
267+
'amount' => $this->localeFormat->getNumber(
256268
$priceInfo->getPrice('final_price')->getAmount()->getBaseAmount()
257269
),
258270
],
259271
'finalPrice' => [
260-
'amount' => $this->_registerJsPrice(
272+
'amount' => $this->localeFormat->getNumber(
261273
$priceInfo->getPrice('final_price')->getAmount()->getValue()
262274
),
263275
],
@@ -270,6 +282,7 @@ protected function getOptionPrices()
270282
/**
271283
* Replace ',' on '.' for js
272284
*
285+
* @deprecated Will be removed in major release
273286
* @param float $price
274287
* @return string
275288
*/

0 commit comments

Comments
 (0)