0

After creating a custom page (and navigation link) in the customer account section, there seems to be an issue with keeping the link active (in the customer_account_navigation block) when going to a sub page.

In other words: I have a custom customer page called 'dealers/orders', when clicked on the link called 'Dealer orders' is highlighted on the right hand side.

However when a dealer clicks on 'order details' which takes them to dealers/orders/orderdetails/id/x the link on the right hand side is not active.

Here is what I tried so far:

Setting the following in my xml for the page:

 <dealers_orders_orderdetails>
    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
        <block type="customer/account_navigation" name="navigation_dealer">
            <action method="setActive"><path>dealers/orders</path></action>
        </block>
    </reference>
</dealers_orders_orderdetails>

The setActive function is being called (can see it when logging) but it doesn't seem to highlight the desired link.

Any help would be appreciated

  • I'm having exactly the same issue. Did you find a resolution to this? – Stuart H Jun 19 '14 at 8:58
  • @StuartH not yet but slowly cracking at it...it seems that its instantiating a second customer navigation block and for that reason it doesn't highlight it, if you find anything more let us know – pzirkind Jun 19 '14 at 15:52
  • @StuartH just posted solution – pzirkind Jun 22 '14 at 19:30
3

To manually specify which tab that you would like highlighted in the customer account section, you will need to specify the setActive method with reference to the customer_account_navigation block.

<dealers_orders_orderdetails>
  <reference name="root">
    <action method="setTemplate"><template>page/1column.phtml</template></action>
  </reference>
  <reference name="customer_account_navigation">
    <action method="setActive"><path>dealers/orders/</path></action>
  </reference>
  <reference name="my.account.wrapper">
    ...
  </reference>
</dealers_orders_orderdetails>

With reference to specifically what you are trying to do, I see you are creating your own dealer section, with this in mind try move your block into the content section and not the root section though I can not test if this will achieve exactly what you are trying to do.

<dealers_orders_orderdetails>
  <reference name="root">
    <action method="setTemplate"><template>page/1column.phtml</template></action>
  </reference>
  <reference name="content">
     <block type="customer/account_navigation" name="navigation_dealer">
        <action method="setActive"><path>dealers/orders</path></action>
    </block>
  </reference>
</dealers_orders_orderdetails>
1

Enough:

$this->loadLayout();

if ($navigationBlock = $this->getLayout()->getBlock('customer_account_navigation')) {
    $navigationBlock->setActive('customer/address');
}

$this->renderLayout();
1

You can make active tab in customer account section by adding below xml code in your xml body section:

     <referenceBlock name="customer-account-navigation-dealer-order-link">
        <arguments>
            <argument name="is_highlighted" xsi:type="boolean">true</argument>
        </arguments>
    </referenceBlock>

where customer-account-navigation-dealer-order-link is your block name in your customer_account.xml file. even if you want to add in inner page above code add in layout xml file body section.

  • Works perfectly while using action tags is or will be deprecated – JonaPkr Apr 27 '18 at 8:59
0

It seems that the problem was one of two things:

  • The customer_account_navigation block was being loaded after the setActive function was being called
  • The setActive method is being called on a second instantiation of the block (in other words: there is a second object being created which is not the one being displayed on the page)

Either way here is the code that is now working for me.

In the controller add this code:

$this->loadLayout();

// add layout handle so that we will have the customer navigation on the right hand side
$layout = $this->getLayout();
$update = $layout->getUpdate();
$this->addActionLayoutHandles();
$update->addHandle('customer_account'); // add the customer navigation bar on the side
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
$navigationBlock = $layout->getBlock('customer_account_navigation');
// make sure we have an instantiation    
if ($navigationBlock) {
    $navigationBlock->setActive('path/to/highlight'); // example: 'customer/address'
}
$this->_isLayoutLoaded = true;

// render the layout
$this->renderLayout();

As you can see we are doing a lot of manual work to do something relatively simple, when I find a better way will post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.