Skip to content

useAddToCart

useAddToCart

Category:
Cart & Checkout

Composable to manage adding product to cart

With this composable you can:

  • Add product to cart
  • Get product quantity
  • Get product stock
  • Get product available stock
  • Check if product is in cart
  • Get product count in cart

Types

ts
export function useAddToCart(
  product: Ref<Schemas["Product"] | undefined>,
): UseAddToCartReturn

source code

ts
export type UseAddToCartReturn = {
  /**
   * Add to cart method
   * @type {function}
   */
  addToCart(): Promise<Schemas["Cart"]>;
  /**
   * If you want to add more that 1 product set quantity before invoking `addToCart`
   */
  quantity: Ref<number>;
  /**
   * Returns product count in stock
   */
  getStock: ComputedRef<number | undefined>;
  /**
   * Returns product count in available stock
   */
  getAvailableStock: ComputedRef<number | undefined>;
  /**
   * Flag if product is already in cart
   */
  isInCart: ComputedRef<boolean>;
  /**
   * count of the product quantity already in the cart
   */
  count: ComputedRef<number>;
};

source code