Add Magento Link My Account

I would like to create a link on the "My Account" page, which will only appear under certain conditions.

Now I have the link mapping all the time by adding the following entry to my layout xml file:

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="nie"><name>nie</name><path>nie</path><label>NIE Admin</label></action>
    </reference>
</customer_account>

I guess there is a way to encode this so that it only appears under certain circumstances.

+5
source share
1 answer

Links to the cart and statement already do something similar, so you can copy their method.

  • Create a block. It will not be displayed directly, so it can come from drilling Mage_Core_Block_Abstract.
  • Give him a method in which conditional logic will execute.

    public function addNieLink()
    {
        if (($parentBlock = $this->getParentBlock()) && (CONDITION-GOES-HERE)) {
            $parentBlock->addLink($this->_('NIE Admin'), 'nie', $this->_('NIE Admin'), true, array(), 50, null, 'class="top-link-cart"');
            // see Mage_Page_Block_Template_Links::addLink()
        }
    }
    
    protected function _prepareLayout()
    {
        // Add the special link automatically
        $this->addNieLink();
        return parent::_prepareLayout();
    }
    

    Put your check in place CONDITION-GOES-HERE.

  • .

    <customer_account>
        <reference name="customer_account_navigation">
            <block type="yourmodule/link" name="yourmodule.link" />
        </reference>
    </customer_account>
    

    ( , )

getParentBlock(), , .

+7

All Articles