When the Magento 2 installation runs on both the main domain and the subdomain, you’ll notice that the ‘ Add to cart ‘ process doesn’t work on the subdomain (both the domains are open in the same browser).
This is a common issue with all the Magento 2 stores as the subdomain hosts the development or staging website.
We faced this issue ourselves as we have our main store on Magento 2. And our Magento 2 extension demo installation is on the subdomain.
We traced this problem and here’s the solution to add-to cart issue on the subdomain:
Problem:
The issue occurs due to a conflict of PHP session cookie named “PHPSESSID”. The subdomain starts reading main domain’s cookie when both are open in the same browser.
Solution:
We changed the PHP session name on the subdomain by adding the code given below at the beginning of Magento’s index.php file:
session_name(‘rcM2DEMO’)
You can replace the text ‘rcM2DEMO’ with any unique string you like. And you’re done!