Cart
This section details the functions related to the shopping cart in the Zid Themes Library.
Note: For functions that require a
product_id
parameter, this parameter can be obtained from user interactions within the theme. Anonclick
event handler in your theme's interactive elements, such as buttons or images, can capture and pass theproduct_id
to these functions.
Fetch Cart
Function: fetch
Description: Retrieves the current contents and data of the shopping cart, including products, pricing, applied coupons and offers, and other related attributes.
Usage: zid.store.cart.fetch().then(function (response) { /* Handle response */ });
Add Product to Cart
Function: addProduct
Description: Adds a product to the cart. Useful for simple products, i.e., products with neither variants nor custom input fields. For complex products, refer to the Products Template documentation.
Parameters:
product_id
quantity
options
(optional)custom_fields
(optional)
Usage: zid.store.cart.addProduct({ productId, quantity }).then(function (response) { /* Handle response */ });
Update Product in Cart
Function: updateProduct
Description: Updates the quantity of a specific product in the cart.
Parameters:
cart_product_id
- The identifier for the product entry within the cart (cart.products[].id
in the Cart payload.quantity
- The new quantity of the product.product_id
- The original product identifier (cart.products[].product_id
in the Cart payload.
Usage: zid.store.cart.updateProduct(cart_product_id, quantity, product_id).then(function (response) { /* Handle response */ });
Remove Product from Cart
Function: removeProduct
Description: Removes a specific product from the cart.
Parameters:
cart_product_id
- The identifier for the product entry within the cart (cart.products[].id
in the Cart payload.product_id
- The original product identifier (cart.products[].product_id
in the Cart payload.
Usage: zid.store.cart.removeProduct(cart_product_id, product_id).then(function (response) { /* Handle response */ });
Redeem Coupon in Cart
Function: redeemCoupon
Description: Applies a coupon code to the cart for discounts or offers.
Parameters:
coupon_code
Usage: zid.store.cart.redeemCoupon(coupon_code).then(function (response) { /* Handle response */ });
Remove Coupon from Cart
Function: removeCoupon
Description: Removes any currently applied coupon from the cart.
Usage: zid.store.cart.removeCoupon().then(function (response) { /* Handle response */ });