I am using Magento2 and need to add a product to the cart from a remote site. Same TLD, different subdomain.

ie www.mainsite.com add to checkout.mainsite.com

I was using the REST API and found that it actually uses sessions, which override other data when adding to a cart.

For example POST to /rest/V1/guest-carts will return a cartID and set the PHPSESSID cookie. If you include the PHPSESSID in subsequent POST to /rest/V1/guest-carts/cartID/items then the cartID is overridden and PHPSESSID is used instead.

It seems like the cart data is now tied to PHPSESSID, but if I go to checkout.mainsite.com there is nothing in the shopping cart, even though my PHPSESSID is still the same.

Can the API be used as is to AddToCart from a remote site, then go to Magento2 and view the items in the cart?


Go to General, Web, Default Cookie Settings section, and change the Cookie Domain field to .yoursite.com (note the . before the domain name)

It seems your issue is that your session is not being shared between subdomains, which is not a bug itself but a feature used to enhance security. More info on cookies can be found here and a similar question for M1 can be found here.

  • That is already setup correctly. Both cookie domains are .mainsite.com – username Jan 16 '17 at 18:49
  • So you are using 2 different Magento 2 installs? – mbalparda Jan 16 '17 at 18:50
  • Only checkout.mainsite.com is Magento. www.mainsite.com is another platform. We are trying to use Magento as a headless CMS. – username Jan 16 '17 at 19:18
  • 1
    I don't think you can combine headless with headed Magento versions. If you add to cart via the API you should get the cart via the API and the same goes for adding a product to cart via the headed Magento version. – mbalparda Jan 16 '17 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.