Skip to content

Commit 878d029

Browse files
committed
Merge branch 'ACP2E-1634' of https://github.com/magento-l3/magento2ce into PR-VK-2023-04-05-CE
2 parents d1edab7 + 8a4e2d4 commit 878d029

File tree

7 files changed

+109
-41
lines changed

7 files changed

+109
-41
lines changed

app/code/Magento/Bundle/view/base/templates/product/price/final_price.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
?>
77

88
<?php
9+
// @codingStandardsIgnoreFile
910
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
1011
/** @var \Magento\Bundle\Pricing\Render\FinalPriceBox $block */
1112

@@ -22,7 +23,7 @@ $regularPriceAttributes = [
2223
'display_label' => __('Regular Price'),
2324
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
2425
'include_container' => true,
25-
'skip_adjustments' => true
26+
'skip_adjustments' => false
2627
];
2728
$renderMinimalRegularPrice = $block->renderAmount($minimalRegularPrice, $regularPriceAttributes);
2829
?>

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
namespace Magento\Catalog\Pricing\Price;
88

9-
use Magento\Framework\Pricing\SaleableInterface;
109
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
1110
use Magento\Framework\Pricing\Amount\AmountInterface;
11+
use Magento\Framework\Pricing\SaleableInterface;
1212

1313
/**
1414
* As Low As shows minimal value of Tier Prices
@@ -36,18 +36,7 @@ public function __construct(CalculatorInterface $calculator)
3636
*/
3737
public function getValue(SaleableInterface $saleableItem)
3838
{
39-
/** @var TierPrice $price */
40-
$price = $saleableItem->getPriceInfo()->getPrice(TierPrice::PRICE_CODE);
41-
$tierPriceList = $price->getTierPriceList();
42-
43-
$tierPrices = [];
44-
foreach ($tierPriceList as $tierPrice) {
45-
/** @var AmountInterface $price */
46-
$price = $tierPrice['price'];
47-
$tierPrices[] = $price->getValue();
48-
}
49-
50-
return $tierPrices ? min($tierPrices) : null;
39+
return $this->getAmount($saleableItem)?->getValue();
5140
}
5241

5342
/**
@@ -58,10 +47,16 @@ public function getValue(SaleableInterface $saleableItem)
5847
*/
5948
public function getAmount(SaleableInterface $saleableItem)
6049
{
61-
$value = $this->getValue($saleableItem);
50+
$minPrice = null;
51+
/** @var TierPrice $price */
52+
$tierPrice = $saleableItem->getPriceInfo()->getPrice(TierPrice::PRICE_CODE);
53+
$tierPriceList = $tierPrice->getTierPriceList();
54+
55+
if (count($tierPriceList)) {
56+
usort($tierPriceList, fn ($tier1, $tier2) => $tier1['price']->getValue() <=> $tier2['price']->getValue());
57+
$minPrice = array_shift($tierPriceList)['price'];
58+
}
6259

63-
return $value === null
64-
? null
65-
: $this->calculator->getAmount($value, $saleableItem, 'tax');
60+
return $minPrice;
6661
}
6762
}

app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
namespace Magento\Catalog\Pricing\Render;
88

9-
use Magento\Catalog\Pricing\Price;
10-
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
11-
use Magento\Msrp\Pricing\Price\MsrpPrice;
129
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
13-
use Magento\Framework\View\Element\Template\Context;
14-
use Magento\Framework\Pricing\SaleableInterface;
10+
use Magento\Catalog\Pricing\Price;
11+
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
1514
use Magento\Framework\Pricing\Price\PriceInterface;
15+
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
1616
use Magento\Framework\Pricing\Render\RendererPool;
17-
use Magento\Framework\App\ObjectManager;
18-
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
17+
use Magento\Framework\Pricing\SaleableInterface;
18+
use Magento\Framework\View\Element\Template\Context;
19+
use Magento\Msrp\Pricing\Price\MsrpPrice;
1920

2021
/**
2122
* Class for final_price rendering
@@ -140,7 +141,7 @@ public function renderAmountMinimal()
140141
'display_label' => __('As low as'),
141142
'price_id' => $id,
142143
'include_container' => false,
143-
'skip_adjustments' => true
144+
'skip_adjustments' => false
144145
]
145146
);
146147
}
@@ -183,7 +184,7 @@ public function showMinimalPrice()
183184
public function getCacheKey()
184185
{
185186
return parent::getCacheKey()
186-
. ($this->getData('list_category_page') ? '-list-category-page': '')
187+
. ($this->getData('list_category_page') ? '-list-category-page' : '')
187188
. ($this->getSaleableItem()->getCustomerGroupId() ?? '');
188189
}
189190

app/code/Magento/Catalog/Test/Unit/Pricing/Price/MinimalTierPriceCalculatorTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Catalog\Test\Unit\Pricing\Price;
99

10+
use Magento\Catalog\Pricing\Price\FinalPrice;
1011
use Magento\Catalog\Pricing\Price\MinimalTierPriceCalculator;
1112
use Magento\Catalog\Pricing\Price\TierPrice;
1213
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
@@ -73,10 +74,10 @@ private function getValueTierPricesExistShouldReturnMinTierPrice()
7374
$notMinPrice = 10;
7475

7576
$minAmount = $this->getMockForAbstractClass(AmountInterface::class);
76-
$minAmount->expects($this->once())->method('getValue')->willReturn($minPrice);
77+
$minAmount->expects($this->atLeastOnce())->method('getValue')->willReturn($minPrice);
7778

7879
$notMinAmount = $this->getMockForAbstractClass(AmountInterface::class);
79-
$notMinAmount->expects($this->once())->method('getValue')->willReturn($notMinPrice);
80+
$notMinAmount->expects($this->atLeastOnce())->method('getValue')->willReturn($notMinPrice);
8081

8182
$tierPriceList = [
8283
[
@@ -89,10 +90,12 @@ private function getValueTierPricesExistShouldReturnMinTierPrice()
8990

9091
$this->price->expects($this->once())->method('getTierPriceList')->willReturn($tierPriceList);
9192

92-
$this->priceInfo->expects($this->once())->method('getPrice')->with(TierPrice::PRICE_CODE)
93-
->willReturn($this->price);
93+
$this->priceInfo->expects($this->atLeastOnce())
94+
->method('getPrice')
95+
->withConsecutive([TierPrice::PRICE_CODE], [FinalPrice::PRICE_CODE])
96+
->willReturnOnConsecutiveCalls($this->price, $notMinAmount);
9497

95-
$this->saleable->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfo);
98+
$this->saleable->expects($this->atLeastOnce())->method('getPriceInfo')->willReturn($this->priceInfo);
9699
return $minPrice;
97100
}
98101

@@ -107,12 +110,8 @@ public function testGetGetAmountMinTierPriceExistShouldReturnAmountObject()
107110
$minPrice = $this->getValueTierPricesExistShouldReturnMinTierPrice();
108111

109112
$amount = $this->getMockForAbstractClass(AmountInterface::class);
113+
$amount->method('getValue')->willReturn($minPrice);
110114

111-
$this->calculator->expects($this->once())
112-
->method('getAmount')
113-
->with($minPrice, $this->saleable)
114-
->willReturn($amount);
115-
116-
$this->assertSame($amount, $this->object->getAmount($this->saleable));
115+
$this->assertEquals($amount, $this->object->getAmount($this->saleable));
117116
}
118117
}

app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ public function testRenderAmountMinimal(): void
339339
$arguments = [
340340
'zone' => 'test_zone',
341341
'list_category_page' => true,
342-
'display_label' => 'As low as',
342+
'display_label' => __('As low as'),
343343
'price_id' => $priceId,
344344
'include_container' => false,
345-
'skip_adjustments' => true
345+
'skip_adjustments' => false
346346
];
347347

348348
$amountRender = $this->createPartialMock(Amount::class, ['toHtml']);

app/code/Magento/Catalog/view/base/templates/product/price/final_price.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
?>
77

88
<?php
9+
// @codingStandardsIgnoreFile
910
/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */
1011

1112
/** ex: \Magento\Catalog\Pricing\Price\RegularPrice */
@@ -34,7 +35,7 @@ $schema = ($block->getZone() == 'item_view') ? true : false;
3435
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
3536
'price_type' => 'oldPrice',
3637
'include_container' => true,
37-
'skip_adjustments' => true
38+
'skip_adjustments' => false
3839
]); ?>
3940
</span>
4041
<?php else :?>

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ListProduct/CheckProductPriceTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Catalog\Block\Product\ListProduct;
12+
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
13+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
14+
use Magento\Customer\Model\Group;
1215
use Magento\Customer\Model\Session;
1316
use Magento\Framework\View\Element\Template;
1417
use Magento\Framework\View\Result\PageFactory;
18+
use Magento\Tax\Model\Config as TaxConfig;
19+
use Magento\Tax\Test\Fixture\TaxRate as TaxRateFixture;
20+
use Magento\Tax\Test\Fixture\TaxRule as TaxRuleFixture;
21+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
22+
use Magento\TestFramework\Fixture\DataFixture;
1523
use Magento\TestFramework\Helper\Bootstrap;
1624
use Magento\TestFramework\ObjectManager;
1725
use PHPUnit\Framework\TestCase;
@@ -242,6 +250,30 @@ private function assertAsLowAsPrice(string $priceHtml, float $expectedPrice): vo
242250
);
243251
}
244252

253+
/**
254+
* Assert that price html contain "As low as" label and expected price amount with taxes
255+
*
256+
* @param string $priceHtml
257+
* @param float $expectedPriceWithTaxes
258+
* @param float $expectedPriceWithoutTaxes
259+
* @return void
260+
*/
261+
private function assertAsLowAsPriceWithTaxes(
262+
string $priceHtml,
263+
float $expectedPriceWithTaxes,
264+
float $expectedPriceWithoutTaxes
265+
): void {
266+
$this->assertMatchesRegularExpression(
267+
sprintf(
268+
'/<span class="price-label">As low as<\/span>(.)+<span.*data-price-amount="%s".*>\\$%01.2f<\/span>(.)+<span class="price">\$%01.2f<\/span>/',//phpcs:ignore
269+
$expectedPriceWithTaxes,
270+
$expectedPriceWithTaxes,
271+
$expectedPriceWithoutTaxes
272+
),
273+
$priceHtml
274+
);
275+
}
276+
245277
/**
246278
* Assert that price html contain expected final price amount.
247279
*
@@ -307,4 +339,43 @@ private function getListProductBlock(): ListProduct
307339

308340
return $categoryProductsBlock->getChildBlock('product_list');
309341
}
342+
343+
#[
344+
ConfigFixture(TaxConfig::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, 0, 'store', 'default'),
345+
ConfigFixture(TaxConfig::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE, 3, 'store', 'default'),
346+
DataFixture(
347+
TaxRateFixture::class,
348+
as: 'rate'
349+
),
350+
DataFixture(
351+
TaxRuleFixture::class,
352+
[
353+
'customer_tax_class_ids' => [3],
354+
'product_tax_class_ids' => [2],
355+
'tax_rate_ids' => ['$rate.id$']
356+
],
357+
'rule'
358+
),
359+
DataFixture(CategoryFixture::class, as: 'category'),
360+
DataFixture(
361+
ProductFixture::class,
362+
[
363+
'sku' => 'simple-product-tax-both',
364+
'category_ids' => ['1', '$category.id$'],
365+
'tier_prices' => [
366+
[
367+
'customer_group_id' => Group::NOT_LOGGED_IN_ID,
368+
'qty' => 2,
369+
'value' => 5
370+
]
371+
]
372+
]
373+
)
374+
]
375+
public function testRenderAmountMinimalProductWithTierPricesShouldShowMinTierPriceWithTaxes()
376+
{
377+
$priceHtml = $this->getProductPriceHtml('simple-product-tax-both');
378+
$this->assertFinalPrice($priceHtml, 10.00);
379+
$this->assertAsLowAsPriceWithTaxes($priceHtml, 5.500001, 5.00);
380+
}
310381
}

0 commit comments

Comments
 (0)