7

We are in a project where Magento 2 CE is used as the commerce service provider. Usually when a guest user who has items in Cart login the cart gets merged to the customer's cart and the guest cart will be deleted. How can the same be achieved using Rest APIs in Magento 2? I know that in WCS, we needed to pass the guest token as a header to the Registered user login Rest API. Can someone help us on this?

asked Mar 18, 2016 at 11:25
1
  • hi @ many vijayan whether you got the solution for this api? Commented Nov 2, 2017 at 10:00

2 Answers 2

3

Use the below steps: Method - PUT

{URL}/rest/V1/guest-carts/{guest-card-id}
Param - {
 "customerId": 3,
 "storeId": 1
}

Authorization -"Bearer {user-token}"

It will assign the guest cart to a logged-in user

Rama Chandran M
3,26515 gold badges24 silver badges38 bronze badges
answered Aug 22, 2018 at 11:06
2
0

I got stuck on the same thing. I didn't have any issues using the Magento REST API when I was logged-in but I ran into a bunch of problems using the guest cart API including connecting a guest cart initialized from the REST API to the user session in the backend and transitioning the cart from the guest state to the logged-in state.

In the end I created a custom web service module so that I could do this logic in PHP.

http://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/

https://blog.amasty.com/how-to-create-a-magento-2-extension/

This approach worked well for me so I wanted to put it out there as an option. I find that the Magento documentation for its REST API isn't as good as it could be.

answered Apr 8, 2016 at 11:43
1
  • 1
    Would you not mind sharing the cartMerge Api? Commented Oct 2, 2017 at 10:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.