Skip to main content

Class: CartService

Hierarchy

  • TransactionBaseServiceCopy to Clipboard

    CartServiceCopy to Clipboard

Constructors

constructor

new CartService(__namedParametersCopy to Clipboard)

Parameters

NameType
__namedParametersCopy to ClipboardInjectedDependenciesCopy to Clipboard

Overrides

TransactionBaseService.constructor

Defined in

packages/medusa/src/services/cart.ts:137

Properties

__configModule__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __configModule__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__configModule__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:10


__container__

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard __container__: anyCopy to Clipboard

Inherited from

TransactionBaseService.__container__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:9


__moduleDeclaration__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __moduleDeclaration__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:11


addressRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard addressRepository_: typeof AddressRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:112


cartRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard cartRepository_: typeof CartRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:111


customShippingOptionService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard customShippingOptionService_: CustomShippingOptionServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:130


customerService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard customerService_: CustomerServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:123


discountService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard discountService_: DiscountServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:125


eventBus_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard eventBus_: EventBusServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:115


featureFlagRouter_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard featureFlagRouter_: FlagRouterCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:133


giftCardService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard giftCardService_: GiftCardServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:126


lineItemAdjustmentService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard lineItemAdjustmentService_: LineItemAdjustmentServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:132


lineItemRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard lineItemRepository_: typeof LineItemRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:114


lineItemService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard lineItemService_: LineItemServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:121


manager_

ProtectedCopy to Clipboard manager_: EntityManagerCopy to Clipboard

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/cart.ts:107


newTotalsService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard newTotalsService_: NewTotalsServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:129


paymentProviderService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard paymentProviderService_: PaymentProviderServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:122


paymentSessionRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard paymentSessionRepository_: typeof PaymentSessionRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:113


priceSelectionStrategy_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard priceSelectionStrategy_: IPriceSelectionStrategyCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:131


productService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard productService_: ProductServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:117


productVariantInventoryService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard productVariantInventoryService_: ProductVariantInventoryServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:135


productVariantService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard productVariantService_: ProductVariantServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:116


regionService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard regionService_: RegionServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:120


salesChannelService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard salesChannelService_: SalesChannelServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:119


shippingMethodRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard shippingMethodRepository_: typeof ShippingMethodRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:110


shippingOptionService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard shippingOptionService_: ShippingOptionServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:124


storeService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard storeService_: StoreServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:118


taxProviderService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard taxProviderService_: TaxProviderServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:127


totalsService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard totalsService_: TotalsServiceCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:128


transactionManager_

ProtectedCopy to Clipboard transactionManager_: undefinedCopy to Clipboard | EntityManagerCopy to Clipboard

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/cart.ts:108


Events

StaticCopy to Clipboard ReadonlyCopy to Clipboard Events: ObjectCopy to Clipboard

Type declaration

NameType
CREATEDCopy to ClipboardstringCopy to Clipboard
CUSTOMER_UPDATEDCopy to ClipboardstringCopy to Clipboard
UPDATEDCopy to ClipboardstringCopy to Clipboard

Defined in

packages/medusa/src/services/cart.ts:101

Methods

addLineItem

addLineItem(cartIdCopy to Clipboard, lineItemCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Adds a line item to the cart.

DeprecatedCopy to Clipboard

Use addOrUpdateLineItems instead.

Parameters

NameTypeDefault valueDescription
cartIdCopy to ClipboardstringCopy to ClipboardundefinedCopy to Clipboardthe id of the cart that we will add to
lineItemCopy to ClipboardLineItemCopy to ClipboardundefinedCopy to Clipboardthe line item to add.
configCopy to ClipboardObjectCopy to ClipboardundefinedCopy to ClipboardvalidateSalesChannels - should check if product belongs to the same sales chanel as cart (if cart has associated sales channel)
config.validateSalesChannelsCopy to ClipboardbooleanCopy to ClipboardtrueCopy to Clipboard-

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:619


addOrUpdateLineItems

addOrUpdateLineItems(cartIdCopy to Clipboard, lineItemsCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

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

NameTypeDefault valueDescription
cartIdCopy to ClipboardstringCopy to ClipboardundefinedCopy to Clipboardthe id of the cart that we will add to
lineItemsCopy to ClipboardLineItemCopy to Clipboard | LineItemCopy to Clipboard[]undefinedCopy to Clipboardthe line items to add.
configCopy to ClipboardObjectCopy to ClipboardundefinedCopy to ClipboardvalidateSalesChannels - should check if product belongs to the same sales chanel as cart (if cart has associated sales channel)
config.validateSalesChannelsCopy to ClipboardbooleanCopy to ClipboardtrueCopy to Clipboard-

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:745


addShippingMethod

addShippingMethod(cartOrIdCopy to Clipboard, optionIdCopy to Clipboard, data?Copy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

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

NameTypeDescription
cartOrIdCopy to ClipboardstringCopy to Clipboard | CartCopy to Clipboardthe id or the cart to add shipping method to
optionIdCopy to ClipboardstringCopy to Clipboardid of shipping option to add as valid method
dataCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>the fulmillment data for the method

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:2068


adjustFreeShipping_

ProtectedCopy to Clipboard adjustFreeShipping_(cartCopy to Clipboard, shouldAddCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

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

NameTypeDescription
cartCopy to ClipboardCartCopy to Clipboardthe the cart to adjust free shipping for
shouldAddCopy to ClipboardbooleanCopy to Clipboardflag to indicate, if we should add or remove

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

void

Defined in

packages/medusa/src/services/cart.ts:992


applyDiscount

applyDiscount(cartCopy to Clipboard, discountCodeCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

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

NameTypeDescription
cartCopy to ClipboardCartCopy to Clipboardthe cart to update
discountCodeCopy to ClipboardstringCopy to Clipboardthe discount code

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:1414


applyDiscounts

applyDiscounts(cartCopy to Clipboard, discountCodesCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

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

NameTypeDescription
cartCopy to ClipboardCartCopy to Clipboardthe cart to update
discountCodesCopy to ClipboardstringCopy to Clipboard[]the discount code(s) to apply

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:1426


applyGiftCard_

ProtectedCopy to Clipboard applyGiftCard_(cartCopy to Clipboard, codeCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Parameters

NameType
cartCopy to ClipboardCartCopy to Clipboard
codeCopy to ClipboardstringCopy to Clipboard

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:1379


atomicPhase_

ProtectedCopy to Clipboard atomicPhase_<TResultCopy to Clipboard, TErrorCopy to Clipboard>(workCopy to Clipboard, isolationOrErrorHandler?Copy to Clipboard, maybeErrorHandlerOrDontFail?Copy to Clipboard): PromiseCopy to Clipboard<TResultCopy to Clipboard>

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

Name
TResultCopy to Clipboard
TErrorCopy to Clipboard

Parameters

NameTypeDescription
workCopy to Clipboard(transactionManagerCopy to Clipboard: EntityManagerCopy to Clipboard) => PromiseCopy to Clipboard<TResultCopy to Clipboard>the transactional work to be done
isolationOrErrorHandler?Copy to ClipboardIsolationLevelCopy to Clipboard | (errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?Copy to Clipboard(errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>Potential error handler

Returns

PromiseCopy to Clipboard<TResultCopy to Clipboard>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:50


authorizePayment

authorizePayment(cartIdCopy to Clipboard, context?Copy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

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

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to authorize payment for
contextCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard> & { cart_idCopy to Clipboard: stringCopy to Clipboard }object containing whatever is relevant for authorizing the payment with the payment provider. As an example, this could be IP address or similar for fraud handling.

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the resulting cart

Defined in

packages/medusa/src/services/cart.ts:1592


create

create(dataCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Creates a cart.

Parameters

NameTypeDescription
dataCopy to ClipboardCartCreatePropsCopy to Clipboardthe data to create the cart with

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the result of the create operation

Defined in

packages/medusa/src/services/cart.ts:320


createOrFetchGuestCustomerFromEmail_

ProtectedCopy to Clipboard createOrFetchGuestCustomerFromEmail_(emailCopy to Clipboard): PromiseCopy to Clipboard<CustomerCopy to Clipboard>

Creates or fetches a user based on an email.

Parameters

NameTypeDescription
emailCopy to ClipboardstringCopy to Clipboardthe email to use

Returns

PromiseCopy to Clipboard<CustomerCopy to Clipboard>

the resultign customer object

Defined in

packages/medusa/src/services/cart.ts:1266


createTaxLines

createTaxLines(cartOrIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Parameters

NameType
cartOrIdCopy to ClipboardstringCopy to Clipboard | CartCopy to Clipboard

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:2477


decorateTotals

decorateTotals(cartCopy to Clipboard, totalsConfig?Copy to Clipboard): PromiseCopy to Clipboard<WithRequiredPropertyCopy to Clipboard<CartCopy to Clipboard, "total"Copy to Clipboard>>

Parameters

NameType
cartCopy to ClipboardCartCopy to Clipboard
totalsConfigCopy to ClipboardTotalsConfigCopy to Clipboard

Returns

PromiseCopy to Clipboard<WithRequiredPropertyCopy to Clipboard<CartCopy to Clipboard, "total"Copy to Clipboard>>

Defined in

packages/medusa/src/services/cart.ts:2527


decorateTotals_

ProtectedCopy to Clipboard decorateTotals_(cartCopy to Clipboard, totalsToSelectCopy to Clipboard, options?Copy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

DeprecatedCopy to Clipboard

Use decorateTotals instead

Parameters

NameType
cartCopy to ClipboardCartCopy to Clipboard
totalsToSelectCopy to ClipboardTotalFieldCopy to Clipboard[]
optionsCopy to ClipboardTotalsConfigCopy to Clipboard

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:2700


delete

delete(cartIdCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Deletes a cart from the database. Completed carts cannot be deleted.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to delete

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the deleted cart or undefined if the cart was not found.

Defined in

packages/medusa/src/services/cart.ts:2392


deletePaymentSession

deletePaymentSession(cartIdCopy to Clipboard, providerIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Removes a payment session from the cart.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to remove from
providerIdCopy to ClipboardstringCopy to Clipboardthe id of the provider whoose payment session should be removed.

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the resulting cart.

Defined in

packages/medusa/src/services/cart.ts:1959


deleteTaxLines

deleteTaxLines(idCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Parameters

NameType
idCopy to ClipboardstringCopy to Clipboard

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:2508


findCustomShippingOption

findCustomShippingOption(cartCustomShippingOptionsCopy to Clipboard, optionIdCopy to Clipboard): undefinedCopy to Clipboard | CustomShippingOptionCopy to Clipboard

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

NameTypeDescription
cartCustomShippingOptionsCopy to ClipboardCustomShippingOptionCopy to Clipboard[]the cart's custom shipping options
optionIdCopy to ClipboardstringCopy to Clipboardid of the normal or custom shipping option to find in the cartCustomShippingOptions

Returns

undefinedCopy to Clipboard | CustomShippingOptionCopy to Clipboard

custom shipping option

Defined in

packages/medusa/src/services/cart.ts:2175


getTotalsRelations

PrivateCopy to Clipboard getTotalsRelations(configCopy to Clipboard): stringCopy to Clipboard[]

Parameters

NameType
configCopy to ClipboardFindConfigCopy to Clipboard<CartCopy to Clipboard>

Returns

stringCopy to Clipboard[]

Defined in

packages/medusa/src/services/cart.ts:2751


getValidatedSalesChannel

ProtectedCopy to Clipboard getValidatedSalesChannel(salesChannelId?Copy to Clipboard): PromiseCopy to Clipboard<SalesChannelCopy to Clipboard>

Parameters

NameType
salesChannelId?Copy to ClipboardstringCopy to Clipboard

Returns

PromiseCopy to Clipboard<SalesChannelCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:456


list

list(selectorCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard[]>

Parameters

NameTypeDescription
selectorCopy to ClipboardFilterableCartPropsCopy to Clipboardthe query object for find
configCopy to ClipboardFindConfigCopy to Clipboard<CartCopy to Clipboard>config object

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard[]>

the result of the find operation

Defined in

packages/medusa/src/services/cart.ts:201


onSalesChannelChange

ProtectedCopy to Clipboard onSalesChannelChange(cartCopy to Clipboard, newSalesChannelIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Remove the cart line item that does not belongs to the newly assigned sales channel

Parameters

NameTypeDescription
cartCopy to ClipboardCartCopy to ClipboardThe cart being updated
newSalesChannelIdCopy to ClipboardstringCopy to ClipboardThe new sales channel being assigned to the cart

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

void

Defined in

packages/medusa/src/services/cart.ts:1212


refreshAdjustments_

ProtectedCopy to Clipboard refreshAdjustments_(cartCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Parameters

NameType
cartCopy to ClipboardCartCopy to Clipboard

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:2621


refreshPaymentSession

refreshPaymentSession(cartIdCopy to Clipboard, providerIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Refreshes a payment session on a cart

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to remove from
providerIdCopy to ClipboardstringCopy to Clipboardthe id of the provider whoose payment session should be removed.

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the resulting cart.

Defined in

packages/medusa/src/services/cart.ts:2013


removeDiscount

removeDiscount(cartIdCopy to Clipboard, discountCodeCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Removes a discount based on a discount code.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to remove from
discountCodeCopy to ClipboardstringCopy to Clipboardthe discount code to remove

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the resulting cart

Defined in

packages/medusa/src/services/cart.ts:1502


removeLineItem

removeLineItem(cartIdCopy to Clipboard, lineItemIdCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Removes a line item from the cart.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart that we will remove from
lineItemIdCopy to ClipboardstringCopy to Clipboardthe line item to remove.

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:488


retrieve

retrieve(cartIdCopy to Clipboard, options?Copy to Clipboard, totalsConfig?Copy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Gets a cart by id.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to get.
optionsCopy to ClipboardFindConfigCopy to Clipboard<CartCopy to Clipboard>the options to get a cart
totalsConfigCopy to ClipboardTotalsConfigCopy to Clipboard

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the cart document.

Defined in

packages/medusa/src/services/cart.ts:219


retrieveLegacy

ProtectedCopy to Clipboard retrieveLegacy(cartIdCopy to Clipboard, options?Copy to Clipboard, totalsConfig?Copy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

DeprecatedCopy to Clipboard

Parameters

NameType
cartIdCopy to ClipboardstringCopy to Clipboard
optionsCopy to ClipboardFindConfigCopy to Clipboard<CartCopy to Clipboard>
totalsConfigCopy to ClipboardTotalsConfigCopy to Clipboard

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:268


retrieveWithTotals

retrieveWithTotals(cartIdCopy to Clipboard, options?Copy to Clipboard, totalsConfig?Copy to Clipboard): PromiseCopy to Clipboard<WithRequiredPropertyCopy to Clipboard<CartCopy to Clipboard, "total"Copy to Clipboard>>

Parameters

NameType
cartIdCopy to ClipboardstringCopy to Clipboard
optionsCopy to ClipboardFindConfigCopy to Clipboard<CartCopy to Clipboard>
totalsConfigCopy to ClipboardTotalsConfigCopy to Clipboard

Returns

PromiseCopy to Clipboard<WithRequiredPropertyCopy to Clipboard<CartCopy to Clipboard, "total"Copy to Clipboard>>

Defined in

packages/medusa/src/services/cart.ts:300


setMetadata

setMetadata(cartIdCopy to Clipboard, keyCopy to Clipboard, valueCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Dedicated method to set metadata for a cart. To ensure that plugins does not overwrite each others metadata fields, setMetadata is provided.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe cart to apply metadata to.
keyCopy to ClipboardstringCopy to Clipboardkey for metadata field
valueCopy to ClipboardstringCopy to Clipboard | numberCopy to Clipboardvalue for metadata field.

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

resolves to the updated result.

Defined in

packages/medusa/src/services/cart.ts:2435


setPaymentSession

setPaymentSession(cartIdCopy to Clipboard, providerIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Selects a payment session for a cart and creates a payment object in the external provider system

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to add payment method to
providerIdCopy to ClipboardstringCopy to Clipboardthe id of the provider to be set to the cart

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:1666


setPaymentSessions

setPaymentSessions(cartOrCartIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

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

NameTypeDescription
cartOrCartIdCopy to ClipboardstringCopy to Clipboard | CartCopy to Clipboardthe id of the cart to set payment session for

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the update operation.

Defined in

packages/medusa/src/services/cart.ts:1781


setRegion_

ProtectedCopy to Clipboard setRegion_(cartCopy to Clipboard, regionIdCopy to Clipboard, countryCodeCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Set's the region of a cart.

Parameters

NameTypeDescription
cartCopy to ClipboardCartCopy to Clipboardthe cart to set region on
regionIdCopy to ClipboardstringCopy to Clipboardthe id of the region to set the region to
countryCodeCopy to ClipboardnullCopy to Clipboard | stringCopy to Clipboardthe country code to set the country to

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:2258


shouldRetryTransaction_

ProtectedCopy to Clipboard shouldRetryTransaction_(errCopy to Clipboard): booleanCopy to Clipboard

Parameters

NameType
errCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard> | { codeCopy to Clipboard: stringCopy to Clipboard }

Returns

booleanCopy to Clipboard

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:31


transformQueryForTotals_

ProtectedCopy to Clipboard transformQueryForTotals_(configCopy to Clipboard): FindConfigCopy to Clipboard<CartCopy to Clipboard> & { totalsToSelectCopy to Clipboard: TotalFieldCopy to Clipboard[] }

Parameters

NameType
configCopy to ClipboardFindConfigCopy to Clipboard<CartCopy to Clipboard>

Returns

FindConfigCopy to Clipboard<CartCopy to Clipboard> & { totalsToSelectCopy to Clipboard: TotalFieldCopy to Clipboard[] }

Defined in

packages/medusa/src/services/cart.ts:2642


update

update(cartIdCopy to Clipboard, dataCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Parameters

NameType
cartIdCopy to ClipboardstringCopy to Clipboard
dataCopy to ClipboardCartUpdatePropsCopy to Clipboard

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:1035


updateBillingAddress_

ProtectedCopy to Clipboard updateBillingAddress_(cartCopy to Clipboard, addressOrIdCopy to Clipboard, addrRepoCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Updates the cart's billing address.

Parameters

NameTypeDescription
cartCopy to ClipboardCartCopy to Clipboardthe cart to update
addressOrIdCopy to ClipboardstringCopy to Clipboard | AddressPayloadCopy to Clipboard | PartialCopy to Clipboard<AddressCopy to Clipboard>the value to set the billing address to
addrRepoCopy to ClipboardAddressRepositoryCopy to Clipboardthe repository to use for address updates

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:1292


updateCustomerId_

ProtectedCopy to Clipboard updateCustomerId_(cartCopy to Clipboard, customerIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Sets the customer id of a cart

Parameters

NameTypeDescription
cartCopy to ClipboardCartCopy to Clipboardthe cart to add email to
customerIdCopy to ClipboardstringCopy to Clipboardthe customer to add to cart

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:1248


updateLineItem

updateLineItem(cartIdCopy to Clipboard, lineItemIdCopy to Clipboard, lineItemUpdateCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Updates a cart's existing line item.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to update
lineItemIdCopy to ClipboardstringCopy to Clipboardthe id of the line item to update.
lineItemUpdateCopy to ClipboardLineItemUpdateCopy to Clipboardthe line item to update. Must include an id field.

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:915


updatePaymentSession

updatePaymentSession(cartIdCopy to Clipboard, updateCopy to Clipboard): PromiseCopy to Clipboard<CartCopy to Clipboard>

Updates the currently selected payment session.

Parameters

NameTypeDescription
cartIdCopy to ClipboardstringCopy to Clipboardthe id of the cart to update the payment session for
updateCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>the data to update the payment session with

Returns

PromiseCopy to Clipboard<CartCopy to Clipboard>

the resulting cart

Defined in

packages/medusa/src/services/cart.ts:1554


updateShippingAddress_

ProtectedCopy to Clipboard updateShippingAddress_(cartCopy to Clipboard, addressOrIdCopy to Clipboard, addrRepoCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Updates the cart's shipping address.

Parameters

NameTypeDescription
cartCopy to ClipboardCartCopy to Clipboardthe cart to update
addressOrIdCopy to ClipboardstringCopy to Clipboard | AddressPayloadCopy to Clipboard | PartialCopy to Clipboard<AddressCopy to Clipboard>the value to set the shipping address to
addrRepoCopy to ClipboardAddressRepositoryCopy to Clipboardthe repository to use for address updates

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/cart.ts:1330


updateUnitPrices_

ProtectedCopy to Clipboard updateUnitPrices_(cartCopy to Clipboard, regionId?Copy to Clipboard, customer_id?Copy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Parameters

NameType
cartCopy to ClipboardCartCopy to Clipboard
regionId?Copy to ClipboardstringCopy to Clipboard
customer_id?Copy to ClipboardstringCopy to Clipboard

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/cart.ts:2194


validateLineItem

ProtectedCopy to Clipboard validateLineItem(sales_channel_idCopy to Clipboard, lineItemCopy to Clipboard): PromiseCopy to Clipboard<booleanCopy to Clipboard>

Check if line item's variant belongs to the cart's sales channel.

Parameters

NameTypeDescription
sales_channel_idCopy to ClipboardObjectCopy to Clipboardthe cart for the line item
sales_channel_id.sales_channel_idCopy to ClipboardnullCopy to Clipboard | stringCopy to Clipboard-
lineItemCopy to ClipboardLineItemValidateDataCopy to Clipboardthe line item being added

Returns

PromiseCopy to Clipboard<booleanCopy to Clipboard>

a boolean indicating validation result

Defined in

packages/medusa/src/services/cart.ts:585


validateLineItemShipping_

ProtectedCopy to Clipboard validateLineItemShipping_(shippingMethodsCopy to Clipboard, lineItemCopy to Clipboard): booleanCopy to Clipboard

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

NameTypeDescription
shippingMethodsCopy to ClipboardShippingMethodCopy to Clipboard[]the set of shipping methods to check from
lineItemCopy to ClipboardLineItemCopy to Clipboardthe line item

Returns

booleanCopy to Clipboard

boolean representing whether shipping method is validated

Defined in

packages/medusa/src/services/cart.ts:554


withTransaction

withTransaction(transactionManager?Copy to Clipboard): CartServiceCopy to Clipboard

Parameters

NameType
transactionManager?Copy to ClipboardEntityManagerCopy to Clipboard

Returns

CartServiceCopy to Clipboard

Inherited from

TransactionBaseService.withTransaction

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:14