We have to add product into cart using on the bases of Ajax response from another domain on requesting Magento 2 Add to cart url or function.

Request url or domain:


Response domain: "localhost/"

So here is the problem:

Product has been added to cart but while getting response customer cart session has been changed to new and new quote id is created I.e fresh cart session will be created and existing products from the cart are wipeout and new added products will be shown only. Also on every response for the request having new session for cart. On using request url on the browser its working fine and product has been added to cart as expected.

Issue is when we are using that add to cart functionality with Ajax or adding product after response from localhost domain has issue. I guess response is coming from cross domain that’s why its creating problem?

If any one faced this kind of situation and have solution for Magento 2.1.6 will be appreciated.

NOTE: This the way Iam using is working fine in Magento 1 versions but not working in Magento 2

  • FYI: I am able to figure-out the solution of the problem, with below parameters passing to url. $session_id = "abacccsdojsodjasiahdai" // get our session echo Mage::getUrl( '/', array('_store' => $YOUR_STORE_ID,// pass along a store id IF NEEDED '_query' => array('SID' => $session_id ), //make sure we append our session '_store_to_url' => true ) ); // lastly add store to our url if needed – Keshav Patidar Jun 12 '17 at 20:51

Your Answer

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

Browse other questions tagged or ask your own question.