Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom "Catalog Input Type for Store Owner" for magento product attributes

In magento you can create new attributes (which are then added to attribute sets which products inherit) with certain types.

The default options (textfield/area, data, boolean) are fairly limited and I would like to add my own, complete with backend field renderer and its own validation. This to create a youtube field which accepts a range of urls which are transformed into only the youtube id.

But I'd really like a good explanation on how to add your own "Catalog Input Type for Store Owner". I've seen other plugins do it, but digging through code is tedious and this is definitely something which interests other people as well (question gets asked a lot over the web).

I have been searching for a while, but to no avail, I will continue to hunt down the answer until I find it however.

tl;dr

So my question is: How to add a "Catalog Input Type for Store Owner", maybe with a reference how to add a custom validation to this field type. This in the proper MVC style, so no editing of core files if possible.

Bonus points for being elaborate, generic explanations & code examples, I will award a bounty based on the quality of answer, if it is worth it (since this will be applicable to a larger audience).

like image 699
sg3s Avatar asked May 22 '12 09:05

sg3s


1 Answers

Sorry, I don't have time for writing long answer. Next 4 observers from Wee module will give you needed directions:

<config>
    <global>
        <events>
            <catalog_entity_attribute_save_before>
                <observers>
                    <weee>
                        <type>model</type>
                        <class>weee/observer</class>
                        <method>assignBackendModelToAttribute</method>
                    </weee>
                </observers>
            </catalog_entity_attribute_save_before>
        </events>
    </global>
...

    <adminhtml>
        <events>
            <adminhtml_catalog_product_edit_prepare_form>
                <observers>
                    <weee>
                        <class>weee/observer</class>
                        <method>setWeeeRendererInForm</method>
                    </weee>
                </observers>
            </adminhtml_catalog_product_edit_prepare_form>
            <adminhtml_product_attribute_types>
                <observers>
                    <weee>
                        <type>model</type>
                        <class>weee/observer</class>
                        <method>addWeeeTaxAttributeType</method>
                    </weee>
                </observers>
            </adminhtml_product_attribute_types>
            <adminhtml_catalog_product_edit_element_types>
                <observers>
                    <weee>
                        <class>weee/observer</class>
                        <method>updateElementTypes</method>
                    </weee>
                </observers>
            </adminhtml_catalog_product_edit_element_types>
        </events>
    </adminhtml>
</config>
like image 132
Dmytro Zavalkin Avatar answered Nov 08 '22 10:11

Dmytro Zavalkin