I'm a newbie with magento. I want to add two custom image fields to a category. I have created a module with installer file to my module:
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('catalog_category');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('catalog_category', 'image1', array(
'input' => 'image',
'type' => 'file',
'group' => 'General',
'label' => 'Additional image 1',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'frontend_input' =>'',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible_on_front' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'image1',
'999' //sort_order
);
$installer->endSetup();
I can see the image field when editing or adding new category but its not saving to database. How to make it work? Thanks
Try below code: $categoryId = 5; $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $object_manager = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId); echo "<pre>"; print_r($object_manager->getData()); die('shasha test');
Magento 2 allows store admins to add and remove products from the category under Magento 2 Admin panel > CATALOG > Categories > Products in Categories section.
To change the category layout, go to Products -> Categories -> Select your desired Category go to the Design tab and select desired option from the Layout dropdown.
To add a new image attribute for the categories, you need to use those values in your setup :
'type' => 'varchar',
'input' => 'image',
'backend' => 'catalog/category_attribute_backend_image',
instead of those ones :
'input' => 'image',
'type' => 'file',
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With