addLineItems - Cart Module Reference

This documentation provides a reference to the addLineItems method. This belongs to the Cart Module.

NoteYou should only use this methods when implementing complex customizations. For common cases, check out available workflows instead.

addLineItems(data): Promise<CartLineItemDTO[]>#

This method adds a line item to a cart

Example#

Code
1const lineItem = await cartModuleService.addLineItems({2  cart_id: "cart_123",3  title: "Shirt",4  quantity: 2,5  unit_price: 4000,6})

Parameters#

The line item to create and add to the cart. The cart is specified in the cart_id field.

Returns#

PromisePromise<CartLineItemDTO[]>
The added line item.

addLineItems(data): Promise<CartLineItemDTO[]>#

This method adds line items to carts.

Example#

Code
1const lineItems = await cartModuleService.addLineItems([2  {3    cart_id: "cart_123",4    title: "Shirt",5    quantity: 2,6    unit_price: 4000,7  },8  {9    cart_id: "cart_123",10    title: "Pants",11    quantity: 1,12    unit_price: 3000,13  },14])

Parameters#

The line item to create and add to the carts. The cart is specified in the cart_id field.

Returns#

PromisePromise<CartLineItemDTO[]>
The added line items.

addLineItems(cartId, items, sharedContext?): Promise<CartLineItemDTO[]>#

This method adds line items to a cart.

Example#

Code
1const lineItems = await cartModuleService.addLineItems(2  "cart_123",3  [4    {5      title: "Shirt",6      quantity: 2,7      unit_price: 4000,8    },9    {10      title: "Pants",11      quantity: 1,12      unit_price: 3000,13    },14  ]15)

Parameters#

cartIdstring
The cart's ID.
The line items to be created and added.
sharedContextContextOptional
A context used to share resources, such as transaction manager, between the application and the module.

Returns#

PromisePromise<CartLineItemDTO[]>
The added line items.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break