Skip to content
On this page

addProductToCart ​

Definition ​

Adds specific quantity of the product to the cart by productId. It creates a new cart line item.

Warning: This method does not change the state of the cart in any way if productId already exists in a cart. For changing the quantity use addQuantityToCartLineItem() or changeCartLineItemQuantity() methods.

Signature ​

ts
export async function addProductToCart(
  productId: string,
  quantity?: number,
  contextInstance: ShopwareApiInstance = defaultInstance,
): Promise<Cart> 

Parameters ​

NameTypeDescription
productId
string
id of the cart line item (usually it's a product id)
quantity
number
quantity of the product to be added to the cart
contextInstance
ShopwareApiInstance
instance of the api client (by default it's an Axios instance)

Return type ​

ts
Promise<Cart>

Usage example ​

WARNING

Example is generated automatically. Sometimes it's required to be adjusted to your needs.

Open in StackBlitz

addProductToCart has loaded