1
votes

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 Magento\Catalog\Model\Category\FileInfo::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

1
I would recommend consulting the documentation for Magento. The error is pretty clear to me, but I don't know why it would be receiving an array rather a string via the administration interface unless you're somehow passing in an array manually. If this is not the case, it is a defect in Magento (assuming you haven't mucked about with their code) and you should contact their support team. - Jeremy Anderson
Thank you, haven't touch the code, i am just passing a string in the meta title field and the keywords. - Andres Gonzalez
Did you found any solution for this? I'm having same problem - Ranganathan
Hi there, I got same issue, did you find a solution for this @Ranganathan? - wandyyd
Oddly enough, I have this issue too but in my local environment only (the deployed app allows to upload images just fine) - Francesco Salvi

1 Answers

3
votes

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 := Magento\Catalog\Model\Category\Attribute\Backend\Image
  • 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 \Magento\Framework\Session\SessionManager::__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)