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?

1
  • hi @ many vijayan whether you got the solution for this api?
    – Nagaraju K
    Nov 2 '17 at 10:00
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

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.

1
  • 1
    Would you not mind sharing the cartMerge Api?
    – MagePsycho
    Oct 2 '17 at 10:39

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.