Magento2: "Fatal error: Uncaught TypeError" in Cart when Flat Catalog is enabled and Quote contains disabled Configurable product

Created on 17 Dec 2018  路  22Comments  路  Source: magento/magento2

if persistent cart is enabled, a user's quote might contain a product that is now disabled in the catalog. if this happens when Flat Product Catalog is enabled, the cart page will throw a Fatal Error, and the entire cart functionality will not be usable for this customer until the quote is manually deleted from the database.

Preconditions (*)

  1. 2.2.7 CE

Steps to reproduce (*)

backend:

  1. activate persistent cart
  2. activate flat product catalog
  3. create configurable product SKU parent
  4. create at least one child configuration item with SKU child
  5. reindex in the cli: indexer:reindex catalog_product_flat

frontend:

  1. create new customer & login
  2. add configurable product child to cart
  3. log out

backend:

  1. set status of child to disabled

frontend:

  1. login as customer
  2. open cart

Expected result (*)

a) cart is showing product child but as "not available anymore"
b) cart is empty

Actual result (*)

  • cart page isn't showing the product
  • error is logged
  • no further product can be added to the cart
  • checkout fails
Fatal error: Uncaught TypeError: Return value of Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver::getChildProduct() must be an instance of Magento\Catalog\Model\Product, null returned in /var/www/users/demo/src/www/vendor/magento/module-configurable-product/Model/Product/Configuration/Item/ItemProductResolver.php:83
Stack trace: 
#0 /var/www/users/demo/src/www/vendor/magento/module-configurable-product/Model/Product/Configuration/Item/ItemProductResolver.php(51): Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver->getChildProduct(Object(Magento\Quote\Model\Quote\Item\Interceptor)) 
#1 /var/www/users/demo/src/www/vendor/magento/module-catalog/Model/Product/Configuration/Item/ItemResolverComposite.php(44): Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver->getFinalProduct(Object(Magento\Quote\Model\Quote\Item\Interceptor)) 
#2 /var/www/users/demo/src/www/vendor/magento/module-checkout/Block/Cart/Item/Re in /var/www/users/demo/src/www/vendor/magento/module-configurable-product/Model/Product/Configuration/Item/ItemProductResolver.php on line 83

2.2.7 added an explicit return type in ItemProductResolver::getChildProduct() which doesn't allow returning null: private function getChildProduct(ItemInterface $item): Product. while this is the reason for the fatal error, the underlying problem seems to be that the flat catalog doesn't contain disabled items and thus will return null for disabled products.

Clear Description Format is valid

Most helpful comment

facing same in 2.2.7

All 22 comments

Hi @heldchen. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@heldchen do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-backlog-andrii. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [x] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

@magento-engcom-team give me 2.2.7 instance

Hi @heldchen. Thank you for your request. I'm working on Magento 2.2.7 instance for you

Hi @heldchen, here is your Magento instance.
Admin access: https://i-19842-2-2-7.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@heldchen could you post a PR maybe? Just changing return type to ?Product should be sufficient.

@orlangur I've tried that, it is not sufficient. the ItemResolverInterface requires a non-null class implementing ProductInterface as well, and then a bunch of other places start to fail...

@heldchen do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [x] yes
  • [ ] no

disclaimer: the engcom temp instance cannot be used to properly demonstrate the error in full, due to the lack of cli access required for reindexing / error logging. it still shows the problem tho as the cart and checkout is unusable even in the encom instance after the outlined steps.

@heldchen This issue is resolved in Magento 2.3

@mallikaverma good to know. looking forward to a 2.2 backport as our customers want to see 2.3 mature a bit first...

HI @heldchen. Thanks for the report. This problem has already been fixed on 2.3 develop

@engcom-backlog-andrii why is this closed now? 2.2 is still a supported version and thus the problem should be fixed for this branch as well.

@heldchen only issues for the most relevant stable Magento vesion should remain open.

@engcom-backlog-andrii maybe it would be good to have Reproduced in 2.2.x label for this closed issue?

maybe I'm not understanding the details of magento's issue handling, but that reads to me as: "this checkout-breaking issue will not be fixed for 2.2, tough luck for anyone not upgrading"

@heldchen,

this checkout-breaking issue will not be fixed for 2.2

Such assumption is not based on anything as to me.

This issue was specifically raised as a 2.2.7 problem. It would be great to get a solution for the most relevant stable Magento version - in this case 2.2.

If you close a ticket how is anyone going to pick this up for a 2.2 port as this clearly needs?

It would help to at least have a relevant pull for 2.3 so that someone can work on a solution for 2.2.

I am facing this issue on 2.3.0

facing same in 2.2.7

Why has this been closed @engcom-backlog-tomash when it has not been fixed?

Reopening on the ground of @johnny-longneck comment to check whether it exists in 2.3.x.

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

Hi @johnny-longneck this issue was tested and we can confirm that this already fixed in 2.3-develop branch and available on 2.3.1 release

Was this page helpful?
0 / 5 - 0 ratings