From 1350c77193f939e40deea8101cf8fd6befde4abe Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Fri, 29 Dec 2017 16:07:55 -0500 Subject: [PATCH 01/11] Issues #10559 -Extend swatch using mixins For Magento 2.2 --- .../templates/product/listing/renderer.phtml | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml b/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml index 75a39a0e4e270..7e4115034ccf9 100644 --- a/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml +++ b/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml @@ -5,36 +5,33 @@ */ ?> -
- - priceBoxes.priceBox({ - 'priceConfig': { - priceFormat: jsonConfig.priceFormat, - prices: jsonConfig.prices + From 33261e0b5096a249a0bd0a239a4c2b9f4cbfdc0c Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Fri, 29 Dec 2017 16:13:26 -0500 Subject: [PATCH 02/11] Add new element attribute querySelectorAll - Selector cannot be integer --- app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php b/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php index f370c49cdfa20..afa4519954900 100644 --- a/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php +++ b/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php @@ -116,6 +116,7 @@ protected function wrapResult($html) return '
' . $html . '
'; } From 4fca69d21b15a2614d3df11cfc51bbaba0217c4f Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Fri, 29 Dec 2017 16:16:35 -0500 Subject: [PATCH 03/11] Add new JSON method --- .../Product/Renderer/Listing/Configurable.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/code/Magento/Swatches/Block/Product/Renderer/Listing/Configurable.php b/app/code/Magento/Swatches/Block/Product/Renderer/Listing/Configurable.php index 6a42ad1cc9849..bd2b24dbed630 100644 --- a/app/code/Magento/Swatches/Block/Product/Renderer/Listing/Configurable.php +++ b/app/code/Magento/Swatches/Block/Product/Renderer/Listing/Configurable.php @@ -66,6 +66,25 @@ public function getJsonConfig() $this->unsetData('allow_products'); return parent::getJsonConfig(); } + + /** + * Composes configuration for js price format + * + * @return string + */ + public function getPriceFormatJson(){ + return $this->jsonEncoder->encode($this->localeFormat->getPriceFormat()); + } + + + /** + * Composes configuration for js price + * + * @return string + */ + public function getPricesJson(){ + return $this->jsonEncoder->encode($this->getPrices()); + } /** * Do not load images for Configurable product with swatches due to its loaded by request From 97779a63eb34d72f82a34ba430cd37b7356f9b9c Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Fri, 29 Dec 2017 16:23:37 -0500 Subject: [PATCH 04/11] Refactor code for JSON config --- .../Block/Product/View/Type/Configurable.php | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php index b5d02f64e6eb5..198b114197587 100644 --- a/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php @@ -67,7 +67,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView /** * @var Format */ - private $localeFormat; + protected $localeFormat; /** * @var Session @@ -211,9 +211,6 @@ public function getJsonConfig() $store = $this->getCurrentStore(); $currentProduct = $this->getProduct(); - $regularPrice = $currentProduct->getPriceInfo()->getPrice('regular_price'); - $finalPrice = $currentProduct->getPriceInfo()->getPrice('final_price'); - $options = $this->helper->getOptions($currentProduct, $this->getAllowProducts()); $attributesData = $this->configurableAttributeData->getAttributesData($currentProduct, $options); @@ -223,17 +220,7 @@ public function getJsonConfig() 'currencyFormat' => $store->getCurrentCurrency()->getOutputFormat(), 'optionPrices' => $this->getOptionPrices(), 'priceFormat' => $this->localeFormat->getPriceFormat(), - 'prices' => [ - 'oldPrice' => [ - 'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getValue()), - ], - 'basePrice' => [ - 'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getBaseAmount()), - ], - 'finalPrice' => [ - 'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getValue()), - ], - ], + 'prices' => $this->getPrices(), 'productId' => $currentProduct->getId(), 'chooseText' => __('Choose an Option...'), 'images' => $this->getOptionImages(), @@ -248,6 +235,32 @@ public function getJsonConfig() return $this->jsonEncoder->encode($config); } + + + /** + * Get product prices for configurable variations + * + * @return array + * @since 100.2.0 + */ + protected function getPrices(){ + $currentProduct = $this->getProduct(); + + $regularPrice = $currentProduct->getPriceInfo()->getPrice('regular_price'); + $finalPrice = $currentProduct->getPriceInfo()->getPrice('final_price'); + + return [ + 'oldPrice' => [ + 'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getValue()), + ], + 'basePrice' => [ + 'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getBaseAmount()), + ], + 'finalPrice' => [ + 'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getValue()), + ], + ]; + } /** * Get product images for configurable variations From 494c9c08a1c9491f211f6d234308fc0a7d9f8d31 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Fri, 29 Dec 2017 18:42:12 -0500 Subject: [PATCH 05/11] Update renderer.phtml --- .../view/frontend/templates/product/listing/renderer.phtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml b/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml index 7e4115034ccf9..7462f5f2bca13 100644 --- a/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml +++ b/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml @@ -25,11 +25,11 @@