I need to set a variable session in Magento, do I do just procedural PHP or is there a proper way in Magento 2 ?
Example :
$_SESSION['myKey'] = "00001";
@AnsarHunsain code help me, but I can't get my value into another page. My page and my block are on the same module than the block where I've defined getCheckoutSession.
I have this error with this :
echo $block->getCheckoutSession()->getCommande();
Call to a member function getCommande() on null
Best Answer
You can use to set and get custom session value like below
You can use dependency injection also like below
Use below code in phtml file