在 Magento 中排序 "My Account" 个链接

Sorting "My Account" Links in Magento

我想在 Magento(当前使用 1.9.0.1)中的“我的帐户”页面添加 注销 link,并在 local.xml 有效:

<customer_account>
  <reference name="customer_account_navigation">
    <action method="addLink" module="customer" translate="label">
      <name>logout</name>
      <path>customer/account/logout</path>
      <label>Logout</label>
    </action>
  </reference>
</customer_account>

但是,我希望确保上述 Logout link 出现在 底部 ,同时将其保持在 相同 列表。我想知道是否有合适的方法通过 XML 实现此目的,或者我是否必须通过前端模板将其清除。

谢谢!

不幸的是,没有这样的规定可以通过 XML 执行此操作。但是如果你在local.xml中使用上面的代码,那么最后会显示你添加的link。所以最简单的解决方案是使用 local.xml 本身来添加这样的 links.

如果您想知道为什么无法通过xml,那么就是这个原因。当您尝试 addLink 时,Magento 所做的是将项目附加到数组。只规定加一个link。没有删除 link.

的规定

由于最后处理了 local.xml 文件,您通过上述脚本添加的 link 会将 link 附加到该数组的最后一个,因此您将看到 logout link 最后.

但是如果您有兴趣通过观察者执行此操作,则可以使用事件 controller_action_layout_generate_blocks_after。如果你使用这个,那么你可以像这样抓取所有的link。

<?php
public function yourObserverMethod(Varien_Event_Observer $observer)
{
    $fullaction = $observer->getEvent()->getAction()->getFullActionName();
    if (Mage::getSingleton('customer/session')->isLoggedIn()
        && strpos($fullaction, 'customer_account') !== false
    ) {
        $layout = $observer->getEvent()->getLayout();
        $navigationBlock = $layout->getBlock('customer_account_navigation');
        if ($navigationBlock !== false) {

             //here you get all links.do anything with this array.
            $links = $navigationBlock->getLinks();
        }
    }
    return $this;
}