Creating new options for Magento attributes

4

I'm having trouble trying to create new options in the "Manage Options" tab. When I create an attribute, I already know how to save the data correctly in the database. I'm replacing Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options with my module to create custom fields.

My module:

config.xml

<config>
        <blocks>
            <adminhtml>
                <rewrite>
                     <catalog_product_attribute_edit_tabs>Ceicom_Swatches_Block_Adminhtml_Tabs</catalog_product_attribute_edit_tabs>
                     <catalog_product_attribute_edit_tab_options>Ceicom_Swatches_Block_Adminhtml_Options</catalog_product_attribute_edit_tab_options>
                 </rewrite>
             </adminhtml>
        </blocks>
</config>

Ceicom / Swatches / Block / Adminhtml / Options.php

class Ceicom_Swatches_Block_Adminhtml_Options extends Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('ceicom/attribute/options.phtml');
    }
}

In the phtml file I put in the custom fields:

By all means to do this need to be added new columns in the eav_attribute_option table. For example, campo_1 , campo_2 .

To save the additional fields I need to rewrite Mage_Eav_Model_Resource_Entity_Attribute::_saveOption() .

How do I do this without changing the core, just as I did above using rewrite , and how do I load the database data for the inputs when editing the attribute?

    
asked by anonymous 31.01.2014 / 22:34

1 answer

1

You can rewrite the eav / entity_attribute using another model.

To do this add in config.xml

<global>
    ...
    <models>
        ...
        <eav_resource>
            <rewrite>
                <entity_attribute>Seumodulo_Model_Eav_Resource_Entity_Attribute</entity_attribute>
            </rewrite>
        </eav_resource>
        ...
    </models>
    ...
</global>

Create your file in

/app/code/local/Seumodulo/Eav/Model/Resource/Entity/Attribute.php

and use the class signature so

class Seumodulo_Eav_Model_Resource_Entity_Attribute extends Mage_Core_Model_Resource_Db_Abstract {
    ...
}

Make sure that you have cleared the cache configuration, and verify that the module is showing up in System-> Configuration-> Advanced-> Disable Modules Output

Test this to see if it worked out

echo get_class(Mage::getResourceModel('eav/entity_attribute'));

To save you can overwrite the methods that enable actions before and after saving. Are they

Mage_Catalog_Model_Resource_Attribute::_beforeSave()
Mage_Catalog_Model_Resource_Attribute::_afterSave()

instead of

Mage_Eav_Model_Resource_Entity_Attribute::_saveOption()

So you will not have to worry about the original code.

See some examples in the links

05.02.2014 / 00:45