I have an install script that works, but doesn't upload the files where I want them:

$installer->addAttribute('catalog_category', 'category_banner_image',  array(
    'type'     => 'varchar',
    'label'    => 'Category Banner Image',
    'input'    => 'image',
    'backend'  => 'catalog/category_attribute_backend_image',
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => true,
    'default'           => '',
    'nullable'          => true,
    'group'             => 'Category Promo'

It uploads everything to /media/catalog/category but I would like for them to go to /media/categories/banners. How can I specify that in the install script?


Your attribute code can not describe where to store image, so you need to add this in your di.xml

    <virtualType name="vendor_name\module_name\BannerImageUpload" type="vendor_name\module_name\Model\ImageUploader">
        <argument name="baseTmpPath" xsi:type="string">categories/banners</argument>
           <argument name="basePath" xsi:type="string">categories/banner</argument>
           <argument name="allowedExtensions" xsi:type="array">
               <item name="jpg" xsi:type="string">jpg</item>
               <item name="jpeg" xsi:type="string">jpeg</item>
               <item name="gif" xsi:type="string">gif</item>
               <item name="png" xsi:type="string">png</item>
  • Thanks, but I'm confused. I only see di.xml files in my tests dir. Google tells me this is a Magento 2.x thing? I am using a 1.x version. I tried dropping this in my module's etc dir, but to no avail. Any suggestions for getting this to work in 1.x? – jmargolisvt Nov 8 '16 at 19:01

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.