6

When I add a configurable product in Magento CE 2.2.3, I try to add variations. No problems so far. When I return to the product edit screen I see the variations. When I try to save the product I get the following error (changed user and domain).

Got error

PHP message: PHP Fatal error:  Uncaught Error: Call to undefined method Magento\\Catalog\\Model\\Product\\Type\\Simple::getConfigurableAttributeCollection() in vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php:52
Stack trace:
#0 vendor/magento/module-configurable-product/Model/Product/ReadHandler.php(48): Magento\\ConfigurableProduct\\Helper\\Product\\Options\\Loader->load(Object(Magento\\Catalog\\Model\\Product\\Interceptor))
#1 vendor/magento/framework/EntityManager/Operation/Read/ReadExtensions.php(48): Magento\\ConfigurableProduct\\Model\\Product\\ReadHandler->execute(Object(Magento\\Catalog\\Model\\Product\\Interceptor), Array)
#2 vendor/magento/framework/EntityManager/Operation/Read.php(112): Magento\\Framework\\EntityManager\\Operation\\Read\\ReadExtensions->execute(Object(Magento\\Catalog\\Model\\Product\\Interce...', 
referer: http://domain.com/admin/catalog/product/edit/id/4670/set/54/type/configurable/store/0/key/3c6931241c19f977a1c6f03ae3207a09140b29c47712291add87d3fcd84df4da/back/edit/

Please help.

6

I had the same problem and when I changed

$objectManager->get('\Magento\Catalog\Model\Product')->load($productId)

into

$objectManager->create('\Magento\Catalog\Model\Product')->load($productId)

the problem disappeared.

4
  • I have the same issue.Did you edited in this path /root_dir/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php – Vindhuja May 23 '19 at 12:16
  • No. Never edit core files! – Zsolti May 24 '19 at 11:53
  • Then, where did yoy edit. Did youoverrided this file – Vindhuja May 27 '19 at 4:18
  • Most probably I've overridden it. – Zsolti May 28 '19 at 13:18
2

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

source: - https://github.com/magento/magento2/issues/21663#issuecomment-674535792

0

I found this error also occurs when trying to access the admin catalog grid..

This query to DB to resets any admin filters tied to your user ID:

DELETE FROM ui_bookmark WHERE user_id = <YOUR_USER_ID>;

This worked for me.

0

This is a core issue in Magento 2. Here is the issue url: https://github.com/magento/magento2/issues/21663

You can try these two answers in the above issue:

  1. https://github.com/magento/magento2/issues/21663#issuecomment-477966963

  2. https://github.com/magento/magento2/issues/21663#issuecomment-501121021

0

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
/**
 * Copyright ©  All rights reserved.
 * See COPYING.txt for license details.
 */
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
 * @package Custom\Module\Helper\Product\Options
 */
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;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.