Magento 2.3.4 Error Call to a Member Function Get Attribute Code

I upgrade my store to Magento 2.3.4 version and suddenly I can’t save / edit categories, after I press the Save button I have this error in admin: Something went wrong while saving the category. When I check var/log/debug.log file I found this error:

main.CRITICAL: Error: Call to a member function getAttributeCode() on bool in /chroot/home/a593d01f/html/vendor/magento/module-catalog/Observer/InvalidateCacheOnCategoryDesignChange.php:67

and when I check

vendor/magento/module-catalog/Observer/InvalidateCacheOnCategoryDesignChange.php:67

I have this part of code:

public function execute(Observer $observer)
{
    $category = $observer->getEvent()->getEntity();
    if (!$category->isObjectNew()) {
        foreach ($category->getDesignAttributes() as $designAttribute) {
            if ($this->isCategoryAttributeChanged($designAttribute->getAttributeCode(), $category)) {
                $this->cacheTypeList->invalidate(
                    [
                        \Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER,
                        \Magento\Framework\App\Cache\Type\Layout::TYPE_IDENTIFIER
                    ]
                );
                break;
            }
        }
    }
}

If I comment out this:

        if ($this->isCategoryAttributeChanged($designAttribute->getAttributeCode(), $category)) {
            $this->cacheTypeList->invalidate(
                [
                    \Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER,
                    \Magento\Framework\App\Cache\Type\Layout::TYPE_IDENTIFIER
                ]
            );
            break;
        }

everything is work fine with categories. Is a magento bug? or how I can fix this?

Edit:

Theme dropdown attribute is empty, the name of this attribute is custom_design.

enter image description here

This Post Has One Comment

  1. No Fault

    1. First try

    Check If Flat catalog for category ENABLED then DISABLE it or if Flat Catalog for category found DISABLED then ENABLE it.

    Perform full reindexing

    Then try to save any category again, it should work.

    2. If not solving then try to add the instance check condition like below: Culprit attribute can be found by removing the comment in the first if condition.

    foreach ($category->getDesignAttributes() as $designAttribute) {
    if(!$designAttribute instanceOf \Magento\Eav\Model\Entity\Attribute){
    //$designAttribute->getAttributeCode(); die(‘s’);
    continue;
    }

    if ($this->isCategoryAttributeChanged($designAttribute->getAttributeCode(), $category)) {
    $this->cacheTypeList->invalidate(
    [
    \Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER,
    \Magento\Framework\App\Cache\Type\Layout::TYPE_IDENTIFIER
    ]
    );
    break;
    }
    }
    3rd thing you may try the last Review all the category attributes which are showing after executing the below query.

    Compare with native Magento’s instance table of the same entity_type_id.

    SELECT * FROM `eav_attribute` WHERE `entity_type_id` = 3

Leave a Reply