I am developing third party payment gateway plugin for Magento version 2.4.3 and using PHP version 7.4 with NGINX server. Now I am facing problem after redirecting back from the payment gateway to Magento website.
Due to Same Site cookies issue my session getting lost after returning to the website.
I want to set Same Site Cookie value as None for all requests and for this I have tried all steps as mentioned in the below post.
https://hardikparikh94.medium.com/fixing-magento2-samesite-cookie-issue-8b687908a9e0
I have tried everything as mentioned in the above blog but still Same Site cookie issue is not getting resolved.
Hello @sagar_gopale
We have faced the same issue due to chrome version.
You can refer below custom code for resolve.
You can try setting the samesite=None by following steps..
file : 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>
file : Plugin/View/Element/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;
}
}
file : 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>file : 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;
}
}NOTE : replace namespace & module with your namespace and module.
It may help you!
Thank you