Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ankit-root opened this issue Mar 9, 2019 · 19 comments

Comments

@ankit-root
Copy link

ankit-root commented Mar 9, 2019

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

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Mar 9, 2019
@magento-engcom-team
Copy link
Contributor

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

@ankit-root
Copy link
Author

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

@magento-engcom-team
Copy link
Contributor

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

@ankit-root ankit-root reopened this Mar 9, 2019
@magento-engcom-team
Copy link
Contributor

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.

@ankit-root
Copy link
Author

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?

@ankit-root
Copy link
Author

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

@pixiemediaweb
Copy link

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 ?

@pixiemediaweb
Copy link

pixiemediaweb commented Mar 29, 2019

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

@visahardik
Copy link

visahardik commented Jun 12, 2019

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;
}

@mitcht
Copy link

mitcht commented Oct 30, 2019

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)

@mitcht
Copy link

mitcht commented Nov 4, 2019

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.

@MichaelThessel
Copy link

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.

@WouterStulp
Copy link

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?

@ant0x64
Copy link

ant0x64 commented Mar 11, 2020

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

@hostep
Copy link
Contributor

hostep commented Mar 26, 2020

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.

@webspeaks
Copy link

webspeaks commented May 14, 2020

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;
}

@scommercemage
Copy link

scommercemage commented Aug 16, 2020

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

@ghost ghost added Issue: ready for confirmation and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Oct 21, 2020
@stale
Copy link

stale bot commented Jan 5, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale issue label Jan 5, 2021
@stale stale bot closed this as completed Jan 19, 2021
@jesalazar
Copy link

jesalazar commented Mar 24, 2021

Is not recommended edit the core files either magento or any framework. I made one override to the class. I don't know if there is a best way to fix this issue, but for mi works.

di.xml:

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\ConfigurableProduct\Helper\Product\Options\Loader" type="Custom\Module\Helper\Product\Options\Loader"/> </config>

Override:

`<?php

declare(strict_types=1);

namespace Custom\Module\Helper\Product\Options;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\ConfigurableProduct\Api\Data\OptionValueInterfaceFactory;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;

class Loader extends \Magento\ConfigurableProduct\Helper\Product\Options\Loader
{
/**
* @var OptionValueInterfaceFactory
*/
private $optionValueFactory;

/**
 * @var JoinProcessorInterface
 */
private $extensionAttributesJoinProcessor;

/**
 * Loader constructor.
 * @param OptionValueInterfaceFactory $optionValueFactory
 * @param JoinProcessorInterface $extensionAttributesJoinProcessor
 */
public function __construct(
    OptionValueInterfaceFactory $optionValueFactory,
    JoinProcessorInterface $extensionAttributesJoinProcessor
) {
    $this->optionValueFactory = $optionValueFactory;
    $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
}

/**
 * @param ProductInterface $product
 * @return OptionInterface[]
 */
public function load(ProductInterface $product): array
{
    $options = [];
    /** @var Configurable $typeInstance */
    $typeInstance = $product->getTypeInstance();
    if ($typeInstance instanceof \Magento\Catalog\Model\Product\Type\Simple ||
        $typeInstance instanceof \Magento\Bundle\Model\Product\Type) {
        return $options;
    }

    $attributeCollection = $typeInstance->getConfigurableAttributeCollection($product);
    $this->extensionAttributesJoinProcessor->process($attributeCollection);
    foreach ($attributeCollection as $attribute) {
        $values = [];
        $attributeOptions = $attribute->getOptions();
        if (is_array($attributeOptions)) {
            foreach ($attributeOptions as $option) {
                /** @var \Magento\ConfigurableProduct\Api\Data\OptionValueInterface $value */
                $value = $this->optionValueFactory->create();
                $value->setValueIndex($option['value_index']);
                $values[] = $value;
            }
        }
        $attribute->setValues($values);
        $options[] = $attribute;
    }

    return $options;
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests