During Magento customization, many of our clients request to extend the default functionality of Magento 2 categories. Recently one of them asked to add custom image attribute in category of Magento 2. To fulfill the requirement, I develop below code which I would like to share with you.
You need to add custom image attribute in the following files:
app/code/Vendor/Categoryattribute/Setup/ UpgradeData.php
First of all we need to add the attribute with proper parameters. Use code below:
If you have properly followed the code, image attribute would have been added to category in Magento 2 category.
Now once we have created the attribute, we need to save it in backend. Use following code:
Hope you followed the code properly and could create custom image attribute. If you are stuck between somewhere, I’m always there to provide you with solution. Comment your queries and suggestions.
Enjoy Coding!