Skip to content

Commit f08c409

Browse files
committed
ACP2E-291: Excl.Tax Tier Price issue on QTY Change
1 parent 83f3d01 commit f08c409

File tree

5 files changed

+92
-67
lines changed

5 files changed

+92
-67
lines changed

app/code/Magento/Catalog/Block/Product/View.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
namespace Magento\Catalog\Block\Product;
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
9-
use Magento\Catalog\Model\Category;
9+
use Magento\Tax\Model\Config;
10+
use Magento\Framework\App\ObjectManager;
1011

1112
/**
1213
* Product View block
@@ -64,6 +65,11 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
6465
*/
6566
protected $productRepository;
6667

68+
/**
69+
* @var Config|null
70+
*/
71+
private $taxConfig;
72+
6773
/**
6874
* @param Context $context
6975
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
@@ -76,6 +82,7 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
7682
* @param ProductRepositoryInterface|\Magento\Framework\Pricing\PriceCurrencyInterface $productRepository
7783
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
7884
* @param array $data
85+
* @param Config|null $taxConfig
7986
* @codingStandardsIgnoreStart
8087
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8188
*/
@@ -90,7 +97,8 @@ public function __construct(
9097
\Magento\Customer\Model\Session $customerSession,
9198
ProductRepositoryInterface $productRepository,
9299
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
93-
array $data = []
100+
array $data = [],
101+
Config $taxConfig = null
94102
) {
95103
$this->_productHelper = $productHelper;
96104
$this->urlEncoder = $urlEncoder;
@@ -101,6 +109,7 @@ public function __construct(
101109
$this->customerSession = $customerSession;
102110
$this->productRepository = $productRepository;
103111
$this->priceCurrency = $priceCurrency;
112+
$this->taxConfig = $taxConfig ?: ObjectManager::getInstance()->get(Config::class);
104113
parent::__construct(
105114
$context,
106115
$data
@@ -181,9 +190,14 @@ public function getJsonConfig()
181190
$priceInfo = $product->getPriceInfo();
182191
$tierPricesList = $priceInfo->getPrice('tier_price')->getTierPriceList();
183192
foreach ($tierPricesList as $tierPrice) {
193+
$price = $tierPrice['price']->getValue();
194+
if ($this->taxConfig->getPriceDisplayType() === Config::DISPLAY_TYPE_EXCLUDING_TAX) {
195+
$price = $tierPrice['price']->getBaseAmount();
196+
}
184197
$tierPriceData = [
185198
'qty' => $tierPrice['price_qty'],
186-
'price' => $tierPrice['website_price'],
199+
'price' => $price,
200+
'excl_tax_price' => $tierPrice['price']->getBaseAmount()
187201
];
188202
$tierPrices[] = $tierPriceData;
189203
}

app/code/Magento/Catalog/Pricing/Price/TierPrice.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Magento\Framework\Pricing\PriceCurrencyInterface;
1919
use Magento\Framework\Pricing\PriceInfoInterface;
2020
use Magento\Customer\Model\Group\RetrieverInterface as CustomerGroupRetrieverInterface;
21-
use Magento\Tax\Model\Config;
2221

2322
/**
2423
* @api
@@ -176,13 +175,6 @@ public function getTierPriceList()
176175
function (&$priceData) {
177176
/* convert string value to float */
178177
$priceData['price_qty'] *= 1;
179-
$exclTaxPrice = $this->calculator->getAmount($priceData['price'], $this->product);
180-
if ($this->getConfigTaxDisplayType() === Config::DISPLAY_TYPE_EXCLUDING_TAX) {
181-
$priceData['excl_tax_price'] = $exclTaxPrice;
182-
}
183-
if ($this->getConfigTaxDisplayType() === Config::DISPLAY_TYPE_BOTH) {
184-
$priceData['incl_excl_tax_price'] = $exclTaxPrice;
185-
}
186178
$priceData['price'] = $this->applyAdjustment($priceData['price']);
187179
}
188180
);
@@ -191,16 +183,6 @@ function (&$priceData) {
191183
return $this->priceList;
192184
}
193185

194-
/**
195-
* Returns config tax display type
196-
*
197-
* @return int
198-
*/
199-
private function getConfigTaxDisplayType(): int
200-
{
201-
return (int) $this->scopeConfig->getValue(self::XML_PATH_TAX_DISPLAY_TYPE);
202-
}
203-
204186
/**
205187
* Filters tier prices
206188
*

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,27 +220,39 @@ define([
220220
},
221221

222222
/**
223-
* Updates product final price according to tier prices
223+
* Updates product final and base price according to tier prices
224224
*/
225225
updateProductTierPrice: function updateProductTierPrice() {
226226
var productQty = $(this.qtyInfo).val(),
227-
originalPrice = this.options.prices.finalPrice.amount,
228227
tierPrice,
229-
prices,
228+
prices = {'prices': {}},
230229
i;
231230

232-
for (i = 0; i < this.options.priceConfig.tierPrices.length; i++) {
233-
if (productQty >= this.options.priceConfig.tierPrices[i].qty) {
234-
tierPrice = this.options.priceConfig.tierPrices[i].price;
231+
if (this.options.prices.finalPrice) {
232+
var originalPrice = this.options.prices.finalPrice.amount;
233+
234+
for (i = 0; i < this.options.priceConfig.tierPrices.length; i++) {
235+
if (productQty >= this.options.priceConfig.tierPrices[i].qty) {
236+
tierPrice = this.options.priceConfig.tierPrices[i].price;
237+
}
235238
}
239+
prices.prices.finalPrice = {'amount': tierPrice - originalPrice};
236240
}
237-
prices = {
238-
'prices': {
239-
'finalPrice': {
240-
'amount': tierPrice - originalPrice
241+
242+
if (this.options.prices.basePrice) {
243+
var originalBasePrice = this.options.prices.basePrice.amount,
244+
tierPriceExlTax,
245+
tierPriceItem;
246+
247+
for (i = 0; i < this.options.priceConfig.tierPrices.length; i++) {
248+
tierPriceItem = this.options.priceConfig.tierPrices[i];
249+
if (productQty >= tierPriceItem.qty && tierPriceItem.excl_tax_price) {
250+
tierPriceExlTax = tierPriceItem.excl_tax_price;
241251
}
242252
}
243-
};
253+
prices.prices.basePrice = {'amount': tierPriceExlTax - originalBasePrice};
254+
}
255+
244256
this.updatePrice(prices);
245257
}
246258
});

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
use Magento\ConfigurableProduct\Model\ConfigurableAttributeData;
1111
use Magento\Customer\Helper\Session\CurrentCustomer;
1212
use Magento\Customer\Model\Session;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
1314
use Magento\Framework\App\ObjectManager;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516
use Magento\Framework\Locale\Format;
1617
use Magento\Framework\Pricing\PriceCurrencyInterface;
1718
use Magento\Store\Model\Store;
19+
use Magento\Tax\Model\Config;
1820

1921
/**
2022
* Confugurable product view type
@@ -78,6 +80,11 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
7880
*/
7981
private $variationPrices;
8082

83+
/**
84+
* @var ScopeConfigInterface
85+
*/
86+
private $scopeConfig;
87+
8188
/**
8289
* @param \Magento\Catalog\Block\Product\Context $context
8390
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
@@ -91,6 +98,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
9198
* @param Format|null $localeFormat
9299
* @param Session|null $customerSession
93100
* @param \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices|null $variationPrices
101+
* @param ScopeConfigInterface|null $scopeConfig
94102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
95103
*/
96104
public function __construct(
@@ -105,7 +113,8 @@ public function __construct(
105113
array $data = [],
106114
Format $localeFormat = null,
107115
Session $customerSession = null,
108-
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices $variationPrices = null
116+
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices $variationPrices = null,
117+
?ScopeConfigInterface $scopeConfig = null
109118
) {
110119
$this->priceCurrency = $priceCurrency;
111120
$this->helper = $helper;
@@ -118,6 +127,7 @@ public function __construct(
118127
$this->variationPrices = $variationPrices ?: ObjectManager::getInstance()->get(
119128
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices::class
120129
);
130+
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
121131

122132
parent::__construct(
123133
$context,
@@ -332,29 +342,40 @@ private function getTierPricesByProduct(ProductInterface $product): array
332342
$tierPrices = [];
333343
$tierPriceModel = $product->getPriceInfo()->getPrice('tier_price');
334344
foreach ($tierPriceModel->getTierPriceList() as $tierPrice) {
345+
$price = $tierPrice['price']->getValue();
346+
if ($this->getConfigTaxDisplayType() === Config::DISPLAY_TYPE_EXCLUDING_TAX) {
347+
$price = $tierPrice['price']->getBaseAmount();
348+
}
335349
$tierPriceData = [
336350
'qty' => $this->localeFormat->getNumber($tierPrice['price_qty']),
337-
'price' => $this->localeFormat->getNumber($tierPrice['price']->getValue()),
351+
'price' => $this->localeFormat->getNumber($price),
338352
'percentage' => $this->localeFormat->getNumber(
339353
$tierPriceModel->getSavePercent($tierPrice['price'])
340354
),
341355
];
342356

343-
if (isset($tierPrice['excl_tax_price'])) {
344-
$exclTax = $tierPrice['excl_tax_price'];
345-
$tierPriceData['excl_tax_price'] = $this->localeFormat->getNumber($exclTax->getBaseAmount());
357+
if ($this->getConfigTaxDisplayType() === Config::DISPLAY_TYPE_BOTH) {
358+
$tierPriceData['excl_tax_price'] = $this->localeFormat->getNumber(
359+
$tierPrice['price']->getBaseAmount()
360+
);
346361
}
347362

348-
if (isset($tierPrice['incl_excl_tax_price'])) {
349-
$inclExclTax = $tierPrice['incl_excl_tax_price'];
350-
$tierPriceData['incl_excl_tax_price'] = $this->localeFormat->getNumber($inclExclTax->getBaseAmount());
351-
}
352363
$tierPrices[] = $tierPriceData;
353364
}
354365

355366
return $tierPrices;
356367
}
357368

369+
/**
370+
* Returns config tax display type
371+
*
372+
* @return int
373+
*/
374+
private function getConfigTaxDisplayType(): int
375+
{
376+
return (int) $this->scopeConfig->getValue(Config::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE);
377+
}
378+
358379
/**
359380
* Replace ',' on '.' for js
360381
*

app/code/Magento/ConfigurableProduct/view/base/templates/product/price/tier_price.phtml

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,34 @@
77
?>
88
<script type="text/x-magento-template" id="tier-prices-template">
99
<ul class="prices-tier items">
10-
<% var inclExclPrice = ' <span class="price-wrapper price-excluding-tax"'
11-
+ 'data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">'
12-
+ '<span class="price">&nbsp;%1</span>'
13-
+ '</span>'
10+
<% var exclPriceTemplate = ' <span class="price-wrapper price-excluding-tax"'
11+
+ 'data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">'
12+
+ '<span class="price">&nbsp;%1</span>'
13+
+ '</span>'
1414
%>
1515

1616
<% _.each(tierPrices, function(item, key) { %>
17-
<% var itemInclExclPrice = item.hasOwnProperty('incl_excl_tax_price')
18-
? inclExclPrice.replace('%1', priceUtils.formatPrice(item['incl_excl_tax_price'], currencyFormat))
19-
: ''
20-
%>
21-
<% var price = item.hasOwnProperty('excl_tax_price')
22-
? priceUtils.formatPrice(item['excl_tax_price'], currencyFormat)
23-
: priceUtils.formatPrice(item.price, currencyFormat)
24-
%>
17+
<% var itemExclPrice = item.hasOwnProperty('excl_tax_price')
18+
? exclPriceTemplate.replace('%1', priceUtils.formatPrice(item['excl_tax_price'], currencyFormat))
19+
: ''
20+
%>
2521

26-
<% var priceStr = '<span class="price-container price-tier_price">'
27-
+ '<span data-price-amount="' + price + '"'
22+
<% var priceStr = '<span class="price-container price-tier_price">'
23+
+ '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
2824
+ ' data-price-type=""' + ' class="price-wrapper price-including-tax">'
29-
+ '<span class="price">' + price + '</span>'
30-
+ '</span>' + itemInclExclPrice + '</span>';
25+
+ '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
26+
+ '</span>' + itemExclPrice + '</span>';
27+
%>
28+
<li class="item">
29+
<%= '<?= $block->escapeHtml(__('Buy %1 for %2 each and', '%1', '%2')) ?>'
30+
.replace('%1', item.qty)
31+
.replace('%2', priceStr)
3132
%>
32-
<li class="item">
33-
<%= '<?= $block->escapeHtml(__('Buy %1 for %2 each and', '%1', '%2')) ?>'
34-
.replace('%1', item.qty)
35-
.replace('%2', priceStr)
36-
%>
37-
<strong class="benefit">
38-
<?= $block->escapeHtml(__('save')) ?><span
39-
class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
40-
</strong>
41-
</li>
33+
<strong class="benefit">
34+
<?= $block->escapeHtml(__('save')) ?><span
35+
class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
36+
</strong>
37+
</li>
4238
<% }); %>
4339
</ul>
4440
</script>

0 commit comments

Comments
 (0)