Skip to content

Commit f3b5612

Browse files
committed
AC-7099:: 'As low as' label is still displayed for a Configurable Product price even if all options have the same price
1 parent 98fb0dc commit f3b5612

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/ConfigurableRegularPrice.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ public function getValue()
8787
return $this->values[$this->product->getId()];
8888
}
8989

90+
/**
91+
* Checks if all children simple products have the same price.
92+
*
93+
* @return bool Returns true if all products have the same price, false otherwise.
94+
*/
95+
public function checkProductsHaveEqualPrices():bool
96+
{
97+
$minPrice = $this->getMinRegularAmount()->getValue();
98+
$maxPrice= $this->getMaxRegularAmount()->getValue();
99+
foreach ($this->getUsedProducts() as $subProduct) {
100+
if ($subProduct->isAvailable() && !$subProduct->isDisabled()) {
101+
if ($specialPrice=$subProduct->getSpecialPrice()) {
102+
if ($specialPrice!=$minPrice || $subProduct->getFinalPrice()!=$minPrice) {
103+
return false;
104+
} else {
105+
return true;
106+
}
107+
}
108+
}
109+
}
110+
return $minPrice === $maxPrice;
111+
}
112+
90113
/**
91114
* @inheritdoc
92115
*/

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
$priceModel = $block->getPriceType('regular_price');
1010
/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
1111
$finalPriceModel = $block->getPriceType('final_price');
12+
/** @var Magento\ConfigurableProduct\Pricing\Price\ConfigurableRegularPriceInterface $regularPriceModel */
13+
$regularPriceModel = $block->getPriceType('regular_price');
1214
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
1315
$schema = ($block->getZone() == 'item_view') ? true : false;
1416
?>
1517
<span class="normal-price">
1618
<?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
17-
'display_label' => __('As low as'),
19+
'display_label' => $regularPriceModel->checkProductsHaveEqualPrices() ? '' : __('As low as'),
1820
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
1921
'price_type' => 'finalPrice',
2022
'include_container' => true,
@@ -23,7 +25,7 @@ $schema = ($block->getZone() == 'item_view') ? true : false;
2325
?>
2426
</span>
2527

26-
<?php if (!$block->isProductList() && $block->hasSpecialPrice()) : ?>
28+
<?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
2729
<span class="old-price sly-old-price no-display">
2830
<?= /* @noEscape */ $block->renderAmount($priceModel->getAmount(), [
2931
'display_label' => __('Regular Price'),
@@ -35,12 +37,12 @@ $schema = ($block->getZone() == 'item_view') ? true : false;
3537
</span>
3638
<?php endif; ?>
3739

38-
<?php if ($block->showMinimalPrice()) : ?>
39-
<?php if ($block->getUseLinkForAsLowAs()) :?>
40+
<?php if ($block->showMinimalPrice()): ?>
41+
<?php if ($block->getUseLinkForAsLowAs()):?>
4042
<a href="<?= $block->escapeUrl($block->getSaleableItem()->getProductUrl()) ?>" class="minimal-price-link">
4143
<?= /* @noEscape */ $block->renderAmountMinimal() ?>
4244
</a>
43-
<?php else :?>
45+
<?php else:?>
4446
<span class="minimal-price-link">
4547
<?= /* @noEscape */ $block->renderAmountMinimal() ?>
4648
</span>

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableProductPriceTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,10 @@ private function processPriceView(string $sku): string
221221
public function assertPrice(string $sku, float $expectedPrice): void
222222
{
223223
$priceBlockHtml = $this->processPriceView($sku);
224-
$regexp = '/<span class="price-label">As low as<\/span>.*';
225-
$regexp .= '<span.*data-price-amount="%s".*<span class="price">\$%.2f<\/span><\/span>/';
224+
$regexp = '/<span\s+class="price">\$%.2f<\/span>/';
226225
$this->assertMatchesRegularExpression(
227-
sprintf($regexp, round($expectedPrice, 2), $expectedPrice),
228-
preg_replace('/[\n\r]/', '', $priceBlockHtml)
226+
sprintf($regexp, $expectedPrice),
227+
$priceBlockHtml
229228
);
230229
}
231230

0 commit comments

Comments
 (0)