1

I am writing a web app that communicates with Magento API for reading product data and then allowing the user to add to cart products they wish to purchase.

All API calls are done using a login I added via the admin site.

When the user finishes the selection process are redirected to the shopping cart on the Magento instance and complete the purchase.

And that's the tricky bit - calls to the API are done using a specific admin user, under this user session. The cart is also added to this admin session. When my user is redirected to the site they won't see anything there, since it's not their session - they are arriving to the site as guests.

One way to solve this would be to make the add to cart from JS and not server side, because this will associate the cart with the browser and not with my server side logic, but I'm not aware of a way to do this. Not to mention cross-domain JS issues.

So - Is there somewhere in the API something that can help me do something like retrieve a URL I can redirect the user to - this URL will associate the cart with the user who is redirected to this URL and then they can see the cart.

This sounds like a reasonable requirement and I believe it should be available one form or another in the current API. At least I hope so.. :)

I prefer to avoid (if possible) writing custom APIs for this.

Any help would be much appreciated!

Thanks!

0

OK, I let this lay around for a couple of days and no answer yet. After much digging I came to the conclusion that it cannot be done without customisation on the Magento side.

I ended up writing a custom Magento controller to handle the transfer of the user from my custom UX to Magento. Along the way I pass details on which items to add to the cart. The controller handles the addition to the cart.

Since the request is executed by the browser then all processing on Magento is done in the user session.

Works for me.

Happy to hear thoughts on how this can be done better.

Cheers.

  • Is it open-source? I need something like that right now – VarunAgw Apr 4 '18 at 7:19

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.