magento2: Call to undefined method Magento\Bundle\Model\Product\Type::getConfigurableAttributeCollection()
1) Summary of the issue
I have faced the below issue on Magento 2.2.6 before we have migration from M1.1.9 to M2.2.6
When I added Configurable products on the cart then added Simple product on the cart will facing error but when we added Simple product on the cart then added Configurable product on the cart after working fine
2) Information on your environment
- Magento 2.2.6
- Nginx and apache Server
3) Steps to reproduce 1) Migrate 1.1.9 to 2.2.6 2) first we add Bundle product on cart 3) second we add configurable product on cart
4) Expected results - how to solve this issue and how to sure after migration, not breakup functionality?
5) Actual results
-
When we add Configurable products on the cart then add Simple product on the cart will facing error
PHP Fatal error: Uncaught Error: Call to undefined method Magento\\Bundle\\Model\\Product\\Type::getConfigurableAttributeCollection() in /var/www/html/magentothird/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php:53\nStack trace:\n#0 /var/www/html/magentothird/vendor/magento/module-configurable-product/Model/Product/ReadHandler.php(48): Magento\\ConfigurableProduct\\Helper\\Product\\Options\\Loader->load(Object(Magento\\Catalog\\Model\\Product\\Interceptor))\n#1 /var/www/html/magentothird/vendor/magento/framework/EntityManager/Operation/Read/ReadExtensions.php(48): Magento\\ConfigurableProduct\\Model\\Product\\ReadHandler->execute(Object(Magento\\Catalog\\Model\\Product\\Interceptor), Array)\n#2 /var/www/html/magentothird/vendor/magento/framework/EntityManager/Operation/Read.php(112): Magento\\Framework\\EntityManager\\Operation\\Read\\ReadExtensions->execute(Object(Magento\\Catalog\\Model\\Product\\Interceptor), Array)\n#3 /var/www/html/magentothird/vendor/magento/framework/EntityManager/EntityManager.php(70): Magento\\Framework\\Ent in /var/www/html/magentothird/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php on line 53, referer: http://ehp2.root.com/ehp-configurable.html
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (4 by maintainers)
Figured out a the solution for our issue with simple products;
First extend;
Magento\Catalog\Model\Product\Type\Simple
Add function; public function getConfigurableAttributeCollection(\Magento\Catalog\Model\Product $product) { return false; }
Then extend;
Magento\ConfigurableProduct\Helper\Product\Options\Loader
Rewrite the function load() and replace this part;
$attributeCollection = $typeInstance->getConfigurableAttributeCollection($product); $this->extensionAttributesJoinProcessor->process($attributeCollection);
With;
$attributeCollection = $typeInstance->getConfigurableAttributeCollection($product); // this now returns false if this is a simple product
if($attributeCollection) { $this->extensionAttributesJoinProcessor->process($attributeCollection); } else { $attributeCollection = array(); } …
Check your custom modules or extensions and find if you are using either of the following -:
Magento\Catalog\Model\Product (in the constructor)
$this->_product->load($id)
or
$this->_objectManager->get(‘\Magento\Catalog\Model\Product’)->load($id)
If yes then change it to use \Magento\Catalog\Api\ProductRepositoryInterface and load product using getById($id) instead. Hope it helps
The reason for the issue is using a deprecated load method for models. You should use API Repository for loading the products.
To reproduce needs to inject Product model (not factory) to the constructor
I found temporary solution adding simple condition in
Magento\ConfigurableProduct\Helper\Product\Options\Loader::load(ProductInterface $product)after line no : 51On production following code works: File:
vendor\magento\module-configurable-product\Helper\Product\Options\Loader.phpAdd below code after line # 51