从我的帐户中删除导航链接

Chr*_*ris 15 magento

我正在运行Mage 1.5.0.1,我正在尝试从"我的帐户"部分删除导航链接.

我的local.xml有以下工作正常:

 <customer_account>
    <reference name="root">
        <action method="setTemplate"><template>page/staticpage.phtml</template></action>
    </reference>
   <reference name="left">
        <remove name="cart_sidebar" /> 
        <remove name="catalog.compare.sidebar" />   
    </reference>
 </customer_account>
Run Code Online (Sandbox Code Playgroud)

当我尝试添加以下代码时系统抛出并出错:

   <reference name="customer_account_navigation">
    <action method="removeLinkByName"><name>recurring_profiles</name></action>
    <action method="removeLinkByName"><name>billing_agreements</name></action>
</reference>
Run Code Online (Sandbox Code Playgroud)

错误

Invalid method Mage_Customer_Block_Account_Navigation::removeLinkByName
Run Code Online (Sandbox Code Playgroud)

我在1.4中看到了这个功能,是不是不再支持了,还是我做错了什么?

Dan*_*oof 42

我有类似的问题,我不想注释掉addLink节点,因为我们只想在local.xml中实现我们的更改.写完一个小模块就可以了:

应用\等\模块\ Stackoverflow_Customerlinks.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Stackoverflow_Customerlinks>
            <active>true</active>
            <codePool>local</codePool>
        </Stackoverflow_Customerlinks>
    </modules>
</config>
Run Code Online (Sandbox Code Playgroud)

应用程序\代码\本地\#1\Customerlinks \块\帐户\ Navigation.php:

<?php

class Stackoverflow_Customerlinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation {

    public function removeLinkByName($name) {
        unset($this->_links[$name]);
    }

}
Run Code Online (Sandbox Code Playgroud)

应用程序\代码\本地\#1\Customerlinks \等\ config.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <global>
        <blocks>
            <customer>
                <rewrite>
                    <account_navigation>Stackoverflow_Customerlinks_Block_Account_Navigation</account_navigation>
                </rewrite>
            </customer>
        </blocks>
    </global>
</config>
Run Code Online (Sandbox Code Playgroud)

之后,您只需通过local.xml进行更改:

<customer_account>
    <reference name="customer_account_navigation">
        <action method="removeLinkByName"><name>recurring_profiles</name></action>
        <action method="removeLinkByName"><name>billing_agreements</name></action>
    </reference>
</customer_account>
Run Code Online (Sandbox Code Playgroud)

玩得开心 :)

  • '<action method ="removeLinkByName"> <name> enterprise_reward </ name> </ action>'如果有人有兴趣... (2认同)

Duc*_*ran 16

默认情况下,我们没有"removeLink"这样的方法.因此,诀窍是使用"unsetChild"方法删除整个块并添加所需的链接块,并在local.xml中添加我们自己的链接

<customer_account translate="label">
        <reference name="left">
            <!--Unset the whole block then add back later-->
            <action method="unsetChild"><name>customer_account_navigation</name></action>
            <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
                <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
                <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
                <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
                <action method="addLink" translate="label" module="sales"><name>orders</name><path>sales/order/history/</path><label>My Orders</label></action>
                <action method="addLink" translate="label" module="review"><name>reviews</name><path>review/customer</path><label>My Product Reviews</label></action>
                <action method="addLink" translate="label" module="wishlist" ifconfig="wishlist/general/active"><name>wishlist</name><path>wishlist/</path><label>My Favorite</label></action>
                <action method="addLink" translate="label" module="newsletter"><name>newsletter</name><path>newsletter/manage/</path><label>Newsletter Subscriptions</label></action>
            </block>
            <remove name="catalog.compare.sidebar"/>
        </reference>
    </customer_account>
Run Code Online (Sandbox Code Playgroud)

  • 很好的解决方案,这就像'Magento`这样做的方式.另外值得一提的是,模块可能会添加自己的链接,因此它们也需要单独处理. (2认同)
  • 这应该是公认的答案,因为它是推荐的magento方式! (2认同)

Mar*_*oof 8

只是告诉你们有关导航菜单中的所有链接的信息.要删除local.xml中的所有链接:

<?xml version="1.0"?>
<layout version="0.1.0">
    <customer_account>
        <reference name="customer_account_navigation" >
                <!-- remove the link using your custom method -->
                <action method="removeLinkByName"><name>recurring_profiles</name></action>
                <action method="removeLinkByName"><name>billing_agreements</name></action>
                <action method="removeLinkByName"><name>reviews</name></action>
                <action method="removeLinkByName"><name>downloadable_products</name></action>
                <action method="removeLinkByName"><name>OAuth Customer Tokens</name></action>

                <action method="removeLinkByName"><name>account</name></action>
                <action method="removeLinkByName"><name>account_edit</name></action>
                <action method="removeLinkByName"><name>address_book</name></action>
                <action method="removeLinkByName"><name>orders</name></action>
                <action method="removeLinkByName"><name>tags</name></action>
                <action method="removeLinkByName"><name>wishlist</name></action>
                <action method="removeLinkByName"><name>newsletter</name></action>

        </reference>
    </customer_account>
</layout>
Run Code Online (Sandbox Code Playgroud)

谢谢你的回答Daniel Sloof

  • 我认为removeLinkByName不是magento的默认函数 (7认同)

小智 7

你可以用它:

    <customer_account>
        <action method="unsetChild"><name>customer_account_navigation</name></action>
            <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
                <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
                <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
...
            </block>
     </customer_account>
Run Code Online (Sandbox Code Playgroud)

重写不是解决方案......