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

发布于 2024-11-04 22:31:57 字数 974 浏览 0 评论 0原文

我正在运行 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 中看到了此函数,是不再支持它还是我做错了什么?

I am running Mage 1.5.0.1 and I am trying to remove the navigation links from the My Account section.

My local.xml has the following which works fine:

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

When I try to add the following code the system throws and error:

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

Error

Invalid method Mage_Customer_Block_Account_Navigation::removeLinkByName

I saw this function in 1.4, is it not supported anymore or am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

薄情伤 2024-11-11 22:31:57

我遇到了类似的问题,我不想注释掉 addLink 节点,因为我们只想在 local.xml 中实现我们的更改。最终编写了一个小模块来做到这一点:

app\etc\modules\Stackoverflow_Customerlinks.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Stackoverflow_Customerlinks>
            <active>true</active>
            <codePool>local</codePool>
        </Stackoverflow_Customerlinks>
    </modules>
</config>

app\code\local\Stackoverflow\Customerlinks\Block\Account\Navigation.php:

<?php

class Stackoverflow_Customerlinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation {

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

}

app\code\local\Stackoverflow\Customerlinks\etc\ 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>

玩得开心:)

I had a similar problem, and I didn't want to comment out addLink node because we want to implement our changes in local.xml only. Ended up writing a small module to do it:

app\etc\modules\Stackoverflow_Customerlinks.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Stackoverflow_Customerlinks>
            <active>true</active>
            <codePool>local</codePool>
        </Stackoverflow_Customerlinks>
    </modules>
</config>

app\code\local\Stackoverflow\Customerlinks\Block\Account\Navigation.php:

<?php

class Stackoverflow_Customerlinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation {

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

}

app\code\local\Stackoverflow\Customerlinks\etc\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>

After that, you can simply make the changes through 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>

Have fun :)

傲娇萝莉攻 2024-11-11 22:31:57

默认情况下,我们没有“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>

By default, we don't have such method as "removeLink". Therefore, the trick is to remove the whole block using "unsetChild" approach and add the needed links block back with our own links added to it in 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>
所有深爱都是秘密 2024-11-11 22:31:57

只是为了告诉大家导航菜单中的所有链接。
要删除 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

Just to inform you guys about all the links in the navigation menu.
To remove all links in 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>

Thanks for your answer Daniel Sloof

提笔落墨 2024-11-11 22:31:57

您可以使用:

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

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

You can use that:

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

Rewriting is not solution...

只为一人 2024-11-11 22:31:57

我只是重构了帐户仪表板链接并删除了 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>

基本上取消任何不需要的链接。

I just refactored account dashboard links and removed CSS nth-child selectors as I had before and instead changed app/design/frontend/default/your_theme/template/customer/account/navigation.phtml to this

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

basically unset any unwanted links.

飘过的浮云 2024-11-11 22:31:57

还有其他各种引用 的 xml 文件,您可以将 xml 文件复制到布局目录并注释掉除此之外的 addLink 节点,我看到一个您可以尝试删除LinkByUrl。

There are other various xml file that refer to <reference name="customer_account_navigation"> where you can copy the xml file to your layout directory and comment out the addLink node other than that, I see a removeLinkByUrl that you might try instead.

一个人的夜不怕黑 2024-11-11 22:31:57

您还可以通过空链接覆盖声明 - 无需定义“路径”和“标签”,直接在 local.xml 中:

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

You can also, override declaration by empty link - without define 'path' and 'label', direcly in local.xml:

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink"><name>tags</name></action>
        <action method="addLink"><name>newsletter</name></action>
    </reference>
</customer_account>
无法言说的痛 2024-11-11 22:31:57

转到 app/design/frontend/YourPackageName/YourThemeName/layout/,创建一个 sales/ 目录(如果没有),然后创建一个名为 sales/ 的空文件或目录代码>billing_agreement.xml 和recurring_profile.xml

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

这对用户完全隐藏了计费协议和定期配置文件功能。

Go to app/design/frontend/YourPackageName/YourThemeName/layout/, create a sales/ directory if there isn't one, and create an empty file or directory named billing_agreement.xml and recurring_profile.xml.

Cleanest method ever, no custom functions, no CSS hacking, no logic in template files.

This completely hides the Billing Agreements and Recurring Profiles features from the user.

宫墨修音 2024-11-11 22:31:57

该模块进行功能排序或显示我自己的链接,不进行布局,并且 phtml 覆盖该块并在那里进行所有逻辑。

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

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

This module makes functionality ordering or show the links of my own, does not make for layout and phtml overwrites the block and makes all the logic there.

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

  • The cleanest solution would be to make an overwrite of the box and add a method to remove links from layout.
绝影如岚 2024-11-11 22:31:57

我的帐户导航链接来自 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>

My Account Navigation links comes from customer.xml file.

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

我的方法是利用 css 的强大功能并避免大量的代码修改。

EG

/* 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 个月后所做的事情。

My apperoach is to bring power of css and avoid hevy code modifications.

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;}

Obviously change selectors to your themes customer navigation li, and use li:nth-child() sudo with number between parenthesis which you want to remove.
Use comments in customer.xml as well just in case u don't forget what you did 6 month down the line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文