【问题标题】:Magento - How to add/remove links on my account navigation?Magento - 如何在我的帐户导航上添加/删除链接?
【发布时间】:2009-12-30 00:38:04
【问题描述】:

我正在尝试删除我的帐户导航中的链接。我查看了 customer/account/navigation.phtml 模板。模板通过 $this->getLinks() 获取链接。如何编辑 getLinks() 方法以便删除一些链接?

【问题讨论】:

标签: magento


【解决方案1】:

如果您想选择性地删除链接而不必复制/编辑整个 xml 文件,可以在this post in the magento forums 中找到一个不错的解决方案

在此解决方案中,您使用本地版本覆盖 Mage_Customer_Block_Account_Navigation 块,这会添加一个 removeLinkByName 方法,然后您可以在您的 layout.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>
        </reference>
    </customer_account>
</layout>

【讨论】:

  • 那是论坛,哪个解决方案有效,可以的话请详细说明
  • Ryan Christofferson 给出了更好的答案,谢谢
【解决方案2】:

你的问题的答案最终是,这取决于。该导航中的链接是通过不同的布局 XML 文件添加的。这是首先在layout/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>

其他菜单项在其他布局文件中定义。例如,Reviews 模块使用layout/review.xml 定义其布局,并包含以下内容:

<customer_account>
    <!-- Mage_Review -->
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="review"><name>reviews</name><path>review/customer</path><label>My Product Reviews</label></action>
    </reference>
</customer_account>

要删除此链接,只需注释掉或删除&lt;action method=...&gt; 标签,菜单项就会消失。如果您想一次找到所有菜单项,请使用您最喜欢的文件搜索并找到 name="customer_account_navigation" 的任何实例,这是 Magento 用于该导航块的句柄。

【讨论】:

  • 这个解决方案是在广泛采用修改布局之前创建的,通过在 local.xml 中执行更新而不接触基本模板文件。修改基本模板文件当然是一个很大的禁忌,因为修改可能会在 Magento 版本更改中丢失。
  • 免费的“Frontend Links Manager”扩展程序允许您从控制面板执行此操作,“我的应用程序”除外。
  • @ehartwell 新版本的“前端链接管理器”支持 Magento CE 和 EE 中可用的所有链接。
  • 您好,我正在尝试添加 2 个链接,但只会显示最后添加的链接。是他们添加多个链接/菜单的任何其他方式
【解决方案3】:

从 Magento 的“我的帐户”面板中删除任何链接的最简单方法是首先复制:

app/design/frontend/base/default/template/customer/account/navigation.phtml

app/design/frontend/enterprise/YOURSITE/template/customer/account/navigation.phtml

打开文件并细化这一行,应该在第 34 行左右:

<?php $_index = 1; ?>

在它的正下方添加这个:

 <?php $_count = count($_links); /* Add or Remove Account Left Navigation Links Here -*/
        unset($_links['tags']); /* My Tags */
        unset($_links['invitations']); /* My Invitations */
        unset($_links['enterprise_customerbalance']); /* Store Credit */
        unset($_links['OAuth Customer Tokens']); /* My Applications */
        unset($_links['enterprise_reward']); /* Reward Points */
        unset($_links['giftregistry']); /* Gift Registry */
        unset($_links['downloadable_products']); /* My Downloadable Products */
        unset($_links['recurring_profiles']); /* Recurring Profiles */
        unset($_links['billing_agreements']); /* Billing Agreements */
        unset($_links['enterprise_giftcardaccount']); /* Gift Card Link */
        ?> 

只需在此处删除您想要显示的任何链接。

【讨论】:

    【解决方案4】:

    您还可以通过后端禁用菜单项,而无需接触任何代码。进入:

    System > Configuration > Advanced
    

    您将看到一长串选项。以下是一些设置为“已禁用”的关键模块:

    Mage_Downloadable -> My Downloadable Products
    Mage_Newsletter -> My Newsletter
    Mage_Review -> My Reviews
    Mage_Tag -> My Tags
    Mage_Wishlist -> My Wishlist
    

    我还禁用了 Mage_Poll,因为它往往会出现在其他页面模板中,如果您不使用它会很烦人。

    【讨论】:

    • 我认为这是一个非常干净的解决方案。如果您更改代码,有一天会出现问题,当您想恢复以前的状态并且更改了这么多文件时...
    • 如果我没记错的话,这只会禁用 html 的输出。块仍在处​​理中。如果您不想要块处理的开销,那么您将不得不使用 xml。
    【解决方案5】:

    我相信它的工作 100%。

    第 1 步:转到 (YourTemplate/customer/account/navigation.phtml)

    第 2 步:替换此行:&lt;?php $_count = count($_links); ?&gt; 与:

    <?php $_count = count($_links); /* Add or Remove Account Left Navigation Links Here -*/
    unset($_links['account']); /* Account Info */     
    unset($_links['account_edit']); /* Account Info */            
    unset($_links['tags']); /* My Tags */
    unset($_links['invitations']); /* My Invitations */
    unset($_links['reviews']);  /* Reviews */
    unset($_links['wishlist']); /* Wishlist */
    unset($_links['newsletter']); /* Newsletter */
    unset($_links['orders']); /* My Orders */
    unset($_links['address_book']); /* Address */
    unset($_links['enterprise_customerbalance']); /* Store Credit */
    unset($_links['OAuth Customer Tokens']); /* My Applications */
    unset($_links['enterprise_reward']); /* Reward Points */
    unset($_links['giftregistry']); /* Gift Registry */
    unset($_links['downloadable_products']); /* My Downloadable Products */
    unset($_links['recurring_profiles']); /* Recurring Profiles */
    unset($_links['billing_agreements']); /* Billing Agreements */
    unset($_links['enterprise_giftcardaccount']); /* Gift Card Link */
    

    ?>

    【讨论】:

      【解决方案6】:

      从技术上讲,zlovelady 的答案更可取,但由于我只需从导航中删除项目,因此取消设置模板中不需要的导航项目的方法对我来说是最快/最简单的方法:

      只是复制

      app/design/frontend/base/default/template/customer/account/navigation
      

      app/design/frontend/YOUR_THEME/default/template/customer/account/navigation
      

      并在渲染之前取消设置不需要的导航项,例如:

      <?php $_links = $this->getLinks(); ?>    
      <?php 
          unset($_links['recurring_profiles']);
      ?>
      

      【讨论】:

      • +1 最好的选择是不修改核心文件并将其全部放在一个地方
      【解决方案7】:

      另外,如果您正在开发自定义模块,则需要在 config.xml 中执行类似操作

          <frontend>
              <layout>
                  <updates>
                      <hpcustomer>
                          <file>hpcustomer.xml</file>
                      </hpcustomer>
                  </updates>
              </layout>
          </frontend>
      

      【讨论】:

        【解决方案8】:

        打开导航.phtml

        app/design/frontend/yourtheme/default/template/customer/account/navigation.phtml
        

        替换

        <?php $_links = $this->getLinks(); ?>
        

        您要删除的未设置链接

        <?php 
        $_count = count($_links);
        unset($_links['account']); // Account Information     
        unset($_links['account_edit']); // Account Information  
        unset($_links['address_book']); // Address Book
        unset($_links['orders']); // My Orders
        unset($_links['billing_agreements']); // Billing Agreements
        unset($_links['recurring_profiles']); // Recurring Profiles
        unset($_links['reviews']);  // My Product Reviews
        unset($_links['wishlist']); // My Wishlist
        unset($_links['OAuth Customer Tokens']); // My Applications
        unset($_links['newsletter']); // Newsletter Subscriptions
        unset($_links['downloadable_products']); // My Downloadable Products
        unset($_links['tags']); // My Tags
        unset($_links['invitations']); // My Invitations
        unset($_links['enterprise_customerbalance']); // Store Credit
        unset($_links['enterprise_reward']); // Reward Points
        unset($_links['giftregistry']); // Gift Registry
        unset($_links['enterprise_giftcardaccount']); // Gift Card Link
        ?>
        

        【讨论】:

          【解决方案9】:

          上面的大部分工作,但对我来说,这是最简单的。

          安装插件、注销、登录、系统、高级、前端链接管理器,选中和取消选中您要显示的选项。它也适用于您网站上的任何前端导航。

          http://www.magentocommerce.com/magento-connect/frontend-links-manager.html

          【讨论】:

          • 非常好用。
          【解决方案10】:

          您也可以使用这个免费的即插即用扩展:

          http://www.magentocommerce.com/magento-connect/manage-customer-account-menu.html

          此扩展不涉及任何 Magento 核心文件。

          使用此扩展程序,您可以:

          1. 在 Magento 后端单击即可决定每个菜单项是显示还是隐藏。
          2. 轻松重命名菜单项。

          【讨论】:

            【解决方案11】:

            我的解决方案是完全删除 local.xml 中的块并使用我需要的块创建它,例如

            <customer_account>
                    <reference name="left">
                        <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>
                </reference>
            </customer_account>
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2016-02-28
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2012-01-12
              • 1970-01-01
              相关资源
              最近更新 更多