Adding products to your cart

You can use the cartAddProducts function to add products to your cart. This function takes the products you want to add and includes them in your cart.

After adding products, the function provides an updated cart Cart as the result.

Here is an example of how you can use the mutation to add products to your cart:

mutation CartAddProducts($cartId: ID!, $input: CartAddProductsInput!) {
  cartAddProducts(id: $cartId, input: $input) {
    id
    # Check the Cart type for its fields
  }
}

The quantity field indicates the number of products you want to add to the cart. For instance, let’s say your cart already has 1 unit of the product with ID prd_ZJQYAR_-ypwOLKEz. The following JSON code will add 2 more units of that product, resulting in a total of 3 units:

{
  "input": {
    "cartId": "cart_ZMe6Bb4GqqUe3BWV",
    "products": [
      {
        "productId": "prd_ZJQYAR_-ypwOLKEz",
        "quantity": 2
      },
      {
        "productId": "prd_ZJQYAR_-ypwOLKE0",
        "quantity": 3
      }
    ]
  }
}

Updating Line Items in the Cart

To update line items in your cart, you can use the cartLineUpdate mutation. This mutation allows you to modify the quantity of a specific line item in the cart. Here is an example of how to use this mutation:

mutation CartLineUpdate($id: ID!, $lineId: ID!, $quantity: Int!) {
  cartLineUpdate(id: $id, lineId: $lineId, quantity: $quantity) {
    id
    lines {
      id
      quantity
    }
     # Check the Cart type for remaining fields
  }
}

To update a line item, you’ll need to provide the following parameters:

  • $id: The ID of the cart you want to update.
  • $lineId: The ID of the specific line item within the cart.
  • $quantity: The new quantity you want to set for the line item.

For example, suppose you have a cart with ID “cart_ZWCpKM_dQeQl3oke” and you want to update the quantity of a line item with ID “bagLine_ZWCpLc_dQeQl3okm” to 3 units. You can use the following arguments to the mutation:

{
  "id": "cart_ZWCpKM_dQeQl3oke",
  "lineId": "bagLine_ZWCpLc_dQeQl3okm",
  "quantity": 3
}

Deleting Line Items from the Cart

To remove line items from the cart, you can use the cartLineDelete mutation. This mutation allows you to delete a specific line item from the cart. Here is an example of how to use this mutation:

mutation CartLineDelete($id: ID!, $lineId: ID!) {
  cartLineDelete(id: $id, lineId: $lineId) {
    id
    lines {
      id
      quantity
    }
     # Check the Cart type for remaining fields
  }
}

To delete a line item, you’ll need to provide the following parameters:

  • $id: The ID of the cart from which you want to delete the line item.
  • $lineId: The ID of the specific line item you wish to remove from the cart.

For example, suppose you have a cart with ID “cart_ZWCpKM_dQeQl3oke” and you want to delete a line item with ID “bagLine_ZWCpLc_dQeQl3okm”. You can use the following arguments to the mutation:

{
  "id": "cart_ZWCpKM_dQeQl3oke",
  "lineId": "bagLine_ZWCpLc_dQeQl3okm"
}