启用所有缓存后,Magento 2 Cookie不起作用


9

在观察者中,我正在这样设置一个cookie:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');

$cookieManager->setPublicCookie('myvar', $myVar);

Full page caching禁用时一切正常。但是,一旦启用它,就不会设置cookie。

我怎样才能解决这个问题?

Answers:



2

我设法以与magento使用插件设置其存储方式相同的方式设置cookie。

参见文件以了解插件定义:vendor / magento / module-store / etc / di.xml:265

<type name="Magento\Framework\App\FrontController">
    <plugin name="storeCookieValidate" type="Magento\Store\Model\Plugin\StoreCookie" sortOrder="10"/>
</type>

在这里,您可以在beforeDispatch()vendor / magento / module-store / Model / Plugin / StoreCookie.php:69 上设置实际的cookie

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.