Skip to content

Cart Actions

Adds coupons to the cart.

import { addCouponsToCart } from '@shopgate/engage/cart';
const couponIds = ['someCouponId', 'anotherCouponId'];
dispatch(addCouponsToCart(couponIds));
  • couponIds (Array<string>): The IDs of the coupons to add to the cart.

Adds products to the cart. For each product that is added, this action determines if the product is a product variant or a base product by the input productId. Metadata is then updated appropriately based off of the productId.

import { addProductsToCart } from '@shopgate/engage/cart';
const productsData = [
{
productId: '1',
quantity: 1,
},
{
productId: '2',
quantity: 5,
}
];
dispatch(addProductsToCart(productsData));
  • data (Array<Object>) required: The data necessary for the products to be added to the cart.
    • productId (string) required: can be a base product ID or variant product ID.
    • quantity (number) required: any number greater than 0.
    • options (Array<Object>) Required when a product with options is added to the cart.
      • type (string) required: Option type (select or text).
      • id (string) required: Option ID.
      • value (string) required: Option value (ID of an option value for select options, input value for text options.)

Removes coupons from the cart.

import { deleteCouponsFromCart } from '@shopgate/engage/cart';
const couponIds = ['someCouponId', 'anotherCouponId'];
dispatch(deleteCouponsFromCart(couponIds));
  • couponIds (Array<string>) required: The IDs of the coupons to be removed from the cart.

Removes products from the cart.

import { deleteProductsFromCart } from '@shopgate/engage/cart';
const cartItemIds = ['1', '2', '5'];
dispatch(deleteProductsFromCart(cartItemIds));
  • cartItemIds (Array<string>) required: The IDs of the cart items to be removed from the cart.

Retrieves the current cart for the user.

import { fetchCart } from '@shopgate/engage/cart';
dispatch(fetchCart());

Updates the quantity of a product in the cart. The input can be an array of multiple products.

import { updateProductsInCart } from '@shopgate/engage/cart';
const updateData = [
{
cartItemId: '20',
quantity: 2,
},
{
cartItemId: '21',
quantity: 4,
}
]
dispatch(updateProductsInCart(updateData));
  • updateData (Array<Object>) required: The data required to update the products in the cart.
    • cartItemId (string) required: The ID of the cart item to be updated.
    • quantity (number) required: Any number greater than 0.