Skip to content

magento/magento2#40104 #40105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -49,7 +49,7 @@ public function __construct(
* @param int $productId
* @return float
*/
public function getMaxPriceForConfigurableProduct($productId)
public function getMaxPriceForConfigurableProduct(int $productId): float
{
$connection = $this->resourceConnection->getConnection();
$superLinkTable = $this->resourceConnection->getTableName('catalog_product_super_link');
Expand All @@ -63,7 +63,7 @@ public function getMaxPriceForConfigurableProduct($productId)
$result = $connection->fetchRow($select);

if ($result && isset($result['max_price'])) {
return $result['max_price'];
return (float) $result['max_price'];
}

// Return a default value or handle the case where there's no max price
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
* All Rights Reserved.
*/

namespace Magento\ConfigurableProduct\Pricing\Price;
Expand Down Expand Up @@ -196,26 +196,38 @@ public function _resetState(): void
}

/**
* Check whether Configurable Product have more than one children products
* @deprecated
* @see isPriceEqualAcrossChildProducts
*
* Check whether Configurable options do not have price difference
*
* @param SaleableInterface $product
* @return bool
*/
public function isChildProductsOfEqualPrices(SaleableInterface $product): bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should an early return be added to the beginning of this method to exit if the product is not configurable?

    if ($product->getTypeId() !== 'configurable') {
        return false;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment!
I've just realized that we don't need any arguments, as an object of this class will already have a product assigned.

Copy link

@victortodoran victortodoran Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should not need a new instance of a class to call a one method with a different product.

  • isChildProductsOfEqualPrices is no longer backwards compatible checks $this->product instead of parameter.
  • proposed alternative reduces flexibility, I should not need a new instance to just check a different product. the change basically makes the code single use.

I propose to revert back to checking the parameter.

EDIT: I just saw that the price is checked against the instance on the class. Please disregard above.

{
return $this->isPriceEqualAcrossChildProducts();
}

/**
* Check whether Configurable options do not have price difference
*
* @return bool
*/
public function isPriceEqualAcrossChildProducts(): bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it should be private method

cc @engcom-Bravo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Den4ik,

Please elaborate.
This method is called in template to decide if “as low as” label should be rendered.

Also, it replaces isChildProductsOfEqualPrices, as we don’t need to pass arguments for the check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swnsma,
You're right, for some reason I missed using this method in the template.

{
$minPrice = $this->getMinRegularAmount()->getValue();
$final_price = $product->getFinalPrice();
$productId = $product->getId();
if ($final_price < $minPrice) {

if ($this->product instanceof Product && $this->product->getFinalPrice() < $minPrice) {
return false;
}
$attributes = $product->getTypeInstance()->getConfigurableAttributes($product);
$items = $attributes->getItems();
$options = reset($items);
$maxPrice = $this->configurableMaxPriceCalculator->getMaxPriceForConfigurableProduct($productId);
if ($maxPrice == 0) {

$maxPrice = $this->configurableMaxPriceCalculator
->getMaxPriceForConfigurableProduct((int) $this->product->getId());
if ($maxPrice === 0.0) {
$maxPrice = $this->getMaxRegularAmount()->getValue();
}
return (count($options->getOptions()) > 1) && $minPrice == $maxPrice;

return $minPrice === $maxPrice;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
* All Rights Reserved.
*/

/** @var $escaper \Magento\Framework\Escaper */
Expand All @@ -14,12 +14,11 @@ $finalPriceModel = $block->getPriceType('final_price');
$regularPriceModel = $block->getPriceType('regular_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
$product = $regularPriceModel->getProduct();
?>
<span class="normal-price">
<?= /* @noEscape */
$block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => $regularPriceModel->isChildProductsOfEqualPrices($product) ? '' : __('As low as'),
'display_label' => $regularPriceModel->isPriceEqualAcrossChildProducts() ? '' : __('As low as'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand All @@ -11,12 +11,21 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Block\Product\ListProduct;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Test\Fixture\AssignProducts as AssignProductsFixture;
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture;
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
use Magento\Eav\Model\Entity\Collection\AbstractCollection;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Fixture\AppIsolation;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Store\ExecuteInStoreContext;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -129,6 +138,48 @@ public function testCheckConfigurablePriceOnSecondWebsite(): void
$this->assertProductPrice('configurable', '$150.00');
}

#[
AppIsolation(true),
DataFixture(CategoryFixture::class, [], 'category'),
DataFixture(ProductFixture::class, [
'sku' => 'simple_1',
'price' => 10.0,
'visibility' => Visibility::VISIBILITY_NOT_VISIBLE
], 'p1'),
DataFixture(AttributeFixture::class, as: 'attr'),
DataFixture(
ConfigurableProductFixture::class,
[
'sku' => 'configurable',
'_options' => ['$attr$'],
'_links' => ['$p1$']
],
'configurable'
),
DataFixture(
AssignProductsFixture::class,
['products' => ['$configurable$', '$p1$'], 'category' => '$category$'],
as: 'assignProducts'
)
]
public function testCheckConfigurablePriceOnOneSimple(): void
{
$this->resetPageLayout();
$fixtures = DataFixtureStorageManager::getStorage();

$this->registry->unregister('current_category');
$this->registry->register(
'current_category',
$fixtures->get('category')
);
$this->page->addHandle(['default', 'catalog_category_view']);
$this->page->getLayout()->generateXml();

$this->assertCollectionSize(1, $this->getListingBlock()->getLoadedProductCollection());
$priceHtml = $this->getListingBlock()->getProductPrice($this->getProduct('configurable'));
$this->assertStringContainsString('$10.00', $this->clearPriceHtml($priceHtml));
}

/**
* @param string $sku
* @param string $priceString
Expand Down