【问题标题】:Overriding already existing magento module adminhtml block覆盖已经存在的magento模块adminhtml块
【发布时间】:2013-05-02 06:03:31
【问题描述】:

我试图在 Amasty shopby 模块中再添加一个自定义字段。为此,我需要覆盖 adminhtml 表单。我为此创建了模块,但这并没有覆盖现有模块。我必须覆盖“Amasty_Shopby_Block_Adminhtml_Filter_Edit_Tab_General”类。 这是我的代码。

Mycompany_Mymodule.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Mymodule>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Amasty_Shopby />
                <Amasty_Base />
            </depends>
        </Mycompany_Mymodule>
    </modules>
</config>

我的公司/我的模块/etc/config.xml

<config>
_____________
______________
    <global>
        <blocks>
            <adminhtml>
                 <rewrite>        <filter_edit_tab_general>Mycompany_Mymodule_Block_Adminhtml_Filter_Edit_Tab_General
                   </filter_edit_tab_general>
                 </rewrite>
            </adminhtml>
        </blocks>
    </global>
 ____________
-________________
</config>

Mycompany\Mymodule\Block\Adminhtml\Filter\Edit\Tab\General.php

public class Mycompany_Mymodule_Block_Adminhtml_Filter_Edit_Tab_General extends Amasty_Shopby_Block_Adminhtml_Filter_Edit_Tab_General
{
 _______________
___________
}

【问题讨论】:

    标签: magento


    【解决方案1】:

    您现在要覆盖的不是 Amasty 块,而是 adminhtml/filter_edit_tab_general。所以要重写 Amasty_Shopby_Block_Adminhtml_Filter_Edit_Tab_General 你需要以下配置:

    <global>
        <blocks>
            <amshopby>
                <rewrite>
                    <adminhtml_filter_edit_tab_general>Mycompany_Mymodule_Block_Adminhtml_Filter_Edit_Tab_General</adminhtml_filter_edit_tab_general>
                </rewrite>
            </amshopby>
        </blocks>
    </global>
    

    【讨论】:

    • 我正在尝试覆盖另一个表单“Amasty_Shopby_Block_Adminhtml_Page_Edit_Form”,如您所说。但无法覆盖。在 rewrite 下的 xml 文件中,我添加了这一行。 Mycompany_Mymodule_Block_Adminhtml_Page_Edit_Form
    • 这条线本身看起来不错。你把它放在 里面还是外面?它应该在您的 adminhtml_filter_edit_tab_general 行的正下方。这也取决于这个 Amasty_Shopby_Block_Adminhtml_Page_Edit_Form 是原始块,还是覆盖某些核心块。如果它不是原始的,那么您必须从 Amasty config.xml 中删除该重写,然后在您的扩展中重写该核心块。
    • Amasty_Shopby_Block_Adminhtml_Page_Edit_Form 是一个原始的,我放在 里面。但它不是压倒一切的。
    • 那么不幸的是我不知道出了什么问题。配置对我来说似乎很好,所以它一定是别的东西。
    • @AlexeiYerofeyev 在覆盖未扩展核心块的块时,我发现在配置中进行通常的重写,但从要覆盖的块的父级扩展块工作正常(而不是比块本身) - 所以根本不需要修改被覆盖的模块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多