cancel
Showing results for 
Search instead for 
Did you mean: 

Adding My Account navigation to module's frontend view

SOLVED

Adding My Account navigation to module's frontend view

Hello,

 

I've built a module, with a custom product type, what adds a menu item (My Coupon Codes), to the My Account menu, in the frontend. I'm having troubles to render the My Account menu in my module's frontend view, after i click on my added menu item.

 

/app/code/local/Dan/CouponProduct/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- /**
* Module Configuration
*
* @author: helln
*/ -->

<config>
...
        <frontend>
		<events>
			<controller_action_layout_load_before>
				<observers>
					<mage_customer>
						<class>mage_customer/observer</class>
						<method>beforeLoadLayout</method>
					</mage_customer>
				</observers>
			</controller_action_layout_load_before>
         </events>
		<routers>
			<dan_couponproduct>
				<use>standard</use>
				<args>
					<module>Dan_CouponProduct</module>
					<frontName>coupon-codes</frontName>
				</args>
			</dan_couponproduct>
		</routers>
		<layout>
			<updates>
				<dan_couponproduct_layout module="dan_couponproduct">
					<file>dan_couponproduct.xml</file>
				</dan_couponproduct_layout>
			</updates>
		</layout>
	</frontend>
</config>

 

 /app/design/frontend/base/default/layout/dan_couponproduct.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- /**
* Layout
*
* @author: helln
*/ -->

<layout>
...
	<customer_account>
		<reference name="customer_account_navigation">
                        ......

			<action method="addLink" translate="label title" module="dan_couponproduct">
				<label>My Coupon Codes</label>
				<url>coupon-codes/index/index</url>
				<title>My Coupon Codes</title>
				<prepare>true</prepare>
			</action>
        </reference>
	</customer_account>

<dan_couponproduct_index_index translate="label">
		<label>My Coupon Codes</label>
		<reference name="root">
			<action method="setTemplate">
				<template>page/3columns.phtml</template>
			</action>
			<action method="setHeaderTitle" translate="title" module="dan_couponproduct">
				<title>My Coupon Codes</title>
			</action>
		</reference>
		<reference name="content">
			<block type="dan_couponproduct/list" name="couponproduct.list" template="dan_couponproduct/couponproduct/list.phtml">
				<block type="page/html_pager" name="couponproduct.list.pager" as="couponproduct_list_pager" />
			</block>
		</reference>
<update handle="customer_account" />
 </dan_couponproduct_index_index> </layout>

 

/app/code/local/Dan/CouponProduct/controllers/IndexController.php

<?php /**
* Index Controller
*
* @author: helln
*/

class Dan_CouponProduct_IndexController extends Mage_Core_Controller_Front_Action {
	public function preDispatch () {
		parent::preDispatch();
		
		if ( !Mage::helper('dan_couponproduct')->isEnabled() || !Mage::getSingleton('customer/session')->authenticate( $this, Mage::helper('customer')->getLoginUrl() ) ) {
			$this->setFlag('', self::FLAG_NO_DISPATCH, true);
			$this->_redirect('noRoute');
		}
	}
	
	public function indexAction () {
		$this->loadLayout();
		
		if ( $listBlock = $this->getLayout()->getBlock('couponproduct.list') ) {
			$currentPage = abs( intval( $this->getRequest()->getParam('p') ) );
			if ($currentPage < 1)
				$currentPage = 1;
			$listBlock->setCurrentPage($currentPage);
		}
		
		$navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
		if ($navigationBlock)
			$navigationBlock->setActive('coupon-codes/index/index');
		
		$this->renderLayout();
	}
} ?>

 

As you can see, I'm trying to load the mage customer observer at controller_action_layout_load_before, but it looks like i need to do something else to get the My Account menu rendered in the left column of magento's 3 column template.

Help would be very appreciated! Smiley Happy

Thanks

Nik

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Adding My Account navigation to module's frontend view

oh, add

<update handle="customer_account"/>

in your dan_couponproduct_index_index layout handler

View solution in original post

Re: Adding My Account navigation to module's frontend view

generally the link would be marked active automatically once the item full url match with the full path of current controller, but you are using a incomplete path in your layout, so you have to insert this in your controller, before $this->renderLayout();

        $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
        if ($navigationBlock) {
            $navigationBlock->setActive('coupon-codes');
        }

 or

change

<url>coupon-codes</url>

 to

<url>coupon-codes/index/index</url>

 where you addLink

View solution in original post

7 REPLIES 7

Re: Adding My Account navigation to module's frontend view

Adding menu is mostly layout's job.

When you say you want to add menu link to left column of the 3columns layout, do you simply want to create a box with account link in the left column of ever page?

if so, you can easily create a cms statick block with the link in a div box, then add this block to left via cms->widget

Re: Adding My Account navigation to module's frontend view

Thanks for your reply @KuafuSoft!

 

I'm trying to display the magento customer menu on the left side of the 3 column layout. Since i've added "My Coupon Codes" to it, the menu should be present in my module's frontend view.

 

My added menu item (My Account/Customer Menu)

 

Where the menu should appear.

 

 

Re: Adding My Account navigation to module's frontend view

oh, add

<update handle="customer_account"/>

in your dan_couponproduct_index_index layout handler

Re: Adding My Account navigation to module's frontend view

Thanks again @KuafuSoft,

 

that did the trick. Smiley Happy
Now i have a final question: How can i mark my added menu item as active?

Re: Adding My Account navigation to module's frontend view

generally the link would be marked active automatically once the item full url match with the full path of current controller, but you are using a incomplete path in your layout, so you have to insert this in your controller, before $this->renderLayout();

        $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
        if ($navigationBlock) {
            $navigationBlock->setActive('coupon-codes');
        }

 or

change

<url>coupon-codes</url>

 to

<url>coupon-codes/index/index</url>

 where you addLink

Re: Adding My Account navigation to module's frontend view

Finally it is working.

 

But changing

 

<url>coupon-codes</url>

to

 

 

<url>coupon-codes/index/index</url>

 

alone, did not work.

Adding

 

$navigationBlock->setActive('coupon-codes/index/index');

to my IndexController, solved my problem.

i finally have read the article in the Knowledg Base about the "index/index nonesense", how Alan calls it. Smiley Happy

(Updating/correcting the original post to supply a functional sample)

 


Kindest Regards
Nik

Re: Adding My Account navigation to module's frontend view

try 

<url>dan_couponproduct</url>

and remove the navigation set active method