Skip to content

Commit 0d5d7ee

Browse files
committed
ACP2E-291: Excl.Tax Tier Price issue on QTY Change
1 parent e5da36d commit 0d5d7ee

File tree

6 files changed

+41
-52
lines changed

6 files changed

+41
-52
lines changed

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

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

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

1210
/**
1311
* Product View block
@@ -65,11 +63,6 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
6563
*/
6664
protected $productRepository;
6765

68-
/**
69-
* @var Config|null
70-
*/
71-
private $taxConfig;
72-
7366
/**
7467
* @param Context $context
7568
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
@@ -82,7 +75,6 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
8275
* @param ProductRepositoryInterface|\Magento\Framework\Pricing\PriceCurrencyInterface $productRepository
8376
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
8477
* @param array $data
85-
* @param Config|null $taxConfig
8678
* @codingStandardsIgnoreStart
8779
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8880
*/
@@ -97,8 +89,7 @@ public function __construct(
9789
\Magento\Customer\Model\Session $customerSession,
9890
ProductRepositoryInterface $productRepository,
9991
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
100-
array $data = [],
101-
Config $taxConfig = null
92+
array $data = []
10293
) {
10394
$this->_productHelper = $productHelper;
10495
$this->urlEncoder = $urlEncoder;
@@ -109,7 +100,6 @@ public function __construct(
109100
$this->customerSession = $customerSession;
110101
$this->productRepository = $productRepository;
111102
$this->priceCurrency = $priceCurrency;
112-
$this->taxConfig = $taxConfig ?: ObjectManager::getInstance()->get(Config::class);
113103
parent::__construct(
114104
$context,
115105
$data
@@ -190,14 +180,10 @@ public function getJsonConfig()
190180
$priceInfo = $product->getPriceInfo();
191181
$tierPricesList = $priceInfo->getPrice('tier_price')->getTierPriceList();
192182
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-
}
197183
$tierPriceData = [
198184
'qty' => $tierPrice['price_qty'],
199-
'price' => $price,
200-
'excl_tax_price' => $tierPrice['price']->getBaseAmount()
185+
'price' => $tierPrice['price']->getValue(),
186+
'basePrice' => $tierPrice['price']->getBaseAmount()
201187
];
202188
$tierPrices[] = $tierPriceData;
203189
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ define([
241241

242242
if (this.options.prices.basePrice) {
243243
var originalBasePrice = this.options.prices.basePrice.amount,
244-
tierPriceExlTax,
244+
tierBasePrice,
245245
tierPriceItem;
246246

247247
for (i = 0; i < this.options.priceConfig.tierPrices.length; i++) {
248248
tierPriceItem = this.options.priceConfig.tierPrices[i];
249-
if (productQty >= tierPriceItem.qty && tierPriceItem.excl_tax_price) {
250-
tierPriceExlTax = tierPriceItem.excl_tax_price;
249+
if (productQty >= tierPriceItem.qty && tierPriceItem.basePrice) {
250+
tierBasePrice = tierPriceItem.basePrice;
251251
}
252252
}
253-
prices.prices.basePrice = {'amount': tierPriceExlTax - originalBasePrice};
253+
prices.prices.basePrice = {'amount': tierBasePrice - originalBasePrice};
254254
}
255255

256256
this.updatePrice(prices);

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
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;
1413
use Magento\Framework\App\ObjectManager;
1514
use Magento\Framework\Exception\NoSuchEntityException;
1615
use Magento\Framework\Locale\Format;
1716
use Magento\Framework\Pricing\PriceCurrencyInterface;
1817
use Magento\Store\Model\Store;
19-
use Magento\Tax\Model\Config;
2018

2119
/**
2220
* Confugurable product view type
@@ -80,11 +78,6 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
8078
*/
8179
private $variationPrices;
8280

83-
/**
84-
* @var ScopeConfigInterface
85-
*/
86-
private $scopeConfig;
87-
8881
/**
8982
* @param \Magento\Catalog\Block\Product\Context $context
9083
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
@@ -98,7 +91,6 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
9891
* @param Format|null $localeFormat
9992
* @param Session|null $customerSession
10093
* @param \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices|null $variationPrices
101-
* @param ScopeConfigInterface|null $scopeConfig
10294
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
10395
*/
10496
public function __construct(
@@ -113,8 +105,7 @@ public function __construct(
113105
array $data = [],
114106
Format $localeFormat = null,
115107
Session $customerSession = null,
116-
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices $variationPrices = null,
117-
?ScopeConfigInterface $scopeConfig = null
108+
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices $variationPrices = null
118109
) {
119110
$this->priceCurrency = $priceCurrency;
120111
$this->helper = $helper;
@@ -127,7 +118,6 @@ public function __construct(
127118
$this->variationPrices = $variationPrices ?: ObjectManager::getInstance()->get(
128119
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices::class
129120
);
130-
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
131121

132122
parent::__construct(
133123
$context,
@@ -342,10 +332,9 @@ private function getTierPricesByProduct(ProductInterface $product): array
342332
$tierPrices = [];
343333
$tierPriceModel = $product->getPriceInfo()->getPrice('tier_price');
344334
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-
}
335+
$price = $this->_taxData->displayPriceExcludingTax() ?
336+
$tierPrice['price']->getBaseAmount() : $tierPrice['price']->getValue();
337+
349338
$tierPriceData = [
350339
'qty' => $this->localeFormat->getNumber($tierPrice['price_qty']),
351340
'price' => $this->localeFormat->getNumber($price),
@@ -354,8 +343,8 @@ private function getTierPricesByProduct(ProductInterface $product): array
354343
),
355344
];
356345

357-
if ($this->getConfigTaxDisplayType() === Config::DISPLAY_TYPE_BOTH) {
358-
$tierPriceData['excl_tax_price'] = $this->localeFormat->getNumber(
346+
if ($this->_taxData->displayBothPrices()) {
347+
$tierPriceData['basePrice'] = $this->localeFormat->getNumber(
359348
$tierPrice['price']->getBaseAmount()
360349
);
361350
}
@@ -366,16 +355,6 @@ private function getTierPricesByProduct(ProductInterface $product): array
366355
return $tierPrices;
367356
}
368357

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-
379358
/**
380359
* Replace ',' on '.' for js
381360
*

app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Magento\Store\Model\StoreManagerInterface;
3333
use PHPUnit\Framework\MockObject\MockObject;
3434
use PHPUnit\Framework\TestCase;
35+
use Magento\Tax\Helper\Data as TaxData;
3536

3637
/**
3738
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -160,6 +161,10 @@ protected function setUp(): void
160161
$this->context->expects($this->once())
161162
->method('getResolver')
162163
->willReturn($fileResolverMock);
164+
$taxData = $this->createMock(TaxData::class);
165+
$this->context->expects($this->once())
166+
->method('getTaxData')
167+
->willReturn($taxData);
163168
$this->currency = $this->getMockBuilder(Currency::class)
164169
->disableOriginalConstructor()
165170
->getMock();

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

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

1616
<% _.each(tierPrices, function(item, key) { %>
17-
<% var itemExclPrice = item.hasOwnProperty('excl_tax_price')
18-
? exclPriceTemplate.replace('%1', priceUtils.formatPrice(item['excl_tax_price'], currencyFormat))
17+
<% var itemBasePrice = item.hasOwnProperty('basePrice')
18+
? basePriceTemplate.replace('%1', priceUtils.formatPrice(item['basePrice'], currencyFormat))
1919
: ''
2020
%>
2121

2222
<% var priceStr = '<span class="price-container price-tier_price">'
2323
+ '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
2424
+ ' data-price-type=""' + ' class="price-wrapper price-including-tax">'
2525
+ '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
26-
+ '</span>' + itemExclPrice + '</span>';
26+
+ '</span>' + itemBasePrice + '</span>';
2727
%>
2828
<li class="item">
2929
<%= '<?= $block->escapeHtml(__('Buy %1 for %2 each and', '%1', '%2')) ?>'

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ViewTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ public function testGetJsonConfig(): void
139139
$this->assertEquals($product->getId(), $config['productId']);
140140
}
141141

142+
/**
143+
* Verifies that product tier prices config contains price and basePrice.
144+
*
145+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_fixed_tier_price.php
146+
*
147+
* @return void
148+
*/
149+
public function testTierPriceGetJsonConfig(): void
150+
{
151+
$product = $this->productRepository->get('simple-product-tax-none');
152+
$this->registerProduct($product);
153+
$config = $this->json->unserialize($this->block->getJsonConfig());
154+
155+
$this->assertNotEmpty($config);
156+
$this->assertArrayHasKey('tierPrices', $config);
157+
$this->assertArrayHasKey('basePrice', $config['tierPrices'][0]);
158+
$this->assertArrayHasKey('price', $config['tierPrices'][0]);
159+
}
160+
142161
/**
143162
* @return void
144163
*/

0 commit comments

Comments
 (0)