1

Can you help me to add custom field for the image on my category?

I want to add a thumbnail for my category via admin panel, and then get it on front-end.

I have now eav attribute in eav_attribute table, but it still doesn't appear in admin panel.

Thanks!

3
1
    protected $categorySetupFactory;

    public function __construct(
        ...
        \Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory    
        ....
    ) {
        ....
        $this->categorySetupFactory = $categorySetupFactory;    
        ....
    }

Now In your setup file you can use this like,

         $setup = $this->categorySetupFactory->create(['setup' => $setup]);         
         $setup->addAttribute(
            \Magento\Catalog\Model\Category::ENTITY, 'custom_image', [
                'type' => 'varchar',
                'label' => 'Custom Image',
                'input' => 'image',
                'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
                'required' => false,
                'sort_order' => 9,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'group' => 'General Information',
            ]
        );
5
  • It works and eav attribute added to table, but there is no field in admin panel to add image Sep 7 '17 at 8:15
  • Yes, it was my bad sorry :) , I think its too long answer but you can use this blog belvg.com/blog/…
    – Keyur Shah
    Sep 7 '17 at 8:22
  • Thanks! It works, but when I try to save, it returns me 404 error from my ajax in my browser console Sep 8 '17 at 7:41
  • Glad to hear that, in that case you can ask a new question with your code so someone can answer your question @KyryloRomantsov
    – Keyur Shah
    Sep 8 '17 at 7:42
  • check out my new question please magento.stackexchange.com/questions/192801/… Sep 11 '17 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.