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 1 commit
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
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'];

Choose a reason for hiding this comment

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

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
Expand Up @@ -196,26 +196,25 @@ public function _resetState(): void
}

/**
* Check whether Configurable Product have more than one children products
* 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.

{
$minPrice = $this->getMinRegularAmount()->getValue();
$final_price = $product->getFinalPrice();
$productId = $product->getId();
if ($final_price < $minPrice) {
$finalPrice = $product->getFinalPrice();
$productId = (int)$product->getId();
if ($finalPrice < $minPrice) {
return false;
}
$attributes = $product->getTypeInstance()->getConfigurableAttributes($product);
$items = $attributes->getItems();
$options = reset($items);

$maxPrice = $this->configurableMaxPriceCalculator->getMaxPriceForConfigurableProduct($productId);
if ($maxPrice == 0) {
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
Expand Up @@ -129,6 +129,17 @@ public function testCheckConfigurablePriceOnSecondWebsite(): void
$this->assertProductPrice('configurable', '$150.00');
}

/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_one_simple_with_category.php
*
* @return void
*/
public function testCheckConfigurablePriceOnOneSimple(): void
{
$this->resetPageLayout();
$this->assertProductPrice('configurable', '$10.00');
}

/**
* @param string $sku
* @param string $priceString
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Catalog\Api\CategoryLinkManagementInterface;
use Magento\Catalog\Helper\DefaultCategory;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;

Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category.php');
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_product_with_one_simple.php');

$objectManager = Bootstrap::getObjectManager();
/** @var CategoryLinkManagementInterface $categoryLinkManagement */
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class);
/** @var DefaultCategory $categoryHelper */
$categoryHelper = $objectManager->get(DefaultCategory::class);

foreach (['simple_1', 'configurable'] as $sku) {
$categoryLinkManagement->assignProductToCategories($sku, [$categoryHelper->getId(), 333]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\TestFramework\Workaround\Override\Fixture\Resolver;

Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_rollback.php');
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_product_with_one_simple_with_category.php');