January 09, 2014

Session Variables in Magento


Following are main of the session variables. 

1. First one is about getting information regardng core session data for magento.
Core Session :- Mage::getSingleton(‘core/session’) 

2. Customer session is for getting details associated with the customer data that is currently in session.
You can play with customer session data in shopping cart in the case of one page check out or another kind of. 
Customer Session :- Mage::getSingleton(‘customer/session’);

3 .Admin session gives you information regarding admin session related with admin modules and permisssions.
You have to back up your source code before using this session. This is very important. 
Admin Session :- Mage::getSingleton(‘adminhtml/session’) 

4. Shopping cart session determines that you can get info about various products in shopping cart and customer data. 
Shopping Cart Session :- Mage::getSingleton(‘checkout/session’)->getQuote() 

User defined session variables: 
How to set a session variable in Magento : 
$data = 'Hello heaven welcomes you.'; 
 Mage::getSingleton('core/session')->setMyData($data); 
OR 
Mage::getSingleton('core/session')->setData('my_data', $data); 

How to get a session variable in Magento: 
$string_data = Mage::getSingleton('core/session')->getMyData(); 
OR
$string_data = Mage::getSingleton('core/session')->getData('my_data'); 

var_dump($string_data ); 

No comments:

Post a Comment

Thank you very much for your comment.
Your message has been successfully sent out to author of this blog.