php – 为Magento属性创建新选项
我在尝试在“管理选项”选项卡中创建新选项时遇到问题.创建属性时,我知道如何在数据库中正确保存数据.我正在用我的模块替换Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options来创建自定义字段.
我的模块: 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 /色板/座/ 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'); } } 在放置在自定义字段中的Phtml文件中: 显然,这需要在表eav_attribute_option中添加新列.例如]:field_1,field_2. 要保存我需要重写的其他字段:Mage_Eav_Model_Resource_Entity_Attribute :: _ saveOption(). 有关如何在不更改CORE的情况下执行此操作的任何提示,就像我上面使用重写一样,以及如何加载数据库以进行编辑属性的输入? 解决方法
这是一种可能的解决方法:
在开始时我试图覆盖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 为了能够覆盖属性选项保存过程中的方法,您必须: 1)创建了一个扩展Mage_Eav_Model_Resource_Entity_Attribute并覆盖该方法的类 class My_Module_Model_Eav_Resource_Entity_Attribute extends Mage_Eav_Model_Resource_Entity_Attribute { 不要在模块配置中覆盖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> 现在,您将看到在保存属性时正在执行的自定义__saveOption方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |