- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add simple product to cart from external site
Hello Everyone,
My apologies if the following question has been ask and answered....
I am trying to add a simple product to my Magento 2 shopping cart with a link similar to the one below:
http://domainname.com/checkout/cart/add?product=XXXX&qty=X
The link will direct to the shopping cart but the product won't populate. In researching this I see a lot of references to writing a simple PHP script that leverages "Mage.php" to initiate the magento session. It looks like "Mage.php" has been dropped from CE 2.X.
Has anyone determine figured out how to do this?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add simple product to cart from external site
Hello gregfoss1,
In order to do this you can use REST API. The list of REST APIs can be found by the link: http://devdocs.magento.com/guides/v2.0/rest/list.html
First of all, you need to create new cart. The next request will get CART_ID back to new empty cart.
POST /V1/carts/mine
You need to add new product into the created cart. It can be done with the help of :
POST /V1/carts/mine/items
With parameter:
{ "cart_item": { "quote_id": <CART_ID from previous call>, "sku": "PRODUCT_SKU", "qty": 1 } }
You should also check next requests:
PUT /V1/carts/mine/items/:itemId POST /V1/guest-carts/:cartId/items PUT /V1/guest-carts/:cartId/items/:itemId
Regards,
Plumrocket Team