magento2: "Fatal error: Uncaught TypeError" in Cart when Flat Catalog is enabled and Quote contains disabled Configurable product
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 (*)
- 2.2.7 CE
Steps to reproduce (*)
backend:
- activate persistent cart
- activate flat product catalog
- create configurable product SKU
parent - create at least one child configuration item with SKU
child - reindex in the cli:
indexer:reindex catalog_product_flat
frontend:
- create new customer & login
- add configurable product
childto cart - log out
backend:
- set status of
childtodisabled
frontend:
- login as customer
- 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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 22 (14 by maintainers)
facing same in 2.2.7
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
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”
@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.