Magento 2: Set Unset Get Session

This article shows how to create and destroy different types (Checkout, Customer, Catalog) of sessions in Magento 2. As you can see below, there are different types of session classes present in Magento 2. vendor/magento/module-catalog/Model/Session.php vendor/magento/module-newsletter/Model/Session.php vendor/magento/module-persistent/Model/Session.php vendor/magento/framework/Message/Session.php vendor/magento/module-customer/Model/Session.php vendor/magento/module-backend/Model/Session.php vendor/magento/module-checkout/Model/Session.php In below example code, I will be dealing with Catalog, Customer, and Checkout sessions. … Read more

Magento: Get Set Unset Session

Here are code to Get, Set, and Unset Session in Magento. Set session with variable Name ‘testing_magento‘. The session value here is ‘hello‘. Mage::getSingleton(‘core/session’)->setTestingMagento(‘hello’); Get session ‘testing_magento’ $test = Mage::getSingleton(‘core/session’)->getTestingMagento(); Unset session Mage::getSingleton(‘core/session’)->setTestingMagento(); Note: Use customer or core session in frontend. Use adminhtml session in the backend. Core Session:- Mage::getSingleton(‘core/session’) Customer Session:- Mage::getSingleton(‘customer/session’) Admin Session:- … Read more