CartService
constructor
Parameters
__namedParameters
InjectedDependenciesRequiredProperties
manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequired__container__
anyRequiredEvents
objectRequiredEvents.CUSTOMER_UPDATED
stringRequiredDefault: "cart.customer_updated"
Events.CREATED
stringRequiredDefault: "cart.created"
Events.UPDATED
stringRequiredDefault: "cart.updated"
featureFlagRouter_
FlagRouterRequired__configModule__
Record<string, unknown>__moduleDeclaration__
Record<string, unknown>Accessors
activeManager_
Returns
EntityManager
EntityManagerRequiredMethods
withTransaction
Parameters
transactionManager
EntityManagerReturns
this
thisRequiredshouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleanRequiredatomicPhase_
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
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
Promise<TResult>Requiredlist
Parameters
Default: {}
Returns
retrieve
Gets a cart by id.
Parameters
cartId
stringRequiredDefault: {}
totalsConfig
TotalsConfigRequiredDefault: {}
Returns
retrieveLegacy
Parameters
cartId
stringRequiredDefault: {}
totalsConfig
TotalsConfigRequiredDefault: {}
Returns
Deprecated
retrieveWithTotals
Parameters
cartId
stringRequiredDefault: {}
totalsConfig
TotalsConfigRequiredDefault: {}
Returns
create
Creates a cart.
Parameters
data
CartCreatePropsRequiredReturns
getValidatedSalesChannel
Parameters
salesChannelId
stringReturns
removeLineItem
Removes a line item from the cart.
Parameters
cartId
stringRequiredlineItemId
string | string[]RequiredReturns
Promise
Promise<void>RequiredvalidateLineItemShipping_
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
lineItemShippingProfiledId
stringRequiredReturns
boolean
booleanRequiredvalidateLineItem
Check if line item's variant belongs to the cart's sales channel.
Parameters
sales_channel_id
objectRequiredsales_channel_id.sales_channel_id
null | stringRequiredlineItem
LineItemValidateDataRequiredReturns
Promise
Promise<boolean>RequiredaddLineItem
Adds a line item to the cart.
Parameters
cartId
stringRequiredconfig
objectRequiredconfig.validateSalesChannels
booleanRequiredDefault: true
Returns
Promise
Promise<void>RequiredDeprecated
Use 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
cartId
stringRequiredconfig
objectRequiredconfig.validateSalesChannels
booleanRequiredDefault: true
Returns
Promise
Promise<void>RequiredupdateLineItem
Updates a cart's existing line item.
Parameters
cartId
stringRequiredlineItemId
stringRequiredupdate
LineItemUpdateRequiredReturns
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
shouldAdd
booleanRequiredReturns
Promise
Promise<void>Requiredupdate
Parameters
data
CartUpdatePropsRequiredReturns
onSalesChannelChange
Remove the cart line item that does not belongs to the newly assigned sales channel
Parameters
newSalesChannelId
stringRequiredReturns
Promise
Promise<void>RequiredupdateCustomerId_
Sets the customer id of a cart
Parameters
customerId
stringRequiredReturns
Promise
Promise<void>RequiredcreateOrFetchGuestCustomerFromEmail_
Creates or fetches a user based on an email.
Parameters
email
stringRequiredReturns
updateBillingAddress_
Updates the cart's billing address.
Parameters
Returns
Promise
Promise<void>RequiredupdateShippingAddress_
Updates the cart's shipping address.
Parameters
Returns
Promise
Promise<void>RequiredapplyGiftCard_
Parameters
code
stringRequiredReturns
Promise
Promise<void>RequiredapplyDiscount
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
discountCode
stringRequiredReturns
Promise
Promise<void>RequiredapplyDiscounts
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
discountCodes
string[]RequiredReturns
Promise
Promise<void>RequiredremoveDiscount
Removes a discount based on a discount code.
Parameters
cartId
stringRequireddiscountCode
stringRequiredReturns
updatePaymentSession
Updates the currently selected payment session.
Parameters
cartId
stringRequiredupdate
Record<string, unknown>RequiredReturns
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
context
Record<string, unknown>RequiredReturns
setPaymentSession
Selects a payment session for a cart and creates a payment object in the external provider system
Parameters
cartId
stringRequiredproviderId
stringRequiredReturns
Promise
Promise<void>RequiredsetPaymentSessions
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
Promise
Promise<void>RequireddeletePaymentSession
Removes a payment session from the cart.
Parameters
cartId
stringRequiredproviderId
stringRequiredReturns
Promise
Promise<void>RequiredrefreshPaymentSession
Refreshes a payment session on a cart
Parameters
cartId
stringRequiredproviderId
stringRequiredReturns
Promise
Promise<void>RequiredaddShippingMethod
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
optionId
stringRequireddata
Record<string, unknown>RequiredDefault: {}
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
optionId
stringRequiredReturns
updateUnitPrices_
Parameters
Returns
Promise
Promise<void>RequiredsetRegion_
Set's the region of a cart.
Parameters
regionId
stringRequiredcountryCode
null | stringRequiredReturns
Promise
Promise<void>Requireddelete
Deletes a cart from the database. Completed carts cannot be deleted.
Parameters
cartId
stringRequiredReturns
setMetadata
Dedicated method to set metadata for a cart. To ensure that plugins does not overwrite each others metadata fields, setMetadata is provided.
Parameters
cartId
stringRequiredkey
stringRequiredvalue
string | numberRequiredReturns
createTaxLines
Parameters
Returns
Promise
Promise<void>RequireddeleteTaxLines
Parameters
id
stringRequiredReturns
Promise
Promise<void>RequireddecorateTotals
Parameters
totalsConfig
TotalsConfigRequiredDefault: {}
Returns
refreshAdjustments_
Parameters
Returns
Promise
Promise<void>RequiredtransformQueryForTotals_
Parameters
Returns
decorateTotals_
Parameters
Returns
Deprecated
Use decorateTotals instead
getTotalsRelations
Parameters
Returns
string[]
string[]Required