开发者

override save and load of an attribute in magento

How can I override the way magento saves and load a specific attribute? I want to create an attribute that implements a many-to-many relation to products so I have a custom table with entity_id and attr_id. I'm using a multiselect attribute but magento saves the values as csv in a text field. I want to 开发者_开发问答override this functionality and save and load from the m2m table.

When defining a backend model for an attribute I only have control over beforeSave and afterSave but not on save itself.

Thanks


I think you're going to have to create a custom module with your own Model that extends Mage_Core_Model_Abstract. That way you can override the save() function (always making sure that you call parent::save() in there too!) to perform your multi-table logic.

Once you've created that model, can you create a product attribute that uses the Model as a frontend_model and/or backend_model. You can create the attribute in the config.xml of your module or in the mysql setup.

This is not trivial, and be careful with overriding the save() method, that's getting in deep. Good idea to setup some unit tests to make sure you're not inadvertently breaking things...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜