I have to set some additional data to currently logged in customer session. I have tried setting up new data in following way, but it doesn't work.

if (Mage::getSingleton('customer/session')->isLoggedIn()):
$customer = Mage::getSingleton('customer/session')->getCustomer();

If I print the session right after I set new data to session,I can see the data, but when I refresh the page, the data (test1 and test2) disappears. Note: I can see other regular customer session data.

Please suggest how the session data can be set to customer data session. Looking forward, thank you in advance!

2 Answers 2


@Deepak Bjatta, I don't really see anything wrong with the code that you're showing, other than you could very well overwrite the data you're trying to set on each page load. Since the customer session has Varien_Object as an ancestor, you can do something like:

$customerSession = Mage::getSingleton('customer/session');
if ($customerSession->isLoggedIn()) {
    $customer = $customerSession->getCustomer();
    if (!$customer->hasTest1()){
    } else {
        $customer->getTest1(); // do something with the value
        Mage::log($customer->getTest1()); // to see the output in var/log/system.log

Re: Your ability to only print the data right after you set it, and not see the previously set data on page load...maybe you could show more code context? Maybe give the code above a shot and see if that does it for you?

  • Yes we are pretty much on same page. This does't help me. Can you try using your script in customer controller and test. Thank you for your reply. Jun 13, 2016 at 10:37
  • @DeepakBhatta The code I pasted above was from a test that I ran locally, so that I was providing you with code I verified worked.
    – ryanF
    Jun 13, 2016 at 10:40

I don't have a Magento 1 installation available to test, but I believe that you may need to sate the Customer object to persist the data:

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customer = Mage::getSingleton('customer/session')->getCustomer();

Your Answer

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

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