在 magento 2 中,如何在会话中存储观察者值



示例: 我有 2 个观察类。 1-类别.php 2- 产品.php 我想将类别.php数据存储在会话变量中,例如 $_SESSION['category']= $data;并在产品.php类中调用该会话。

像这样:

<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserver as EventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoCheckoutModelSession as CheckoutSession;
class MyOberver implements ObserverInterface
{
protected $checkoutSession;
public function __construct(
CheckoutSession $checkoutSession
) {
$this->_checkoutSession = $checkoutSession;
}

/**
* @param EventObserver $observer
* @return $this
*/
public function execute(EventObserver $observer)
{
$setValue = $this->_checkoutSession->setVar('dit is een sessie test hoppa');
$getValue = $this->_checkoutSession->getVar();
return $this;

}    
}

最新更新