我在尝试在“管理选项”选项卡中创建新选项时遇到问题.创建属性时,我知道如何在数据库中正确保存数据.我正在用我的模块替换Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options来创建自定义字段.
我的模块:
config.xml中
Ceicom_Swatches_Block_Adminhtml_Tabs
Ceicom_Swatches_Block_Adminhtml_Options
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
> 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
您的配置将如下所示
My_Module_Model_Catalog_Resource_Attribute
现在,您将看到在保存属性时正在执行的自定义__saveOption方法.
标签:php,magento,option,attributes
来源: https://codeday.me/bug/20190728/1563772.html