Skip to content

Commit 8a4e2d4

Browse files
committed
ACP2E-1634: addressing CR comments
1 parent d988484 commit 8a4e2d4

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class MinimalTierPriceCalculator implements MinimalPriceCalculatorInterface
2020
*/
2121
private $calculator;
2222

23-
2423
/**
2524
* @param CalculatorInterface $calculator
2625
*/
@@ -48,22 +47,16 @@ public function getValue(SaleableInterface $saleableItem)
4847
*/
4948
public function getAmount(SaleableInterface $saleableItem)
5049
{
51-
$lowestTierPrice = null;
50+
$minPrice = null;
5251
/** @var TierPrice $price */
5352
$tierPrice = $saleableItem->getPriceInfo()->getPrice(TierPrice::PRICE_CODE);
5453
$tierPriceList = $tierPrice->getTierPriceList();
55-
$finalPrice = $saleableItem->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue();
5654

57-
$minPrice = $finalPrice;
58-
foreach ($tierPriceList as $tierPrice) {
59-
/** @var AmountInterface $price */
60-
$price = $tierPrice['price'];
61-
if ($minPrice > $price->getValue()) {
62-
$minPrice = $price->getValue();
63-
$lowestTierPrice = $price;
64-
}
55+
if (count($tierPriceList)) {
56+
usort($tierPriceList, fn ($tier1, $tier2) => $tier1['price']->getValue() <=> $tier2['price']->getValue());
57+
$minPrice = array_shift($tierPriceList)['price'];
6558
}
6659

67-
return $lowestTierPrice;
60+
return $minPrice;
6861
}
6962
}

0 commit comments

Comments
 (0)