4

I need to have the ability to add a file upload at the admin site and process the files after these have been uploaded. As a first step I like to extend Magento eav attributes with a new custom type "file upload". Therefore I have a number of questions, you may have an answer or can provide me a link for some of these.

Questions

  • How to add a new type for an EAV attribute?
  • How to add the handling of the field so it gets recognized and rendered as file upload?
  • How to setup the persistency handling for this new "type"?

Thank you in advance

1
  • Since you have multiple questions, it is better to ask them in several separate questions, as you will have a higher chance of people answering you. Commented Apr 4, 2013 at 12:21

1 Answer 1

9

My examples are geared towards category image attribute, but the principle is the same for product based.

This information should get you going in the right direction (I hope)

Attributes have two elements that define their input and backend (processing) behaviour.

Below is the base requirements for a new attribute created in a category, which is an image. (the snippet is taken from a co-workers megamenu module (with some help from me in some areas, of course ;), and I include the ref to the code to allow you to view the snippet in context, which may clarify the code - [https://github.com/benjy14/MegaMenu/blob/master/app/code/local/DevBlog/MegaMenu/Model/Mysql4/Setup.php)

'megamenu_feature_image' => array(
            'type' => 'varchar',
            'label' => 'Menu Feature Image',
            'note' => 'Make sure the width is 260px',
            'input' => 'image',
            'backend' => 'catalog/category_attribute_backend_image',
            'required' => false,
            'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
            'visible' => true,
            'required' => false,
            'user_defined' => false,
            'visible_on_front' => true,
            'used_in_product_listing' => false,
            'is_html_allowed_on_front' => false,

        ),

The important bits (for you) will be the input and backend elements.

'input' => 'image' relates to : Varien_Data_Form_Element_Image (all the input element renderers live in lib/varien/data/form/element

'backend' => 'catalog/category_attribute_backend_image', => relates to (well as it says) Mage_Catalog_Model_Category_Attribute_Backend_Image :)

in Mage_Catalog_Model_Category_Attribute_Backend_Image you will see a method 'afterSave' where processing takes place after the image is uploaded.

for a custom input renderer, you will rather use 'input_renderer' (ref: http://inchoo.net/ecommerce/magento/adding-magento-attribute-with-custom-input-renderer/ I am not sure if 'input' will work for a custom renderer, but worth a try. (magento do change at times)

Thus, you just need to point the attribute to your custom input and backend models.

Hope this helps.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.