---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# CartService
## constructor
### Parameters
___
## Properties
`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__moduleDeclaration__","type":"`Record`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} />
___
## Accessors
### activeManager\_
#### Returns
___
## Methods
### addLineItem
Adds a line item to the cart.
#### Parameters
#### Returns
#### Deprecated
Use [addOrUpdateLineItems](services.CartService.mdx#addorupdatelineitems) instead.
### addOrUpdateLineItems
Adds or update one or multiple line items to the cart. It also update all existing items in the cart
to have has\_shipping to false. Finally, the adjustments will be updated.
#### Parameters
#### Returns
### addShippingMethod
Adds the shipping method to the list of shipping methods associated with
the cart. Shipping Methods are the ways that an order is shipped, whereas a
Shipping Option is a possible way to ship an order. Shipping Methods may
also have additional details in the data field such as an id for a package
shop.
#### Parameters
`","description":"the fulmillment data for the method","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]} />
#### Returns
### adjustFreeShipping\_
Ensures shipping total on cart is correct in regards to a potential free
shipping discount
If a free shipping is present, we set shipping methods price to 0
if a free shipping was present, we set shipping methods to original amount
#### Parameters
#### Returns
### applyDiscount
Updates the cart's discounts.
If discount besides free shipping is already applied, this
will be overwritten
Throws if discount regions does not include the cart region
#### Parameters
#### Returns
### applyDiscounts
Updates the cart's discounts.
If discount besides free shipping is already applied, this
will be overwritten
Throws if discount regions does not include the cart region
#### Parameters
#### Returns
### applyGiftCard\_
#### Parameters
#### Returns
### atomicPhase\_
Wraps some work within a transactional block. If the service already has
a transaction manager attached this will be reused, otherwise a new
transaction manager is created.
#### Type Parameters
#### Parameters
Promise<TResult>","description":"the transactional work to be done","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationOrErrorHandler","type":"`IsolationLevel` \\| (`error`: TError) => Promise<void \\| TResult>","description":"the isolation level to be used for the work.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maybeErrorHandlerOrDontFail","type":"(`error`: TError) => Promise<void \\| TResult>","description":"Potential error handler","optional":true,"defaultValue":"","expandable":false,"children":[]}]} />
#### Returns
### authorizePayment
Authorizes a payment for a cart.
Will authorize with chosen payment provider. This will return
a payment object, that we will use to update our cart payment with.
Additionally, if the payment does not require more or fails, we will
set the payment on the cart.
#### Parameters
`","description":"object containing whatever is relevant for\n authorizing the payment with the payment provider. As an example,\n this could be IP address or similar for fraud handling.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} />
#### Returns
### create
Creates a cart.
#### Parameters
#### Returns
### createOrFetchGuestCustomerFromEmail\_
Creates or fetches a user based on an email.
#### Parameters
#### Returns
### createTaxLines
#### Parameters
#### Returns
### decorateTotals
#### Parameters
#### Returns
### decorateTotals\_
#### Parameters
#### Returns
#### Deprecated
Use decorateTotals instead
### delete
Deletes a cart from the database. Completed carts cannot be deleted.
#### Parameters
#### Returns
### deletePaymentSession
Removes a payment session from the cart.
#### Parameters
#### Returns
### deleteTaxLines
#### Parameters
#### Returns
### findCustomShippingOption
Finds the cart's custom shipping options based on the passed option id.
throws if custom options is not empty and no shipping option corresponds to optionId
#### Parameters
#### Returns
### getTotalsRelations
#### Parameters
#### Returns
### getValidatedSalesChannel
#### Parameters
#### Returns
### list
#### Parameters
#### Returns
### onSalesChannelChange
Remove the cart line item that does not belongs to the newly assigned sales channel
#### Parameters
#### Returns
### refreshAdjustments\_
#### Parameters
#### Returns
### refreshPaymentSession
Refreshes a payment session on a cart
#### Parameters
#### Returns
### removeDiscount
Removes a discount based on a discount code.
#### Parameters
#### Returns
### removeLineItem
Removes a line item from the cart.
#### Parameters
#### Returns
### retrieve
Gets a cart by id.
#### Parameters
#### Returns
### retrieveLegacy
#### Parameters
#### Returns
#### Deprecated
### retrieveWithTotals
#### Parameters
#### Returns
### setMetadata
Dedicated method to set metadata for a cart.
To ensure that plugins does not overwrite each
others metadata fields, setMetadata is provided.
#### Parameters
#### Returns
### setPaymentSession
Selects a payment session for a cart and creates a payment object in the external provider system
#### Parameters
#### Returns
### setPaymentSessions
Creates, updates and sets payment sessions associated with the cart. The
first time the method is called payment sessions will be created for each
provider. Additional calls will ensure that payment sessions have correct
amounts, currencies, etc. as well as make sure to filter payment sessions
that are not available for the cart's region.
#### Parameters
#### Returns
### setRegion\_
Set's the region of a cart.
#### Parameters
#### Returns
### shouldRetryTransaction\_
#### Parameters
` \\| `object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} />
#### Returns
### transformQueryForTotals\_
#### Parameters
#### Returns
### update
#### Parameters
#### Returns
### updateBillingAddress\_
Updates the cart's billing address.
#### Parameters
#### Returns
### updateCustomerId\_
Sets the customer id of a cart
#### Parameters
#### Returns
### updateLineItem
Updates a cart's existing line item.
#### Parameters
#### Returns
### updatePaymentSession
Updates the currently selected payment session.
#### Parameters
`","description":"the data to update the payment session with","optional":false,"defaultValue":"","expandable":false,"children":[]}]} />
#### Returns
### updateShippingAddress\_
Updates the cart's shipping address.
#### Parameters
#### Returns
### updateUnitPrices\_
#### Parameters
#### Returns
### validateLineItem
Check if line item's variant belongs to the cart's sales channel.
#### Parameters
#### Returns
### validateLineItemShipping\_
Checks if a given line item has a shipping method that can fulfill it.
Returns true if all products in the cart can be fulfilled with the current
shipping methods.
#### Parameters
#### Returns
### withTransaction
#### Parameters
#### Returns