Method: POST
Product cart can be handled in two ways.
- Locally
- Non locally.(default)
Locally means you handle the cart yourself, and post the entire data(array of product, coupon, etc..) during checkout.
Non locally means you use the api to handle your cart and post only the cart id during checkout.
NB: DURING LOGIN/ REGISTRATION YOU POST “cart_id” WHY.
if you handle cart non locally, then this cart id most be posted during authentication so that it will be added into the user profile.
eg, if a non authenticated user is adding item to cart, whenever he autheticate, if you dont post the cart id generated by the API ALONG, the user will loose the cart.
now, the cart could be for ogwugo local, ogwugo internatioanl or ogwugo food cart, that calls for
domain (ENUM(local,international,food,gas)) default is local
WHEN A QUEST ADD PRODUCT TO CART the cart_id > 0 is returned, if you remove product from cart, if its the last product, the response will return cart_id = 0.
Only when your cart is handled non locally that you need the endpoints bellow, and its the default.
- Add Product to cart.
path:
/cart/product/add
DataType [default] | Detail | |
---|---|---|
cart_id | int. | req |
platform | (ENUM(web,android,ios)) | reg |
domain | (ENUM(local,international,food,gas)) | reg |
product_id | int. | req |
quantity | int. | req |
user_id | int. | req |
filters | [] | optional |
variations | [] | optional |
cart_id =0, if the user do not already have item in cart.
user_id = 0, if the user is a guest.
if user add product to cart, a cart_id is returned, if the user want to add more product to this same cart, post cart_id = the cart_id returned earlier.
POST ‘filters’ ONLY if the product has filters (these are selectable properties like color during order)
if the product has data.attributes post the selected value and the index thus: {“Color”:”Black”,”Size”:”S”} for which the user has selected.
VARIATIONS:
variations[] (follow the same rules for filters array. ask about getting it right.)
variations are items that give us change in price while they are selected, eg, you select red color and the product price increases.
filters are almost the same but they do not change the price.
posting filter array: string: {“Color”:”Black”,”Size”:”L”,”Soup Type”:”Ora”}
posting variations as string also : {“1″:”22″,”3″:”6″,”34″:”66”}
the difference is that variations you post index of the varying property(eg Color = 1) with id of the value(eg Black = 22). eg 1 means color and 22 means Black
in the product data, you see see Color with id 1, and the value, black,… etc
THUS SEE SAMPLE FOR HTML FORM: name=”variations[{{ variation.var_id }}]”
name=”filters[{{ attr.name }}]”
NB: if a user login, you are to post the cart id if no cart, then cart_id = o..
remember that if a user has product in cart, then logs out. if the same user comes back, add product to cart as quest you have a new cart_id now and post it during login, the api will combine the two cart details and return a new cart id for you, remember to watch the new cart_id returned
RESPONSE:
adding to cart will return status = true..
if the product has filters and you did not set it, it will return false with data: “take_to_product_page = 1” which assumes the attempt to add to cart was performed from non product page(eg home) where the user did not select options and thus should be redirected to product page to complete.
2. REMOVE product from CART.
path:
/cart/product/remove_product
DataType [default] | Detail | |
---|---|---|
cart_id | int. | req |
item_id | int. | reg |
user_id | int. | |
RESPONSE : cart_empty = 1 (cart removed if item is now zero after removing)
3. EMPTY THE CART
path:
/cart/empty_cart
DataType [default] | Detail | |
---|---|---|
cart_id | int. | req |
user_id | int. | |
4. UPDATE CART PRODUCTS QUANTITIES
path:
/cart/update_cart
DataType [default] | Detail | |
---|---|---|
cart_id | int. | req |
quantity | [] | reg |
user_id | int. | |
product | [] | reg |
item | [] | req |
x-form data url-encoded | ||
update all products quantity once.
5. GET ALL CART DETAILS..
method: [GET,POST]
path:
/cart/local_cart
post cart_id & user_id
6. UPDATE ADDRESS OR SHIPPER
method: [POST]
path:
/cart/update/address updates the user address or shipping company in a cart to enable calculating shipping fee on the fly.
DataType [default] | Detail | |
---|---|---|
cart_id | int. | req |
shipper_id | int | 0 to use default |
user_id | int. | reg, must be >0 |
address_id | int | 0 to use default |
x-form data url-encoded | ||