Skip to content
On this page

Cart Structure

This is the structure of the cart object that you will be sending to Order Protection inside the createWidget function .

Example:

typescript
{
  load: async () => {
    // Code to reload cart
    const response = await fetch("/cart.js");
    const data = await response.json();
    opWidget.cart = data;
  },
  add: async () => {
    // Code to add item to cart
    await fetch("/cart/add.js");
  },
  remove: async () => {
    // Code to remove item from cart
    await fetch("/cart/remove.js");
  },
  get item_count() {
    // Code to get item count
    return widget.cart.item_count;
  },
  get items() {
    // Code to get items
    return widget.cart.items;
  },
  get requires_shipping() {
    // Code to get if cart requires shipping
    return widget.cart.requires_shipping;
  },
  get subtotal() {
    // Code to get subtotal
    return widget.cart.items_subtotal_price;
  },
  get total_price() {
    // Code to get total price
    return widget.cart.total_price;
  },
}