Skip to content

Commit d29db46

Browse files
authored
ENGCOM-8202: Fixed Issue 12225: Tier pricing tax shows only including tax #27953
2 parents 9b8d63b + 9861d3e commit d29db46

File tree

6 files changed

+289
-69
lines changed

6 files changed

+289
-69
lines changed

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

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@
99
use Magento\Catalog\Model\Product;
1010
use Magento\Customer\Api\GroupManagementInterface;
1111
use Magento\Customer\Model\Session;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
1315
use Magento\Framework\Pricing\Amount\AmountInterface;
1416
use Magento\Framework\Pricing\Price\AbstractPrice;
1517
use Magento\Framework\Pricing\Price\BasePriceProviderInterface;
18+
use Magento\Framework\Pricing\PriceCurrencyInterface;
1619
use Magento\Framework\Pricing\PriceInfoInterface;
1720
use Magento\Customer\Model\Group\RetrieverInterface as CustomerGroupRetrieverInterface;
21+
use Magento\Tax\Model\Config;
1822

1923
/**
2024
* @api
2125
* @since 100.0.2
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2228
*/
2329
class TierPrice extends AbstractPrice implements TierPriceInterface, BasePriceProviderInterface
2430
{
31+
private const XML_PATH_TAX_DISPLAY_TYPE = 'tax/display/type';
32+
2533
/**
2634
* Price type tier
2735
*/
@@ -62,35 +70,43 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
6270
*/
6371
private $customerGroupRetriever;
6472

73+
/**
74+
* @var ScopeConfigInterface
75+
*/
76+
private $scopeConfig;
77+
6578
/**
6679
* @param Product $saleableItem
6780
* @param float $quantity
6881
* @param CalculatorInterface $calculator
69-
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
82+
* @param PriceCurrencyInterface $priceCurrency
7083
* @param Session $customerSession
7184
* @param GroupManagementInterface $groupManagement
7285
* @param CustomerGroupRetrieverInterface|null $customerGroupRetriever
86+
* @param ScopeConfigInterface|null $scopeConfig
7387
*/
7488
public function __construct(
7589
Product $saleableItem,
7690
$quantity,
7791
CalculatorInterface $calculator,
78-
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
92+
PriceCurrencyInterface $priceCurrency,
7993
Session $customerSession,
8094
GroupManagementInterface $groupManagement,
81-
CustomerGroupRetrieverInterface $customerGroupRetriever = null
95+
CustomerGroupRetrieverInterface $customerGroupRetriever = null,
96+
?ScopeConfigInterface $scopeConfig = null
8297
) {
8398
$quantity = (float)$quantity ? $quantity : 1;
8499
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
85100
$this->customerSession = $customerSession;
86101
$this->groupManagement = $groupManagement;
87102
$this->customerGroupRetriever = $customerGroupRetriever
88-
?? \Magento\Framework\App\ObjectManager::getInstance()->get(CustomerGroupRetrieverInterface::class);
103+
?? ObjectManager::getInstance()->get(CustomerGroupRetrieverInterface::class);
89104
if ($saleableItem->hasCustomerGroupId()) {
90105
$this->customerGroup = (int) $saleableItem->getCustomerGroupId();
91106
} else {
92107
$this->customerGroup = (int) $this->customerGroupRetriever->getCustomerGroupId();
93108
}
109+
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
94110
}
95111

96112
/**
@@ -136,6 +152,8 @@ protected function isFirstPriceBetter($firstPrice, $secondPrice)
136152
}
137153

138154
/**
155+
* Returns tier price count
156+
*
139157
* @return int
140158
*/
141159
public function getTierPriceCount()
@@ -144,6 +162,8 @@ public function getTierPriceCount()
144162
}
145163

146164
/**
165+
* Returns tier price list
166+
*
147167
* @return array
148168
*/
149169
public function getTierPriceList()
@@ -155,15 +175,32 @@ public function getTierPriceList()
155175
$this->priceList,
156176
function (&$priceData) {
157177
/* convert string value to float */
158-
$priceData['price_qty'] = $priceData['price_qty'] * 1;
178+
$priceData['price_qty'] *= 1;
179+
if ($this->getConfigTaxDisplayType() === Config::DISPLAY_TYPE_BOTH) {
180+
$exclTaxPrice = $this->calculator->getAmount($priceData['price'], $this->product, true);
181+
$priceData['excl_tax_price'] = $exclTaxPrice;
182+
}
159183
$priceData['price'] = $this->applyAdjustment($priceData['price']);
160184
}
161185
);
162186
}
187+
163188
return $this->priceList;
164189
}
165190

166191
/**
192+
* Returns config tax display type
193+
*
194+
* @return int
195+
*/
196+
private function getConfigTaxDisplayType(): int
197+
{
198+
return (int) $this->scopeConfig->getValue(self::XML_PATH_TAX_DISPLAY_TYPE);
199+
}
200+
201+
/**
202+
* Filters tier prices
203+
*
167204
* @param array $priceList
168205
* @return array
169206
*/
@@ -204,6 +241,8 @@ protected function filterTierPrices(array $priceList)
204241
}
205242

206243
/**
244+
* Returns base price
245+
*
207246
* @return float
208247
*/
209248
protected function getBasePrice()
@@ -213,25 +252,22 @@ protected function getBasePrice()
213252
}
214253

215254
/**
216-
* Calculates savings percentage according to the given tier price amount
217-
* and related product price amount.
255+
* Calculates savings percentage according to the given tier price amount and related product price amount.
218256
*
219257
* @param AmountInterface $amount
220-
*
221258
* @return float
222259
*/
223260
public function getSavePercent(AmountInterface $amount)
224261
{
225-
$productPriceAmount = $this->priceInfo->getPrice(
226-
FinalPrice::PRICE_CODE
227-
)->getAmount();
262+
$productPriceAmount = $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)
263+
->getAmount();
228264

229-
return round(
230-
100 - ((100 / $productPriceAmount->getValue()) * $amount->getValue())
231-
);
265+
return round(100 - ((100 / $productPriceAmount->getValue()) * $amount->getValue()));
232266
}
233267

234268
/**
269+
* Apply adjustment to price
270+
*
235271
* @param float|string $price
236272
* @return \Magento\Framework\Pricing\Amount\AmountInterface
237273
*/
@@ -314,6 +350,8 @@ protected function getStoredTierPrices()
314350
}
315351

316352
/**
353+
* Return is percentage discount
354+
*
317355
* @return bool
318356
*/
319357
public function isPercentageDiscount()

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

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace Magento\ConfigurableProduct\Block\Product\View\Type;
99

10+
use Magento\Catalog\Api\Data\ProductInterface;
1011
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1112
use Magento\ConfigurableProduct\Model\ConfigurableAttributeData;
1213
use Magento\Customer\Helper\Session\CurrentCustomer;
@@ -287,53 +288,70 @@ protected function getOptionPrices()
287288
{
288289
$prices = [];
289290
foreach ($this->getAllowProducts() as $product) {
290-
$tierPrices = [];
291291
$priceInfo = $product->getPriceInfo();
292-
$tierPriceModel = $priceInfo->getPrice('tier_price');
293-
$tierPricesList = $tierPriceModel->getTierPriceList();
294-
foreach ($tierPricesList as $tierPrice) {
295-
$tierPrices[] = [
296-
'qty' => $this->localeFormat->getNumber($tierPrice['price_qty']),
297-
'price' => $this->localeFormat->getNumber($tierPrice['price']->getValue()),
298-
'percentage' => $this->localeFormat->getNumber(
299-
$tierPriceModel->getSavePercent($tierPrice['price'])
300-
),
301-
];
302-
}
303292

304-
$prices[$product->getId()] =
305-
[
306-
'baseOldPrice' => [
307-
'amount' => $this->localeFormat->getNumber(
308-
$priceInfo->getPrice('regular_price')->getAmount()->getBaseAmount()
309-
),
310-
],
311-
'oldPrice' => [
312-
'amount' => $this->localeFormat->getNumber(
313-
$priceInfo->getPrice('regular_price')->getAmount()->getValue()
314-
),
315-
],
316-
'basePrice' => [
317-
'amount' => $this->localeFormat->getNumber(
318-
$priceInfo->getPrice('final_price')->getAmount()->getBaseAmount()
319-
),
320-
],
321-
'finalPrice' => [
322-
'amount' => $this->localeFormat->getNumber(
323-
$priceInfo->getPrice('final_price')->getAmount()->getValue()
324-
),
325-
],
326-
'tierPrices' => $tierPrices,
327-
'msrpPrice' => [
328-
'amount' => $this->localeFormat->getNumber(
329-
$this->priceCurrency->convertAndRound($product->getMsrp())
330-
),
331-
],
332-
];
293+
$prices[$product->getId()] = [
294+
'baseOldPrice' => [
295+
'amount' => $this->localeFormat->getNumber(
296+
$priceInfo->getPrice('regular_price')->getAmount()->getBaseAmount()
297+
),
298+
],
299+
'oldPrice' => [
300+
'amount' => $this->localeFormat->getNumber(
301+
$priceInfo->getPrice('regular_price')->getAmount()->getValue()
302+
),
303+
],
304+
'basePrice' => [
305+
'amount' => $this->localeFormat->getNumber(
306+
$priceInfo->getPrice('final_price')->getAmount()->getBaseAmount()
307+
),
308+
],
309+
'finalPrice' => [
310+
'amount' => $this->localeFormat->getNumber(
311+
$priceInfo->getPrice('final_price')->getAmount()->getValue()
312+
),
313+
],
314+
'tierPrices' => $this->getTierPricesByProduct($product),
315+
'msrpPrice' => [
316+
'amount' => $this->localeFormat->getNumber(
317+
$this->priceCurrency->convertAndRound($product->getMsrp())
318+
),
319+
],
320+
];
333321
}
322+
334323
return $prices;
335324
}
336325

326+
/**
327+
* Returns product's tier prices list
328+
*
329+
* @param ProductInterface $product
330+
* @return array
331+
*/
332+
private function getTierPricesByProduct(ProductInterface $product): array
333+
{
334+
$tierPrices = [];
335+
$tierPriceModel = $product->getPriceInfo()->getPrice('tier_price');
336+
foreach ($tierPriceModel->getTierPriceList() as $tierPrice) {
337+
$tierPriceData = [
338+
'qty' => $this->localeFormat->getNumber($tierPrice['price_qty']),
339+
'price' => $this->localeFormat->getNumber($tierPrice['price']->getValue()),
340+
'percentage' => $this->localeFormat->getNumber(
341+
$tierPriceModel->getSavePercent($tierPrice['price'])
342+
),
343+
];
344+
345+
if (isset($tierPrice['excl_tax_price'])) {
346+
$excludingTax = $tierPrice['excl_tax_price'];
347+
$tierPriceData['excl_tax_price'] = $this->localeFormat->getNumber($excludingTax->getBaseAmount());
348+
}
349+
$tierPrices[] = $tierPriceData;
350+
}
351+
352+
return $tierPrices;
353+
}
354+
337355
/**
338356
* Replace ',' on '.' for js
339357
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontAssertExcludingTierPriceActionGroup">
12+
<annotations>
13+
<description>Assert product item tier price excluding price.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="excludingPrice" type="string"/>
17+
</arguments>
18+
19+
<grabTextFrom selector="{{StorefrontProductInfoMainSection.tierPriceExcludingPrice}}" stepKey="tierPriceExcluding"/>
20+
<assertStringContainsString stepKey="assertTierPriceTextOnProductPage">
21+
<expectedResult type="string">{{excludingPrice}}</expectedResult>
22+
<actualResult type="variable">tierPriceExcluding</actualResult>
23+
</assertStringContainsString>
24+
</actionGroup>
25+
</actionGroups>

app/code/Magento/ConfigurableProduct/Test/Mftf/Section/StorefrontProductInfoMainSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
<element name="stockIndication" type="block" selector=".stock" />
2424
<element name="attributeSelectByAttributeID" type="select" selector="//div[@class='fieldset']//div[//span[text()='{{attribute_code}}']]//select" parameterized="true"/>
2525
<element name="attributeOptionByAttributeID" type="select" selector="//div[@class='fieldset']//div[//span[text()='{{attribute_code}}']]//option[text()='{{optionName}}']" parameterized="true"/>
26+
<element name="tierPriceExcludingPrice" type="text" selector=".item [data-label='Excl. Tax']"/>
2627
</section>
2728
</sections>

0 commit comments

Comments
 (0)