I have created custom image attribute. This is displaying perfect. But when i save category, it is not saving. Images are uploading perfectly, Saving at /media/tmp, but not saving in media/catalog after saving category magento 2.
3 Answers
Magento2.1 Category image upload showing preview after upload image but not working after save category.
this is magento version default bug.
To solve this issue by apply bellow patch.
Opne this url : https://github.com/magento/magento2/pull/5978/files
You have to override below core files code with file code from given URL.
vendor/magento/module-catalog/Controller/Adminhtml/Category/Image/Upload.php
vendor/magento/module-catalog/Controller/Adminhtml/Category/Save.php
vendor/magento/module-catalog/Model/Category.php
vendor/magento/module-catalog/Model/Category/Attribute/Backend/Image.php
vendor/magento/module-catalog/Model/Category/DataProvider.php
Now magento-2.1 working code for custom image attribute of category.
See complete answer for the issue : See my complete answer
Let me know if you have any query/concern from above.
-
-
You can get reference from given my answer otherwise you have add your code so i can debug on that. Oct 7, 2016 at 13:04
I solved this issue by setting the backend_model
for my attribute in the eav_attribute
table to Magento\Catalog\Model\Category\Attribute\Backend\Image
When a category is saved in Magento 2 it walks through the attributes calling the afterSave
function of each attribute.
As you can see below the function Magento\Catalog\Model\Category\Attribute\Backend\Image::afterSave
moves the file from the tmp folder to correct folder.
public function afterSave($object)
{
$image = $object->getData($this->getAttribute()->getName(), null);
if ($image !== null) {
try {
$this->getImageUploader()->moveFileFromTmp($image);
} catch (\Exception $e) {
$this->_logger->critical($e);
}
}
return $this;
}
-
this fails in \Magento\Catalog\Model\ImageUploader::moveFileFromTmp as the $baseTmpImagePath contains both $basePath and $baseTmpPath => the copyFile method fails– RaduApr 14, 2020 at 8:53
Check if you have created a preference for Magento\Catalog\Model\Category\DataProvider, and your new DataProvider has this code in it.
class DataProvider extends \Magento\Catalog\Model\Category\DataProvider {
protected function getFieldsMap()
{
$fields = parent::getFieldsMap();
$fields['content'][] = 'custom_attribute_name';
return $fields;
}
-
-
You can override only the public methods of AbstractPdf.php For protected methods, you can override the methods from where these methods are called. For example to override the method called insertLogo, override the Invoice.php which is calling insertLogo in getPdf method. Oct 29, 2018 at 4:32