Magento – Saving data to session using Magento observer function

event-observerregistrysession

Is it possible to store data in the Magento session or registry using the the observer function, with:

Mage::getSingleton('core/session')->setFoo('bar'); //Or 'customer/session', 'admin/session'

Or

Mage::register('foo', 'bar');

I tried to add

sesson_write_close();

But only managed to read session data.

Best Answer

For that when your observer will call then you can create the session and set the value of that.

you can set the session using set, getting value using get and unset session using uns.

Mage::getSingleton('core/session')->setMySessionVariable('MyValue'); 

$myValue = Mage::getSingleton('core/session')->getMySessionVariable();

echo $myValue;

To Unset the session

Mage::getSingleton('core/session')->unsMySessionVariable();
Related Topic