0

我正在创建一个 Magento 扩展程序,并希望以编程方式将链接添加到“我的帐户”导航。我已阅读以下主题(Magento - 如何在我的帐户导航中添加/删除链接?)及其引用的网站,但他们只谈论静态添加链接。

通过将以下内容添加到我的模块中的布局文件中,我可以获得一个新链接以显示在客户帐户导航中。

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="mymodule">
            <name>modulename</name>
            <path>mymodule/</path>
            <label>New link</label>
        </action>
    </reference>
</customer_account>

我怎样才能使这个链接的外观取决于对我的一个扩展模型的方法调用的结果。

4

3 回答 3

2

我遇到了同样的需求,这是我发现的实现它的最佳方法。

1)使用以下代码创建一个扩展 Magento 帐户导航块的新块文件。

class Mynamespace_Mymodule_Block_Addlink extends Mage_Customer_Block_Account_Navigation {
    public function addLinkToUserNav() {
        if (your logic here) {
            $this->addLink(
                    "your label",
                    "your url",
                    "your title"
            );
        }
    }
}

2)在您的扩展配置文件config.xml中,添加以下代码(尊重您现有的 XML 数据结构):

<config>
    ...
    <global>
        ....
        <blocks>
            ...
            <customer>
                <rewrite>
                    <account_navigation>Mynamespace_Mymodule_Block_Addlink</account_navigation>
                </rewrite>
            </customer>
        </blocks>
    </global>
</config>

3) 在您的扩展 XML 布局文件中,添加以下代码(尊重您现有的 XML 数据结构):

<layout>
    ...
    <customer_account>
        <reference name="customer_account_navigation">
            <action method="addLinkToUserNav"></action>
        </reference>
    </customer_account>
</layout>

就是这样。这将使您能够动态添加/删除帐户导航链接。

于 2015-02-26T10:24:15.723 回答
0

我认为您应该能够使用 Magento 的 ifconfig 属性,如此处所述

于 2012-11-16T09:08:03.817 回答
0

你必须使用magento的事件观察者功能你必须使用它的事件“controller_action_layout_load_before”在你的模块的config.xml中

<controller_action_layout_load_before>
    <observers>
        <uniquename>
            <type>singleton</type>
            <class>Package_Modulename_Model_Observer</class>
            <method>customlink</method>
        </uniquename>
    </observers>
</controller_action_layout_load_before>

并在相应的observer.php中使用以下代码

public function customlink(Varien_Event_Observer $observer)
{
    $update = $observer->getEvent()->getLayout()->getUpdate();
    $update->addHandle('customer_new_handle');
}

并在 local.xml 中写入

<customer_new_handle>
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="mymodule">
            <name>modulename</name>
            <path>mymodule/</path>
            <label>New link</label>
        </action>
    </reference>
</customer_new_handle>
于 2012-11-16T11:00:30.927 回答