Magento2: Configurable products with first simple product 'out of stock' breaks catalog 2.1.1

Created on 29 Sep 2016  路  22Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2 CE 2.1.1, PHP7, MYSQL14.14

Steps to reproduce

  1. Fresh install 2.1.1
  2. add new configurable product with multiple simple products (ie color red,blue,yellow with qty's >0)
  3. Product is now displaying on frontend as expected
  4. Now go back to admin and mark first (lowest product id) simple product as 'out of stock'.

Expected result

  1. Display configurable product as normal on frontend

    Actual result

  1. 1 exception(s):
    Exception #0 (Magento\Framework\Exception\LocalizedException): Configurable product "BSBG" does not have sub-products

Exception #0 (Magento\Framework\Exception\LocalizedException): Configurable product "BSBG" does not have sub-products

0 /home/72576-57509.cloudwaysapps.com/jpyshppark/public_html/vendor/magento/module-configurable-product/Pricing/Price/FinalPrice.php(43): Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver->resolvePrice(Object(Magento\Catalog\Model\Product\Interceptor))

  1. Product not visible on frontend, any category pages this product appears on will not show other products either.
Catalog Cannot Reproduce Clear Description Format is valid Ready for Work bug report

Most helpful comment

Found the solution!

The problem appears to be that, in the price resolver (\Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver), the resolvePrice method loops through the simple products of the configurable looking for a price for an available item. When all items are out of stock, there is no price to return.
I fixed this by adding the line:

$price = $price ? $price : $product->getData('price');

after the foreach loop. This will get the configurable product price.

All that is required is to override this class in your own module and add the line above.

All 22 comments

Hi @staffrob , thank for report
Internal ticket MAGETWO-58922, is in our issue backlog.

probably a duplicate of #6422 and related to #6512

Did some debugging here in this related thread: #5762

@nissablagojevic saw your debug and would like to know where you found ->limit(1).

In version 2.1.2 (after upgrade from 2.1.1 with same problems) the problem still exists.
The frontend catalog page can not display product where config product has one-or-more out-of-stock childproduct(s) (variation).
The var/system.log contains:
"main.Critical: Configurable product "[sku]" does not have sub-pruducts"

If i increase qty and set prodcut "in-stock" on the out-of-stock child, the frontend shows as expected.
If i set qty to zero and stock status: out-of stock, the error comes back.

I can reproduce this situation with 2 different magento installation.

Hi,
I have the same issue after upgrading to 2.1.2, the problem still persists.
Any work around fix? Tried cleaning browser cache as advised by magento team. no result.

It says
Erreur lors du traitement du gabarit: Configurable product "kit_pro" does not have sub-products
Gives me list of exceptions attached.
exceptionlist.txt

@interpigeon @nmallepally: This pull request fixes the issue: https://github.com/magento/magento2/pull/7030
The treatment of this issue by @magento-admin is a shame. Next time I will reconsider twice before recommending Magento to a client again.

@immist Thanks.. Great, worked absolutely fine after applying the fix.
Just brought life to my Magento site. Thanks a mil.
Yes, it's sad Magento is not addressing the critical issues, even with cron indexing as well.
now, I can safely upgrade on to my live site now.

@nmallepally Please can you share with me what exactly you did?

I have just upgraded 2.1.2 to 2.1.3 and now price on configurable product page displays as $0 (zero) until an attribute is selected.

This only occurs if the first configurable attribute qty is 0 or out of stock.
If the first configurable attribute is in stock or >0 price on the cofigurable product page is as expected ie $79.95

Since upgrading to 2.1.3 we have this issue as well as stated by @staffrob

We're having the same issue as staffrob- configurable products with out of stock individual products are showing a price of $0 on both the catalog landing pages and the individual product pages. Magento 2.1.4

I have the same issue - price on configurable product displays as $0, if configurable attribute qty is 0 or out of stock. Magento 2.1.5

Magento 2.1.7 and I'm still having the same issue, price shows 0 if all the simple products are out of stock

@Szymon-GP Yes me too. Magento 2.1.6

Still the same on 2.1.8 :/ ($0 product)

Found the solution!

The problem appears to be that, in the price resolver (\Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver), the resolvePrice method loops through the simple products of the configurable looking for a price for an available item. When all items are out of stock, there is no price to return.
I fixed this by adding the line:

$price = $price ? $price : $product->getData('price');

after the foreach loop. This will get the configurable product price.

All that is required is to override this class in your own module and add the line above.

@wildcard27 that doesn't seem to work with multi-currency..

@erfanimani Seems to be working on my project with multi currency. Do you have any errors is it just failing?

@wildcard27 , actually - my bad. It's not working for product listings created through widget instances. Rest of the time it works fine with multi-currency. Probably a cache issue.

Thanks for sharing your solution!

Hello @staffrob. Your issue has been fixed in later versions. If You are still able to reproduce it on 2.1.9 please let us know.

@staffrob, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings