Question

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

Was it helpful?

Solution

Possible ways to debug further.

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

OTHER TIPS

In my case the attribute was not existed so I was needed to restore missed eav entities. Did it with \Magento\Catalog\Setup\Patch\Data\UpdateCustomLayoutAttributes Data Patch

Just remove the installed state flag from patch_list and make setup:upgrade

I got this problem as well, because of a missing category attribute in the eav_attribute table. Try to run the query below. And if you are missing this attribute, you might be missing other attributes as well. Please compare the eav_attribute table in a new Magento 2 installation with your own to see if you are missing something.

INSERT INTO `eav_attribute` (`entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`) VALUES

(4, 'custom_layout_update_file', NULL, 'Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\LayoutUpdate', 'varchar', NULL, NULL, 'select', 'Custom Layout Update', NULL, 'Magento\\Catalog\\Model\\Product\\Attribute\\Source\\LayoutUpdate', 0, 0, NULL, 0, NULL),
(3, 'custom_layout_update_file', NULL, 'Magento\\Catalog\\Model\\Category\\Attribute\\Backend\\LayoutUpdate', 'varchar', NULL, NULL, 'select', 'Custom Layout Update', NULL, 'Magento\\Catalog\\Model\\Category\\Attribute\\Source\\LayoutUpdate', 0, 0, NULL, 0, NULL);

Did you find a solution for this?

I am able to create a new category, but editing existing categories does not work, also unable to move the categories. I upgraded from Magento 1.9.x to 2.3.4 and have the same error message as yourself.

changing flat file catalog and re-indexing has not resolved it.

I will look at comparing the new category against the old one and see if I can see any difference between the database values.

I'm having a similar problem after updating from 2.3.4 to 2.3.4-p2, in my case, Custom Layout Update is empty. The patch_list table does not contain Magento \ Catalog \ Setup \ Patch \ Data \ UpdateCustomLayoutAttributes, so I ran setup: upgrade but the table has not been updated and Custom Layout Update is still empty. Any idea?

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top