Skip to content

Commit efa39dc

Browse files
committed
Merge branch 'ACP2E-291' of https://github.com/magento-l3/magento2ce into L3-PR-2022-04-19-v2
2 parents c3ed36d + 2b6090b commit efa39dc

File tree

7 files changed

+87
-68
lines changed

7 files changed

+87
-68
lines changed

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

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

88
use Magento\Catalog\Api\ProductRepositoryInterface;
9-
use Magento\Catalog\Model\Category;
109

1110
/**
1211
* Product View block
@@ -183,7 +182,8 @@ public function getJsonConfig()
183182
foreach ($tierPricesList as $tierPrice) {
184183
$tierPriceData = [
185184
'qty' => $tierPrice['price_qty'],
186-
'price' => $tierPrice['website_price'],
185+
'price' => $tierPrice['price']->getValue(),
186+
'basePrice' => $tierPrice['price']->getBaseAmount()
187187
];
188188
$tierPrices[] = $tierPriceData;
189189
}

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: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,45 @@ 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() {
226+
var originalPrice,
227+
prices = {'prices': {}};
228+
229+
if (this.options.prices.finalPrice) {
230+
originalPrice = this.options.prices.finalPrice.amount;
231+
prices.prices.finalPrice = {'amount': this.getPrice('price') - originalPrice};
232+
}
233+
234+
if (this.options.prices.basePrice) {
235+
originalPrice = this.options.prices.basePrice.amount;
236+
prices.prices.basePrice = {'amount': this.getPrice('basePrice') - originalPrice};
237+
}
238+
239+
this.updatePrice(prices);
240+
},
241+
242+
/**
243+
* Returns price.
244+
*
245+
* @param {String} priceKey
246+
* @returns {Number}
247+
*/
248+
getPrice: function (priceKey) {
226249
var productQty = $(this.qtyInfo).val(),
227-
originalPrice = this.options.prices.finalPrice.amount,
228-
tierPrice,
229-
prices,
250+
result,
251+
tierPriceItem,
230252
i;
231253

232254
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;
255+
tierPriceItem = this.options.priceConfig.tierPrices[i];
256+
if (productQty >= tierPriceItem.qty && tierPriceItem[priceKey]) {
257+
result = tierPriceItem[priceKey];
235258
}
236259
}
237-
prices = {
238-
'prices': {
239-
'finalPrice': {
240-
'amount': tierPrice - originalPrice
241-
}
242-
}
243-
};
244-
this.updatePrice(prices);
260+
261+
return result;
245262
}
246263
});
247264

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,23 +332,23 @@ private function getTierPricesByProduct(ProductInterface $product): array
332332
$tierPrices = [];
333333
$tierPriceModel = $product->getPriceInfo()->getPrice('tier_price');
334334
foreach ($tierPriceModel->getTierPriceList() as $tierPrice) {
335+
$price = $this->_taxData->displayPriceExcludingTax() ?
336+
$tierPrice['price']->getBaseAmount() : $tierPrice['price']->getValue();
337+
335338
$tierPriceData = [
336339
'qty' => $this->localeFormat->getNumber($tierPrice['price_qty']),
337-
'price' => $this->localeFormat->getNumber($tierPrice['price']->getValue()),
340+
'price' => $this->localeFormat->getNumber($price),
338341
'percentage' => $this->localeFormat->getNumber(
339342
$tierPriceModel->getSavePercent($tierPrice['price'])
340343
),
341344
];
342345

343-
if (isset($tierPrice['excl_tax_price'])) {
344-
$exclTax = $tierPrice['excl_tax_price'];
345-
$tierPriceData['excl_tax_price'] = $this->localeFormat->getNumber($exclTax->getBaseAmount());
346+
if ($this->_taxData->displayBothPrices()) {
347+
$tierPriceData['basePrice'] = $this->localeFormat->getNumber(
348+
$tierPrice['price']->getBaseAmount()
349+
);
346350
}
347351

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-
}
352352
$tierPrices[] = $tierPriceData;
353353
}
354354

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: 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 basePriceTemplate = ' <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 itemBasePrice = item.hasOwnProperty('basePrice')
18+
? basePriceTemplate.replace('%1', priceUtils.formatPrice(item['basePrice'], 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>' + itemBasePrice + '</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>

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)