Magento 2会话数据在谷歌铬删除



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

我已经探索过的东西
来自谷歌chrome发布说明(https://www.chromium.org/updates/same-site)我可以看到他们已经将samesite默认值更改为">Lax";,并禁用此功能。

寻找解决方案
我想为我向任何第三方服务发出的所有请求赋予samesite=None值。如有任何帮助或线索,我们将不胜感激。

您可以尝试通过以下步骤设置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">
<type name="MagentoFrameworkViewElementJsCookie">
<plugin name="afterGetPath" type="namespacemodulePluginViewElementJsManagePath" sortOrder="10"/>
</type>
</config>

文件:Plugin/View/Element/Js/ManagePath.php

namespace namespacemodulePluginViewElementJs;
use MagentoFrameworkViewElementJsCookie;
class ManagePath
{
public function afterGetPath(MagentoFrameworkViewElementJsCookie $subject, $path)
{

if (preg_match('/SameSite/', $path)) {
$path_array = explode(';', $path);
$path = $path_array[0];
}

return $path;
}
}

文件: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">
<preference for="MagentoFrameworkSessionConfigConfigInterface" type="namespacemoduleSessionCustomConfig"/>
</config>

文件:会话/CustomConfig.php


namespace namespacemoduleSession;
use MagentoFrameworkSessionConfig as DefaultConfig;
class CustomConfig extends DefaultConfig
{
public function setCookiePath($path, $default = null)
{   
parent::setCookiePath($path, $default);
$path = $this->getCookiePath();
//check and update path of cookie
if (!preg_match('/SameSite/', $path)) {
$path .= '; SameSite=None';
$this->setOption('session.cookie_path', $path);
}
return $this;
}
}

注意:替换名称空间&模块与命名空间模块

由于我没有足够的声誉来评论接受的答案,我必须指出,对我来说,这是不起作用的,因为Chrome要求SameSite设置为";none";以标记为安全。修复程序正在添加:

$path .= '; SameSite=None ; secure';

如果不将它们标记为安全,我将无法将项目添加到购物车中。

为我工作,希望它能帮助其他遇到同样问题的人。

最新更新