Magento2: Call to undefined method Magento\Bundle\Model\Product\Type::getConfigurableAttributeCollection()

Created on 9 Mar 2019  路  17Comments  路  Source: magento/magento2

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

`

ready for confirmation

Most helpful comment

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();
}
...

All 17 comments

Hi @ankit-root. 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 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

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

  • [ ] yes
  • [ ] no

Hi @ankit-root. 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 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

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

  • [ ] yes
  • [ ] no

Hi @ankit-root. Thank you for your request. I'm working on Magento 2.3-develop instance for you

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

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

what will we do on instance server?

I have used the same scenario on your server it's working but after migration these not working.t

We are experiencing the same situation with configurable a simple products in the cart, Magento is trying to fetch getConfigurableAttributeCollection() on a simple product;

PHP Fatal error: Uncaught Error: Call to undefined method Magento\Catalog\Model\Product\Type\Simple::getConfigurableAttributeCollection()

Did you find anything useful @ankit-root ?

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();
}
...

I found temporary solution adding simple condition in Magento\ConfigurableProduct\Helper\Product\Options\Loader::load(ProductInterface $product) after line no : 51

if (get_class($typeInstance) == 'Magento\Catalog\Model\Product\Type\Simple' || get_class($typeInstance) == 'Magento\Bundle\Model\Product\Type') 
{
            return null;
}

This is still a problem.

FastCGI sent in stderr: "PHP message: PHP Fatal error:  
Uncaught Error: Call to undefined method Magento\Catalog\Model\Product\Type\Simple::getConfigurableAttributeCollection() 
in /var/www/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php:52
Stack trace:
#0 /var/www/vendor/magento/module-configurable-product/Model/Product/ReadHandler.php(48): Magento\ConfigurableProduct\Helper\Product\Options\Loader->load(Object(Magento\Catalog\Model\Product\Interceptor))
#1 /var/www/vendor/magento/framework/EntityManager/Operation/Read/ReadExtensions.php(48): Magento\ConfigurableProduct\Model\Product\ReadHandler->execute(Object(Magento\Catalog\Model\Product\Interceptor), Array)
#2 /var/www/vendor/magento/framework/EntityManager/Operation/Read.php(112): Magento\Framework\EntityManager\Operation\Read\ReadExtensions->execute(Object(Magento\Catalog\Model\Product\Interceptor), Array)

Just an update, I have a breakpoint set in Loader.php (magento-configurable-product\Helper\Product\Options\Loader.php) on line 52. At this breakpoint, the following things are true:

$product->getTypeId it is equal to "configurable"
$product->getTypeInstance() is equal to type "Magento\Catalog\Model\Product\Type\Simple.

I'm debugging to see if somehow i've managed to set this value, but its doubtful.

I'm seeing the same issue. In my case I get the error when searching for a sku using the keyword search field in the product grid in admin.

[Thu Feb 20 10:56:35.736401 2020] [php7:notice] [pid 651] [client 127.0.0.1:40020] PHP Fatal error:  Uncaught Error: Call to undefined method Magento\\Catalog\\Model\\Product\\Type\\Simple::getConfigurableAttributeCollection() in /data/src/m2/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php:52\nStack trace:\n#0 /data/src/m2/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 /data/src/m2/vendor/magento/framework/EntityManager/Operation/Read/ReadExtensions.php(48): Magento\\ConfigurableProduct\\Model\\Product\\ReadHandler->execute(Object(Magento\\Catalog\\Model\\Product\\Interceptor), Array)\n#2 /data/src/m2/vendor/magento/framework/EntityManager/Operation/Read.php(112): Magento\\Framework\\EntityManager\\Operation\\Read\\ReadExtensions->execute(Object(Magento\\Catalog\\Model\\Product\\Interceptor), Array)\n#3 /data/src/m2/vendor/magento/framework/EntityManager/EntityManager.php(70): Magento\\Framework\\EntityManager\\Operation\\Read->execute(Object(Magento\\Catalog\\Mode in /data/src/m2/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php on line 52

I will re-open this ticket as this is still being reported by multiple people and the proposed workarounds are just masking the problem.

Just an update, I have a breakpoint set in Loader.php (magento-configurable-product\Helper\Product\Options\Loader.php) on line 52. At this breakpoint, the following things are true:

$product->getTypeId it is equal to "configurable"
$product->getTypeInstance() is equal to type "Magento\Catalog\Model\Product\Type\Simple.

I'm debugging to see if somehow i've managed to set this value, but its doubtful.

@mitcht Did you get any results?

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 just saw this same error being thrown on a Magento 2.3.1 shop, having some particular products in your cart: bundled product + a configurable one. At the moment when you moved from the checkout to an external payment provider, a HTTP 500 error was thrown and we could see the error mentioned in this ticket in the error log on the server.

It turned out to get fixed by updating that Payment provider's module to the latest version.
More concretely, we were using https://github.com/MultiSafepay/Magento2Msp/releases version 1.7.1. By upgrading to 1.10.0 the issue got fixed.

So in this case, it was probably some incorrect code in the Payment provider module which caused the bug and might not have been a Magento core bug, but I can't say that with full confidence though.

Maybe this comment helps for other people who run into this and who are also using the MultiSafepay payment module.

On production following code works:
File: vendor\magento\module-configurable-product\Helper\Product\Options\Loader.php
Add below code after line # 51

if (strstr(get_class($typeInstance), 'Magento\Catalog\Model\Product\Type\Simple') !== false || strstr(get_class($typeInstance), 'Magento\Bundle\Model\Product\Type') !== false) {
    return null;
}

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

Was this page helpful?
0 / 5 - 0 ratings