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

时间:2011-05-04 17:49:34

标签: 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>

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

   <reference name="customer_account_navigation">
    <action method="removeLinkByName"><name>recurring_profiles</name></action>
    <action method="removeLinkByName"><name>billing_agreements</name></action>
</reference>

错误

Invalid method Mage_Customer_Block_Account_Navigation::removeLinkByName

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

11 个答案:

答案 0 :(得分: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>

应用\代码\本地\#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]);
    }

}

应用\代码\本地\#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>

之后,您只需通过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>

玩得开心:)

答案 1 :(得分: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>

答案 2 :(得分: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>

感谢Daniel Sloof的回答

答案 3 :(得分: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>

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

答案 4 :(得分:2)

我刚刚重构了帐户信息中心链接并删除了我之前的CSS nth-child选择器,而是将app / design / frontend / default / your_theme / template / customer / account / navigation.phtml更改为此

<div class="block block-account">
<div class="block-title">
    <strong><span><?php echo $this->__('My Account'); ?></span></strong>
</div>
<div class="block-content">
    <ul>
        <?php $_links = $this->getLinks(); ?>
        <?php $_index = 1; ?>


            <?php $_count = count($_links); 
                unset($_links['recurring_profiles']); 
                unset($_links['billing_agreements']); 
                unset($_links['reviews']);
                unset($_links['tags']);
                unset($_links['OAuth Customer Tokens']);
                unset($_links['downloadable_products']); 
            ?>


        <?php foreach ($_links as $_link): ?>
            <?php $_last = ($_index++ >= $_count); ?>
            <?php if ($this->isActive($_link)): ?>
                <li class="current<?php echo ($_last ? ' last' : '') ?>"><strong><?php echo $_link->getLabel() ?></strong></li>
            <?php else: ?>
                <li<?php echo ($_last ? ' class="last"' : '') ?>><a href="<?php echo $_link->getUrl() ?>"><?php echo $_link->getLabel() ?></a></li>
            <?php endif; ?>
        <?php endforeach; ?>
    </ul>
</div>

基本上没有设置任何不需要的链接。

答案 5 :(得分:1)

还有其他各种xml文件引用<reference name="customer_account_navigation">,您可以在其中将xml文件复制到布局目录并注释掉除此之外的addLink节点,我会看到您可能尝试使用的removeLinkByUrl。

答案 6 :(得分:0)

你也可以直接在local.xml中覆盖空链接的声明 - 没有定义'path'和'label':

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink"><name>tags</name></action>
        <action method="addLink"><name>newsletter</name></action>
    </reference>
</customer_account>

答案 7 :(得分:0)

转到app/design/frontend/YourPackageName/YourThemeName/layout/,创建一个sales/目录(如果没有),并创建一个名为billing_agreement.xmlrecurring_profile.xml的空文件或目录。

最干净的方法,没有自定义函数,没有CSS黑客攻击,模板文件中没有逻辑。

这完全隐藏了用户的“结算协议”和“重复发布的配置文件”功能。

答案 8 :(得分:0)

这个模块使功能排序或显示我自己的链接,不会使布局和phtml覆盖块并在那里制作所有逻辑。

http://www.magentocommerce.com/magento-connect/customer-navigation.html

  • 最干净的解决方案是覆盖该框并添加一个方法来从布局中删除链接。

答案 9 :(得分:-1)

我的帐户导航链接来自customer.xml文件。

            <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>
            </block>

答案 10 :(得分:-1)

我的主张是带来css的力量,避免修改代码。

E.G。

/* CUSTOMER ACCOUNT LEFT NAV DISABLER */
.block-content li:nth-child(4),
.block-content li:nth-child(5),
.block-content li:nth-child(6),
.block-content li:nth-child(8){display: none;}

显然,将选择器更改为主题客户导航li,并使用li:nth-​​child()sudo,并在要删除的括号之间添加数字。 在customer.xml中使用注释,以防万一你忘了你在6个月后做了什么。