How to save an information in the customer session?

session
customer
(Dmitry Fedyuk) #1

An example from the core:

Actually the session has no setBeforeAuthUrl method and the magic __call method is called:

A usage example

1. Setting an information to the customer session:

/** @var \Magento\Framework\App\ObjectManager $om */
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Customer\Model\Session $session */
$session = $om->get('Magento\Customer\Model\Session');
$session->setTestKey('test value');

2. Getting an information from the customer session:

/** @var \Magento\Framework\App\ObjectManager $om */
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Customer\Model\Session $session */
$session = $om->get('Magento\Customer\Model\Session');
echo $session->getTestKey();
0 Likes

(Dmitry Fedyuk) #2

See also:

0 Likes