我在尝试在“管理选项”选项卡中创建新选项时遇到问题。当您创建属性时,我知道如何将数据正确保存在数据库中。我正在更换Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options
使用我的模块来创建自定义字段。
我的模块:
配置文件
<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');
}
}
在放置在自定义字段中的 Phtml 文件中:
显然要做到这一点需要在表中添加新列eav_attribute_option
。例如]:field_1
, field_2
.
要保存其他字段,我需要重写:Mage_Eav_Model_Resource_Entity_Attribute::_saveOption()
.
关于如何在不更改核心的情况下执行此操作的任何提示,就像我上面使用的那样rewrite
,以及如何加载数据库以进行属性编辑?
这是一个可能的解决方法:
一开始我尝试重写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){
//your custom logic here
}
}
不要在模块配置中覆盖 Mage_Eav_Model_Resource_Entity_Attribute,上述类将作为我们的主目标类 Mage_Catalog_Model_Resource_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 方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)