4
I’m having problems trying to create new options in the "Manage Options" tab. When creating an attribute, I already know how to save the data correctly in the database. I am overwriting 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:
So everything indicates to do this need to be added new columns in the table eav_attribute_option
. For example, campo_1
, campo_2
.
To save the additional fields I need to rewrite Mage_Eav_Model_Resource_Entity_Attribute::_saveOption()
.
Any hint on how to do this without changing the core in the same way I did above using rewrite
, and how to load database data for inputs when editing the attribute?
Thanks for the help, in the XML part I have configured, my xml, and he restored me
Ceicom_Swatches_Model_Eav_Resource_Entity_Attribute
when usingecho get_class(Mage::getResourceModel('eav/entity_attribute'));
but he doesn’t seem to be taking the codigo de dos after e before, he follows the class: http://pastebin.com/RDZhCEHv– Jonatan Ribeiro dos Santos
foreground Mage_eav_model_resource_entity_attribute instead of Mage_core_model_resource_db_abstract
– marcusagm
still not accessing the methods, before when I used to
Mage_Core_Model_Resource_Db_Abstract
, and was giving the following error http://pastebin.com/yF3cK3ba, now that I useMage_Eav_Model_Resource_Entity_Attribute
the error does not occur but also does not work– Jonatan Ribeiro dos Santos
This error occurs pq when extending the Mage_core_model_resource_db_abstract you need to implement all the methods that the abstract class has. That’s why I told you to extend to Mage_eav_model_resource_entity_attribute, but if it didn’t work it must do some check that invalidates the override
– marcusagm
I guess what I want to do has no way to be done then ;(
– Jonatan Ribeiro dos Santos
Tries to copy the whole originating class to yours, and then you add your methods. It should work
– marcusagm
I’ve tried that, but it performs only the function of Core and not mine
– Jonatan Ribeiro dos Santos
Have you tried watching the "model_save_before" event? Remembering that the event name can be prefixed to a specific model, for example "product_save_before" (product instead of model): http://magedev.com/2009/06/22/event-prefix-in-magento-models/
– J. Bruni
I found that when he saves he dispatches the event
catalog_entity_attribute
, I tried to create an Observer but it doesn’t seem to be working http://pastebin.com/sZ42pQar– Jonatan Ribeiro dos Santos
the event was actually catalog_entity_attribute_save_before, I had only taken the prefix without the _save_before
– Jonatan Ribeiro dos Santos