Please someone review my code and help me with suitable code or answer.
I need serious help from community.
Here's the link of code:
https://magento.stackexchange.com/questions/245457/session-not-getting-value-from-phtml-to-block-cla...
Hello @jhon_doe2,
I found the equivalent way for this in Magento2:
Mage::getSingleton('core/session')->setMyValue('test');
Mage::getSingleton('core/session')->unsMyValue();Set/Get/Unset Value in Core Session:
protected $_coreSession;
public function __construct(
-----
\Magento\Framework\Session\SessionManagerInterface $coreSession
){
$this->_coreSession = $coreSession;
----
}
public function setValue(){
$this->_coreSession->start();
$this->_coreSession->setMessage('The Core session');
}
public function getValue(){
$this->_coreSession->start();
return $this->_coreSession->getMessage();
}
public function unSetValue(){
$this->_coreSession->start();
return $this->_coreSession->unsMessage();
}
By this way we can set custom values if our session value is not related to below sessions:
--
If my answer is useful, please Accept as Solution & give Kudos
Mage::getSingleton
This function is not working in my case.
Kindly use \Magento\Framework\Session\Generic class for default session,
public function __construct(
\Magento\Quote\Model\QuoteValidator $quoteValidator,
\Magento\Framework\Session\Generic $session
) {
$this->quoteValidator = $quoteValidator;
$this->_coreSession = $coreSession;
}
public function getValue()
{
return $this->_coreSession->getMyValue(); //Get value from customer session
}
public function setValue($total_cost)
{
return $this->_coreSession->setMyValue($total_cost);
}
Hello @jhon_doe2,
Please use getModel function on it.
--
If my answer is useful, please Accept as Solution & give Kudos