3

I'm building a Magento sandbox environment and need to set a session cookie based on a value in the query-string. The value in the query-string will be used to set an account ID for another service used within this Magento environment. This is not a production, public facing environment, so security is not a concern.

My first challenge is figuring out where to actually place the code within the Magento MVC. All users accessing this system will come directly through the root domain (as opposed to a specific page within the site... say a product or product category page). The bookmarked URL will look something like this:

http://www.somedomain.com/index.php?accountID=12345678

Below is the initial code I wrote to evaluate the query-string and set the cookie value:

$account_id = $this->getRequest()->getParam('accountID');
$account_id_cookie = Mage::getSingleton('core/cookie');
$account_id_cookie->set('account_id',$account_id,time()+86400,'/');

Where is the best place to put this code within the Magento MVC? I tried the root index.php file but it doesn't work. I suspect the best place is within a controller but I'm not sure which controller file is appropriate.

Once this value is set within a session cookie, it will be referenced in a JavaScript snippet located within the footer of the site so it's necessary for the value to be present in the cookie prior to the footer include being parsed.

7ochem
7,61516 gold badges54 silver badges82 bronze badges
asked Mar 17, 2015 at 15:05

1 Answer 1

4

You can observe the controller_action_layout_render_before event (you can read this if you don't know how do event/observer works)

Or you can rewrite the footer block Mage_Page_Block_Html_Footer (some documentation here)

In all case, you have to deactivate the cache or remove the cache directives in the footer block.

answered Mar 17, 2015 at 15:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.