猿问

Magento 2 会话数据在 google chrome 中被删除

问题:
当我的 magento2.3 应用程序将用户重定向到支付网关时,我可以访问所有会话数据。但是当它从那里返回时,它没有结账会话数据或任何会话数据。这只发生在谷歌浏览器上

我已经探索过的事情
从 google chrome 发行说明(https://www.chromium.org/updates/same-site)我可以看到他们已将 Samesite 默认值更改为“ Lax ”,并禁用此功能。

解决方案寻找我想为我对任何第三方服务的所有传出请求
提供Samesite=None值。任何帮助或领导将不胜感激。


犯罪嫌疑人X
浏览 97回答 2
2回答

斯蒂芬大帝

您可以尝试按照以下步骤设置Samesite=None 。文件:etc/frontend/di.xml<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">&nbsp; &nbsp; <type name="Magento\Framework\View\Element\Js\Cookie">&nbsp; &nbsp; &nbsp; &nbsp; <plugin name="afterGetPath" type="namespace\module\Plugin\View\Element\Js\ManagePath" sortOrder="10"/>&nbsp; &nbsp; </type></config>文件:插件/视图/元素/Js/ManagePath.phpnamespace namespace\module\Plugin\View\Element\Js;use Magento\Framework\View\Element\Js\Cookie;class ManagePath{&nbsp; &nbsp; public function afterGetPath(\Magento\Framework\View\Element\Js\Cookie $subject, $path)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (preg_match('/SameSite/', $path)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$path_array = explode(';', $path);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$path = $path_array[0];&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; return $path;&nbsp; &nbsp; }}文件:etc/di.xml<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">&nbsp; &nbsp; <preference for="Magento\Framework\Session\Config\ConfigInterface" type="namespace\module\Session\CustomConfig"/></config>文件:会话/CustomConfig.phpnamespace namespace\module\Session;use Magento\Framework\Session\Config as DefaultConfig;class CustomConfig extends DefaultConfig{&nbsp; &nbsp; public function setCookiePath($path, $default = null)&nbsp; &nbsp; {&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; parent::setCookiePath($path, $default);&nbsp; &nbsp; &nbsp; &nbsp; $path = $this->getCookiePath();&nbsp; &nbsp; &nbsp; &nbsp; //check and update path of cookie&nbsp; &nbsp; &nbsp; &nbsp; if (!preg_match('/SameSite/', $path)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $path .= '; SameSite=None';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this->setOption('session.cookie_path', $path);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return $this;&nbsp; &nbsp; }}注意:用您的命名空间和模块替换命名空间和模块。

慕仙森

由于我没有足够的声誉来评论已接受的答案,我必须指出,对我来说它不起作用,因为 Chrome 要求将 SameSite 的所有 cookie 设置为“无”以标记为安全。修复添加:$path&nbsp;.=&nbsp;';&nbsp;SameSite=None&nbsp;;&nbsp;secure';如果不将它们标记为安全,我将无法将商品添加到购物车。为我工作,希望它能帮助遇到同样问题的其他人。
随时随地看视频慕课网APP
我要回答