From df344ea877e84ba6fe4bfc0900a8ae88a3c29cff Mon Sep 17 00:00:00 2001 From: LeanderFS <leander@iolabs.nl> Date: Tue, 18 Jan 2022 16:27:53 +0100 Subject: [PATCH 1/2] Fixed issue where dynamic JS price updates for tier prices wouldn't update when catalog price display was set to either Excluding or Including/Excluding tax --- .../Magento/Catalog/Block/Product/View.php | 13 +++++++++- .../Catalog/Pricing/Price/TierPrice.php | 2 +- .../Catalog/view/base/web/js/price-box.js | 24 ++++++++++++------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Product/View.php b/app/code/Magento/Catalog/Block/Product/View.php index e24b3d881bdf8..7524ceb23d931 100644 --- a/app/code/Magento/Catalog/Block/Product/View.php +++ b/app/code/Magento/Catalog/Block/Product/View.php @@ -183,8 +183,19 @@ public function getJsonConfig() foreach ($tierPricesList as $tierPrice) { $tierPriceData = [ 'qty' => $tierPrice['price_qty'], - 'price' => $tierPrice['website_price'], + 'price' => $tierPrice['website_price'] ]; + + if ( + isset($tierPrice['excl_tax_price']) && + $tierPrice['excl_tax_price'] instanceof \Magento\Framework\Pricing\Amount\AmountInterface + ) { + $tierPriceData['excl_tax_price'] = + $this->priceCurrency->convertAndRound( + $tierPrice['excl_tax_price']->getValue(['tax']) + ); + } + $tierPrices[] = $tierPriceData; } diff --git a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php index aee0ab643547a..69f388041b160 100644 --- a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php @@ -176,7 +176,7 @@ public function getTierPriceList() function (&$priceData) { /* convert string value to float */ $priceData['price_qty'] *= 1; - if ($this->getConfigTaxDisplayType() === Config::DISPLAY_TYPE_BOTH) { + if ($this->getConfigTaxDisplayType() !== Config::DISPLAY_TYPE_INCLUDING_TAX) { $exclTaxPrice = $this->calculator->getAmount($priceData['price'], $this->product); $priceData['excl_tax_price'] = $exclTaxPrice; } diff --git a/app/code/Magento/Catalog/view/base/web/js/price-box.js b/app/code/Magento/Catalog/view/base/web/js/price-box.js index 7028e42cc4597..aa54ebc00cdc3 100644 --- a/app/code/Magento/Catalog/view/base/web/js/price-box.js +++ b/app/code/Magento/Catalog/view/base/web/js/price-box.js @@ -224,23 +224,31 @@ define([ */ updateProductTierPrice: function updateProductTierPrice() { var productQty = $(this.qtyInfo).val(), - originalPrice = this.options.prices.finalPrice.amount, tierPrice, - prices, + tierPriceExcl, i; for (i = 0; i < this.options.priceConfig.tierPrices.length; i++) { if (productQty >= this.options.priceConfig.tierPrices[i].qty) { tierPrice = this.options.priceConfig.tierPrices[i].price; + tierPriceExcl = this.options.priceConfig.tierPrices[i].excl_tax_price; } } - prices = { - 'prices': { - 'finalPrice': { - 'amount': tierPrice - originalPrice - } - } + + var prices = { + 'prices': {} }; + + _.each(this.options.prices, function (priceType, index) { + var tierPriceType = index === 'basePrice' && tierPriceExcl ? + tierPriceExcl : + tierPrice; + + prices['prices'][index] = { + amount: tierPriceType - priceType.amount + }; + }); + this.updatePrice(prices); } }); From abc7e6c03ff7dfd8dc753e32d4c17f57e1c9ef7c Mon Sep 17 00:00:00 2001 From: LeanderFS <leander@iolabs.nl> Date: Wed, 19 Jan 2022 09:13:36 +0100 Subject: [PATCH 2/2] Updated getConfigTaxDisplayType to retrieve the value based on the website scope instead of only default scope so it will also work with multi-store environments. --- app/code/Magento/Catalog/Pricing/Price/TierPrice.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php index 69f388041b160..5c9d8f5cba666 100644 --- a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php @@ -18,6 +18,7 @@ use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\Pricing\PriceInfoInterface; use Magento\Customer\Model\Group\RetrieverInterface as CustomerGroupRetrieverInterface; +use Magento\Store\Model\ScopeInterface; use Magento\Tax\Model\Config; /** @@ -195,7 +196,7 @@ function (&$priceData) { */ private function getConfigTaxDisplayType(): int { - return (int) $this->scopeConfig->getValue(self::XML_PATH_TAX_DISPLAY_TYPE); + return (int) $this->scopeConfig->getValue(self::XML_PATH_TAX_DISPLAY_TYPE, ScopeInterface::SCOPE_WEBSITE); } /**