skip to Main Content

I have some issues saving categories in Magento 2.3.5, when I click save after changing the SEO information (Meta Title, Meta description and Meta Keywords) gives me this error.

Argument 1 passed to MagentoCatalogModelCategoryFileInfo::removeStorePath() must be of the type string, array given, called in /home/adminpsol2016/public_html/vendor/magento/module-catalog/Model/Category/FileInfo.php on line 167

here you can see a screenshot of the problem.

Magento 2.3.5 Categories issues

2

Answers


  1. This gave me quite a headache but finally managed to get to the bottom of it; my case is as follow:

    Repro:

    • add a custom category attribute with backend_model := MagentoCatalogModelCategoryAttributeBackendImage
    • Have the category form save operation fail for whatever reason (e.g. have a plugin on the category model save function which throws an Exception)

    Reason:

    If you look at https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php#L240 you’ll see that this has the effect of storing the entire POST data of the current form request to session (also the LocalizedException block does the same).
    Later on, this data is restored in https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L95 and immediately after the form information for the image attribute is stripped/cleared.
    This of course does not handle any custom attribute of Image type we might have defined for our category entity.

    Solution:

    I added an after* plugin (in adminhtml area only) on MagentoFrameworkSessionSessionManager::__call, where I explicitly check that the invoked method is getCategoryData: if this is the case, I fetch all the custom category image attributes, and strip them from the returned array like Category/Edit does.

    This way any further exception message is correctly displayed in the backoffice (granted it extends LocalizedException)

    Login or Signup to reply.
  2. Just to expand on the answer from Francesco Salvi which really helped me with the same problem, this is how we implemented that solution:

    etc/adminhtml/di.xml

    <?xml version="1.0" ?>
    <config>
        <type name="MagentoFrameworkSessionSessionManager">
            <plugin name="pluginNameGoesHere" type="VendorNamespacePluginStripCustomImage" />
        </type>
    </config>
    

    plugin/StripCustomImage.php

    <?php
    namespace VendorNamespacePlugin;
    
    class StripCustomImage
    {
        public function after__call($method, $response, ...$args)
        {
            if ($args[0] === 'getCategoryData') {
                if (isset($response['widget_image']['delete'])) {
                    $response['widget_image'] = null;
                } else {
                    unset($response['widget_image']);
                }
            }
    
            return $response;
        }
    }
    

    Where ‘widget_image’ is the attribute name for the custom category image we created in another module that was causing us the pain.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search