Do you want to build your own magento mobile app shopping cart feature for your e-commerce store? It’s a great idea to allow your visitors to buy stuff on your store and increase your sales. Magento is most famous and vastly used by online stores and its newer version provides great flexibility to integrate REST API to the mobile app. One of the important features in any e-commerce application is “shopping cart”.In this article, we shall explain the steps to add shopping cart functionality using Magento 2.0 REST API .
Build Magento mobile app shopping cart in three easy steps
Here are simple steps which shall be implemented on your mobile app:
1. Add empty cart to the app
Use the following API to add
POST rest/V1/carts/mine/
This call will create a cart and return a “quote_id“ of the cart. This “quote_id“ is specific to the cart so save this “quote_id“ because this will be used in further addition of item in the cart.
For a guest following API will be used
POST rest/V1/carts/
2. Add Item to the Cart
Use the following API to add items to the cart
POST rest/V1/carts/mine/items
with parameters
{"cartItem": {"sku": "test_product", "qty": 1,"name":"Test Product","product_type":"simple","quote_id": "5"}}
This will return the following result:
{"item_id":1,"sku":"test_product","qty":1,"name":"Test Product","price":0,"product_type":"simple","quote_id":"5"}
For the Guest following api will be used:
POST rest/V1/carts/{cartId}/items
with the same parameters as in customer.
3. List the Items in the Cart
Use the below API to access the items of the cart :
GET rest/V1/carts/mine/items
or for a guest:
GET rest /V1/carts/{cartId}/items
This will return the list of the items added in the cart.
That’s about it, some simple steps to add and list the items in cart.
Conclusion
Adding Item to cart is a very important step in any e-commerce application. Magento 2.0 has some enhancement in the calls from the previous version, and so in the “add to cart” call. We have tried to explain the REST API and its implementation in details so that you can add it on your mobile app.
Hope this will help someone! Feel free to contact us if you have any questions or suggestions.
References
MagentoShop- Shopping App