Add custom active links to customer account navigation in Magento
|
<customer_account> |
|
|
|
<reference name="left"> |
|
|
|
<!-- Remove existing navigation --> |
|
<action method="unsetChild"><name>customer_account_navigation</name></action> |
|
|
|
<!-- Build our own navigation --> |
|
<block type="my_module/customer_account_navigation" name="my_customer_account_navigation" before="-" |
|
template="customer/account/navigation.phtml"> |
|
<action method="addLink" translate="label" module="customer"> |
|
<name>account</name> |
|
<path>customer/account/</path> |
|
<label>My Account</label> |
|
</action> |
|
<action method="addLink" translate="label" module="customer"> |
|
<name>account_edit</name> |
|
<path>customer/account/edit/</path> |
|
<label>My Account Information</label> |
|
</action> |
|
<action method="addLink" translate="label" module="customer"> |
|
<name>address_book</name> |
|
<path>customer/address/</path> |
|
<label>My Address Book</label> |
|
</action> |
|
<action method="addLink" translate="label" module="sales"> |
|
<name>orders</name> |
|
<path>sales/order/history/</path> |
|
<label>My Orders</label> |
|
</action> |
|
</block> |
|
|
|
</reference> |
|
|
|
</customer_account> |
|
<sales_order_view> |
|
<reference name="my_customer_account_navigation"> |
|
<action method="setActiveLink"><name>orders</name></action> |
|
</reference> |
|
</sales_order_view> |
|
<?php |
|
class My_ModuleBlock_Customer_Account_Navigation extends Mage_Customer_Block_Account_Navigation |
|
{ |
|
|
|
/** |
|
* Is there a specific active link? |
|
* |
|
* @var |
|
*/ |
|
protected $_activeLink; |
|
|
|
/** |
|
* Set active link to this navigation |
|
* |
|
* @param string $linkName |
|
*/ |
|
public function setActiveLink($linkName) |
|
{ |
|
$this->_activeLink = $linkName; |
|
} |
|
|
|
|
|
/** |
|
* Overloaded in order to force link active display |
|
* when there is an active link explicity set |
|
* |
|
* @param string $link |
|
* @return bool |
|
*/ |
|
public function isActive($link) |
|
{ |
|
$isActive = parent::isActive($link); |
|
|
|
if(!$isActive && $link->getName() == $this->_activeLink) { |
|
$isActive = true; |
|
} |
|
|
|
return $isActive; |
|
} |
|
|
|
} |
|
?> |
This comment has been minimized.
webspeaks commentedDec 26, 2015
Thanks. Its an awesome trick :)