您可以尝试按照以下步骤设置 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="Magento\Framework\View\Element\Js\Cookie">
<plugin name="afterGetPath" type="namespace\module\Plugin\View\Element\Js\ManagePath" sortOrder="10"/>
</type>
</config>
文件:插件/视图/元素/Js/ManagePath.php
namespace namespace\module\Plugin\View\Element\Js;
use Magento\Framework\View\Element\Js\Cookie;
class ManagePath
{
public function afterGetPath(\Magento\Framework\View\Element\Js\Cookie $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="Magento\Framework\Session\Config\ConfigInterface" type="namespace\module\Session\CustomConfig"/>
</config>
文件:Session/CustomConfig.php
namespace namespace\module\Session;
use Magento\Framework\Session\Config 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;
}
}
注意:用您的命名空间和模块替换命名空间和模块。