脚本宝典收集整理的这篇文章主要介绍了php – 为Magento属性创建新选项,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我的模块:
<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 /色板/座/ 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'); } }
显然,这需要在表eav_attribute_option中添加新列.例如]:field_1,field_2.
要保存我需要重写的其他字段:Mage_Eav_Model_Resource_Entity_Attribute :: _ saveOption().
在开始时我试图覆盖eav类Mage_Eav_Model_Resource_Entity_Attribute,但我没有工作.在仔细查看代码之后,我发现_saveOption方法是由另一个扩展Mage_Eav_Model_Resource_Entity_Attribute的类调用的.因此,如果您使用自定义类重写Mage_Eav_Model_Resource_Entity_Attribute,则在保存选项过程中不会产生任何影响.我也意识到还有另外一个扩展Mage_Eav_Model_Resource_Entity_Attribute的条款
那些条款是:
> Mage_Catalog_Model_Resource_Attribute
> Mage_Eav_Model_MysqL4_Entity_Attribute
> Mage_Eav_Model_Resource_Attribute(摘要)
1)创建了一个扩展Mage_Eav_Model_Resource_Entity_Attribute并覆盖该方法的类
class My_Module_Model_Eav_Resource_Entity_Attribute extends Mage_Eav_Model_Resource_Entity_Attribute {
protected function _saveOption(Mage_Core_Model_Abstract $object){
//你的自定义逻辑
}
}
不要在模块配置中覆盖Mage_Eav_Model_Resource_Entity_Attribute,上面的类将作为我们的主目标类Mage_Catalog_Model_Resource_Attribute的父级,它是参与保存过程的类.
2)在模块配置中覆盖Mage_Catalog_Model_Resource_Attribute类,其中包含一个新类,该类将扩展您之前创建的类My_Module_Model_Eav_Resource_Entity_Attribute
您的配置将如下所示
<global> <models> <!-- overrides Mage_Catalog_Model_Resource_Attribute --> <catalog_resource> <rewrite> <attribute>My_Module_Model_Catalog_Resource_Attribute</attribute> </rewrite> </catalog_resource> </models> <!-- The rest of global config section --> </global>
以上是脚本宝典为你收集整理的php – 为Magento属性创建新选项全部内容,希望文章能够帮你解决php – 为Magento属性创建新选项所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。