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.



1 Answer 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]);         
            \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',
  • It works and eav attribute added to table, but there is no field in admin panel to add image Commented Sep 7, 2017 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
    Commented Sep 7, 2017 at 8:22
  • Thanks! It works, but when I try to save, it returns me 404 error from my ajax in my browser console Commented Sep 8, 2017 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
    Commented Sep 8, 2017 at 7:42
  • check out my new question please magento.stackexchange.com/questions/192801/… Commented Sep 11, 2017 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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