Skip to content
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

Configurable product with a subproduct of price '0' results in an error #4314

Closed
kanduvisla opened this issue Apr 26, 2016 · 4 comments
Closed
Assignees

Comments

@kanduvisla
Copy link
Contributor

kanduvisla commented Apr 26, 2016

Steps to reproduce

  1. Create a configurable product
  2. Give one of the subproducts a price of '0'.
  3. Watch how the product grid crashes and gives you the error: Configurable product "%1" do not have sub-products

Expected result

That the product grid doesn't crash.

Actual result

The product grid crashes

Source + Fix

I think the source of this problem lies in \Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver::resolvePrice():

/**
 * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
 * @return float
 * @throws \Magento\Framework\Exception\LocalizedException
 */
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
{
    $price = null;
    foreach ($this->configurable->getUsedProducts($product) as $subProduct) {
        $productPrice = $this->priceResolver->resolvePrice($subProduct);
        $price = $price ? min($price, $productPrice) : $productPrice;
    }
    if (!$price) {
        throw new \Magento\Framework\Exception\LocalizedException(
            __('Configurable product "%1" do not have sub-products', $product->getName())
        );
    }
    return (float)$price;
}

The following line always sets the price to the lowest price:

$price = $price ? min($price, $productPrice) : $productPrice;

With a price of '0', the if (!$price) will cause an exception to be thrown. The fix should be to strict check this:

if ($price === null) {
@mikeweis mikeweis self-assigned this Apr 26, 2016
@kandy kandy added the MX label Apr 26, 2016
@mikeweis
Copy link

I cannot re-create this bug.

  • My first attempt:
    • on the back-end, from Catalog page, add a Configurable Product
    • enter basic product details, such as name, SKU, ...
    • in the Configurations section, press the Create Configurations button
    • in Step 1, I chose the existing color attribute, then pressed Next
    • in Step 2, I created/chose two options (red, blue), then pressed Next
    • in Step 3, I kept the defaults, specifically ...
      • Skip price at this time
      • ... then pressed Next
    • in Step 4, I pressed Next
    • back on the New Product creation page, I changed the "red" variation to 0 (zero)
    • I pressed Save (or Save & Close)
    • everything saved properly
    • on the frontend, I verified my configurable product showed me the expected prices
  • My second attempt:
    • (repeat the above, until Step 3 ...)
    • in Step 3, I changed the Price selection to "Apply unique prices by attribute to each SKU"
      • still in Step 3, I changed my "red" variation to 0 (and my "blue" variation to 5)
      • ... then pressed Next
    • (continue as above from Step 4, and verified all worked as expected)

Please provide any additional details to help re-create the bug you are seeing.

@mslabko
Copy link
Member

mslabko commented Apr 28, 2016

Hello @kanduvisla ,
The issue was fixed in develop branch in 59f9546

It will be available in next 2.1 release

Thank you for reporting!

@mikeweis
Copy link

related issue is #3912

@riccardogiorato
Copy link

Can you help me I need to fix this bug in 2.0.7 but I can't find the right way to make the overide of the resolveprice() function in app code. Someone can help me out?

Here's my full question: magento.stackexchange.com/questions

Can you help me @mikeweis @kanduvisla ??

magento-engcom-team pushed a commit to okorshenko/magento2 that referenced this issue Jun 6, 2019
[Owls] MC-16318: Flaky MFTF Test: MAGETWO-93965: creating scheduled update for staging dashboard with max year value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants