CartService
Hierarchy
TransactionBaseService
↳
CartService
Constructors
constructor
new CartService(«destructured»
)
Parameters
Name |
---|
«destructured» |
Overrides
TransactionBaseService.constructor
Defined in
medusa/src/services/cart.ts:141
Properties
__configModule__
Protected
Optional
Readonly
__configModule__: Record<string
, unknown
>
Inherited from
TransactionBaseService.__configModule__
Defined in
medusa/src/interfaces/transaction-base-service.ts:14
__container__
Protected
Readonly
__container__: any
Inherited from
TransactionBaseService.__container__
Defined in
medusa/src/interfaces/transaction-base-service.ts:13
__moduleDeclaration__
Protected
Optional
Readonly
__moduleDeclaration__: Record<string
, unknown
>
Inherited from
TransactionBaseService.__moduleDeclaration__
Defined in
medusa/src/interfaces/transaction-base-service.ts:15
addressRepository_
Protected
Readonly
addressRepository_: Repository
<Address
>
Defined in
medusa/src/services/cart.ts:114
cartRepository_
Protected
Readonly
cartRepository_: Repository
<Cart
> & { findOneWithRelations
: Method findOneWithRelations ; findWithRelations
: Method findWithRelations }
Defined in
medusa/src/services/cart.ts:113
customShippingOptionService_
Protected
Readonly
customShippingOptionService_: CustomShippingOptionService
Defined in
medusa/src/services/cart.ts:133
customerService_
Protected
Readonly
customerService_: CustomerService
Defined in
medusa/src/services/cart.ts:125
discountService_
Protected
Readonly
discountService_: DiscountService
Defined in
medusa/src/services/cart.ts:128
eventBus_
Protected
Readonly
eventBus_: EventBusService
Defined in
medusa/src/services/cart.ts:117
featureFlagRouter_
Protected
Readonly
featureFlagRouter_: FlagRouter
Defined in
medusa/src/services/cart.ts:136
giftCardService_
Protected
Readonly
giftCardService_: GiftCardService
Defined in
medusa/src/services/cart.ts:129
lineItemAdjustmentService_
Protected
Readonly
lineItemAdjustmentService_: LineItemAdjustmentService
Defined in
medusa/src/services/cart.ts:135
lineItemRepository_
Protected
Readonly
lineItemRepository_: Repository
<LineItem
> & { findByReturn
: Method findByReturn }
Defined in
medusa/src/services/cart.ts:116
lineItemService_
Protected
Readonly
lineItemService_: LineItemService
Defined in
medusa/src/services/cart.ts:123
manager_
Protected
manager_: EntityManager
Inherited from
TransactionBaseService.manager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:5
newTotalsService_
Protected
Readonly
newTotalsService_: NewTotalsService
Defined in
medusa/src/services/cart.ts:132
paymentProviderService_
Protected
Readonly
paymentProviderService_: PaymentProviderService
Defined in
medusa/src/services/cart.ts:124
paymentSessionRepository_
Protected
Readonly
paymentSessionRepository_: Repository
<PaymentSession
>
Defined in
medusa/src/services/cart.ts:115
priceSelectionStrategy_
Protected
Readonly
priceSelectionStrategy_: IPriceSelectionStrategy
Defined in
medusa/src/services/cart.ts:134
pricingService_
Protected
Readonly
pricingService_: PricingService
Defined in
medusa/src/services/cart.ts:139
productService_
Protected
Readonly
productService_: ProductService
Defined in
medusa/src/services/cart.ts:119
productVariantInventoryService_
Protected
Readonly
productVariantInventoryService_: ProductVariantInventoryService
Defined in
medusa/src/services/cart.ts:138
productVariantService_
Protected
Readonly
productVariantService_: ProductVariantService
Defined in
medusa/src/services/cart.ts:118
regionService_
Protected
Readonly
regionService_: RegionService
Defined in
medusa/src/services/cart.ts:122
salesChannelService_
Protected
Readonly
salesChannelService_: SalesChannelService
Defined in
medusa/src/services/cart.ts:121
shippingMethodRepository_
Protected
Readonly
shippingMethodRepository_: Repository
<ShippingMethod
>
Defined in
medusa/src/services/cart.ts:112
shippingOptionService_
Protected
Readonly
shippingOptionService_: ShippingOptionService
Defined in
medusa/src/services/cart.ts:126
shippingProfileService_
Protected
Readonly
shippingProfileService_: ShippingProfileService
Defined in
medusa/src/services/cart.ts:127
storeService_
Protected
Readonly
storeService_: StoreService
Defined in
medusa/src/services/cart.ts:120
taxProviderService_
Protected
Readonly
taxProviderService_: TaxProviderService
Defined in
medusa/src/services/cart.ts:130
totalsService_
Protected
Readonly
totalsService_: TotalsService
Defined in
medusa/src/services/cart.ts:131
transactionManager_
Protected
transactionManager_: undefined
| EntityManager
Inherited from
TransactionBaseService.transactionManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:6
Events
Static
Readonly
Events: Object
Type declaration
Name | Type |
---|---|
CREATED | string |
CUSTOMER_UPDATED | string |
UPDATED | string |
Defined in
medusa/src/services/cart.ts:106
Accessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
-EntityManager
:
Inherited from
TransactionBaseService.activeManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:8
Methods
addLineItem
addLineItem(cartId
, lineItem
, config?
): Promise
<void
>
Adds a line item to the cart.
Parameters
Name | Default value | Description |
---|---|---|
cartId | string | the id of the cart that we will add to |
lineItem | LineItem | the line item to add. |
config | object | validateSalesChannels - should check if product belongs to the same sales channel as cart (if cart has associated sales channel) |
config.validateSalesChannels | boolean | true |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Deprecated
Use addOrUpdateLineItems instead.
Defined in
medusa/src/services/cart.ts:652
addOrUpdateLineItems
addOrUpdateLineItems(cartId
, lineItems
, config?
): Promise
<void
>
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
Name | Default value | Description |
---|---|---|
cartId | string | the id of the cart that we will add to |
lineItems | LineItem | LineItem [] | the line items to add. |
config | object | validateSalesChannels - should check if product belongs to the same sales channel as cart (if cart has associated sales channel) |
config.validateSalesChannels | boolean | true |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Defined in
medusa/src/services/cart.ts:792
addShippingMethod
addShippingMethod(cartOrId
, optionId
, data?
): Promise
<Cart
>
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
Name | Description |
---|---|
cartOrId | string | Cart |
optionId | string |
data | Record<string , unknown > |
Returns
Promise
<Cart
>
-Promise
: the result of the update operation
-Cart
:
Defined in
medusa/src/services/cart.ts:2177
adjustFreeShipping_
Protected
adjustFreeShipping_(cart
, shouldAdd
): Promise
<void
>
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
Name | Description |
---|---|
cart | Cart |
shouldAdd | boolean |
Returns
Promise
<void
>
-Promise
: void
Defined in
medusa/src/services/cart.ts:1111
applyDiscount
applyDiscount(cart
, discountCode
): Promise
<void
>
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
Name | Description |
---|---|
cart | Cart |
discountCode | string |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:1522
applyDiscounts
applyDiscounts(cart
, discountCodes
): Promise
<void
>
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
Name | Description |
---|---|
cart | Cart |
discountCodes | string [] |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:1534
applyGiftCard_
Protected
applyGiftCard_(cart
, code
): Promise
<void
>
Parameters
Name |
---|
cart |
code |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:1487
atomicPhase_
Protected
atomicPhase_<TResult
, TError
>(work
, isolationOrErrorHandler?
, maybeErrorHandlerOrDontFail?
): Promise
<TResult
>
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.
Name |
---|
TResult |
TError |
Parameters
Name | Description |
---|---|
work | (transactionManager : EntityManager ) => Promise <TResult > |
isolationOrErrorHandler? | IsolationLevel | (error : TError ) => Promise <void | TResult > |
maybeErrorHandlerOrDontFail? | (error : TError ) => Promise <void | TResult > |
Returns
Promise
<TResult
>
-Promise
: the result of the transactional work
Inherited from
TransactionBaseService.atomicPhase_
Defined in
medusa/src/interfaces/transaction-base-service.ts:56
authorizePayment
authorizePayment(cartId
, context?
): Promise
<Cart
>
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
Name | Description |
---|---|
cartId | string |
context | Record<string , unknown > & { cart_id : string } |
Returns
Promise
<Cart
>
-Promise
: the resulting cart
-Cart
:
Defined in
medusa/src/services/cart.ts:1701
create
create(data
): Promise
<Cart
>
Creates a cart.
Parameters
Name | Description |
---|---|
data | CartCreateProps |
Returns
Promise
<Cart
>
-Promise
: the result of the create operation
-Cart
:
Defined in
medusa/src/services/cart.ts:350
createOrFetchGuestCustomerFromEmail_
Protected
createOrFetchGuestCustomerFromEmail_(email
): Promise
<Customer
>
Creates or fetches a user based on an email.
Parameters
Name | Description |
---|---|
email | string |
Returns
Promise
<Customer
>
-Promise
: the resultign customer object
-Customer
:
Defined in
medusa/src/services/cart.ts:1373
createTaxLines
createTaxLines(cartOrId
): Promise
<void
>
Parameters
Name |
---|
cartOrId |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:2628
decorateTotals
decorateTotals(cart
, totalsConfig?
): Promise
<WithRequiredProperty
<Cart
, "total"
>>
Parameters
Name |
---|
cart |
totalsConfig |
Returns
Promise
<WithRequiredProperty
<Cart
, "total"
>>
-Promise
:
-WithRequiredProperty
:
-Cart
:
-"total"
: (optional)
Defined in
medusa/src/services/cart.ts:2680
decorateTotals_
Protected
decorateTotals_(cart
, totalsToSelect
, options?
): Promise
<Cart
>
Parameters
Name |
---|
cart |
totalsToSelect |
options |
Returns
Promise
<Cart
>
-Promise
:
-Cart
:
Deprecated
Use decorateTotals instead
Defined in
medusa/src/services/cart.ts:2863
delete
delete(cartId
): Promise
<Cart
>
Deletes a cart from the database. Completed carts cannot be deleted.
Parameters
Name | Description |
---|---|
cartId | string |
Returns
Promise
<Cart
>
-Promise
: the deleted cart or undefined if the cart was not found.
-Cart
:
Defined in
medusa/src/services/cart.ts:2547
deletePaymentSession
deletePaymentSession(cartId
, providerId
): Promise
<void
>
Removes a payment session from the cart.
Parameters
Name | Description |
---|---|
cartId | string |
providerId | string |
Returns
Promise
<void
>
-Promise
: the resulting cart.
Defined in
medusa/src/services/cart.ts:2070
deleteTaxLines
deleteTaxLines(id
): Promise
<void
>
Parameters
Name |
---|
id |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:2660
findCustomShippingOption
findCustomShippingOption(cartCustomShippingOptions
, optionId
): undefined
| CustomShippingOption
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
Name | Description |
---|---|
cartCustomShippingOptions | CustomShippingOption [] |
optionId | string |
Returns
undefined
| CustomShippingOption
-undefined \| CustomShippingOption
: (optional) custom shipping option
Defined in
medusa/src/services/cart.ts:2310
getTotalsRelations
Private
getTotalsRelations(config
): string
[]
Parameters
Name |
---|
config |
Returns
string
[]
-string[]
:
-string
: (optional)
Defined in
medusa/src/services/cart.ts:2914
getValidatedSalesChannel
Protected
getValidatedSalesChannel(salesChannelId?
): Promise
<SalesChannel
>
Parameters
Name |
---|
salesChannelId? |
Returns
Promise
<SalesChannel
>
-Promise
:
-SalesChannel
:
Defined in
medusa/src/services/cart.ts:488
list
list(selector
, config?
): Promise
<Cart
[]>
Parameters
Name | Description |
---|---|
selector | FilterableCartProps |
config | FindConfig <Cart > |
Returns
Promise
<Cart
[]>
-Promise
: the result of the find operation
-Cart[]
:
-Cart
:
Defined in
medusa/src/services/cart.ts:207
onSalesChannelChange
Protected
onSalesChannelChange(cart
, newSalesChannelId
): Promise
<void
>
Remove the cart line item that does not belongs to the newly assigned sales channel
Parameters
Name | Description |
---|---|
cart | Cart |
newSalesChannelId | string |
Returns
Promise
<void
>
-Promise
: void
Defined in
medusa/src/services/cart.ts:1319
refreshAdjustments_
Protected
refreshAdjustments_(cart
): Promise
<void
>
Parameters
Name |
---|
cart |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:2787
refreshPaymentSession
refreshPaymentSession(cartId
, providerId
): Promise
<void
>
Refreshes a payment session on a cart
Parameters
Name | Description |
---|---|
cartId | string |
providerId | string |
Returns
Promise
<void
>
-Promise
: the resulting cart.
Defined in
medusa/src/services/cart.ts:2122
removeDiscount
removeDiscount(cartId
, discountCode
): Promise
<Cart
>
Removes a discount based on a discount code.
Parameters
Name | Description |
---|---|
cartId | string |
discountCode | string |
Returns
Promise
<Cart
>
-Promise
: the resulting cart
-Cart
:
Defined in
medusa/src/services/cart.ts:1612
removeLineItem
removeLineItem(cartId
, lineItemId
): Promise
<Cart
>
Removes a line item from the cart.
Parameters
Name | Description |
---|---|
cartId | string |
lineItemId | string |
Returns
Promise
<Cart
>
-Promise
: the result of the update operation
-Cart
:
Defined in
medusa/src/services/cart.ts:520
retrieve
retrieve(cartId
, options?
, totalsConfig?
): Promise
<Cart
>
Gets a cart by id.
Parameters
Name | Description |
---|---|
cartId | string |
options | FindConfig <Cart > |
totalsConfig | TotalsConfig |
Returns
Promise
<Cart
>
-Promise
: the cart document.
-Cart
:
Defined in
medusa/src/services/cart.ts:224
retrieveLegacy
Protected
retrieveLegacy(cartId
, options?
, totalsConfig?
): Promise
<Cart
>
Parameters
Name |
---|
cartId |
options |
totalsConfig |
Returns
Promise
<Cart
>
-Promise
:
-Cart
:
Deprecated
Defined in
medusa/src/services/cart.ts:287
retrieveWithTotals
retrieveWithTotals(cartId
, options?
, totalsConfig?
): Promise
<WithRequiredProperty
<Cart
, "total"
>>
Parameters
Name |
---|
cartId |
options |
totalsConfig |
Returns
Promise
<WithRequiredProperty
<Cart
, "total"
>>
-Promise
:
-WithRequiredProperty
:
-Cart
:
-"total"
: (optional)
Defined in
medusa/src/services/cart.ts:315
setMetadata
setMetadata(cartId
, key
, value
): Promise
<Cart
>
Dedicated method to set metadata for a cart. To ensure that plugins does not overwrite each others metadata fields, setMetadata is provided.
Parameters
Name | Description |
---|---|
cartId | string |
key | string |
value | string | number |
Returns
Promise
<Cart
>
-Promise
: resolves to the updated result.
-Cart
:
Defined in
medusa/src/services/cart.ts:2588
setPaymentSession
setPaymentSession(cartId
, providerId
): Promise
<void
>
Selects a payment session for a cart and creates a payment object in the external provider system
Parameters
Name | Description |
---|---|
cartId | string |
providerId | string |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:1775
setPaymentSessions
setPaymentSessions(cartOrCartId
): Promise
<void
>
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
Name | Description |
---|---|
cartOrCartId | string | Cart |
Returns
Promise
<void
>
-Promise
: the result of the update operation.
Defined in
medusa/src/services/cart.ts:1891
setRegion_
Protected
setRegion_(cart
, regionId
, countryCode
): Promise
<void
>
Set's the region of a cart.
Parameters
Name | Description |
---|---|
cart | Cart |
regionId | string |
countryCode | null | string |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Defined in
medusa/src/services/cart.ts:2408
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
Name |
---|
err |
Returns
boolean
-boolean
: (optional)
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
medusa/src/interfaces/transaction-base-service.ts:37
transformQueryForTotals_
Protected
transformQueryForTotals_(config
): FindConfig
<Cart
> & { totalsToSelect
: TotalField
[] }
Parameters
Name |
---|
config |
Returns
FindConfig
<Cart
> & { totalsToSelect
: TotalField
[] }
-`FindConfig
<Cart
> & { totalsToSelect
: TotalField
[] }`: (optional)
Defined in
medusa/src/services/cart.ts:2805
update
update(cartOrId
, data
): Promise
<Cart
>
Parameters
Name |
---|
cartOrId |
data |
Returns
Promise
<Cart
>
-Promise
:
-Cart
:
Defined in
medusa/src/services/cart.ts:1152
updateBillingAddress_
Protected
updateBillingAddress_(cart
, addressOrId
, addrRepo
): Promise
<void
>
Updates the cart's billing address.
Parameters
Name | Description |
---|---|
cart | Cart |
addressOrId | string | AddressPayload | Partial <Address > |
addrRepo | Repository <Address > |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Defined in
medusa/src/services/cart.ts:1400
updateCustomerId_
Protected
updateCustomerId_(cart
, customerId
): Promise
<void
>
Sets the customer id of a cart
Parameters
Name | Description |
---|---|
cart | Cart |
customerId | string |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Defined in
medusa/src/services/cart.ts:1355
updateLineItem
updateLineItem(cartId
, lineItemId
, update
): Promise
<Cart
>
Updates a cart's existing line item.
Parameters
Name | Description |
---|---|
cartId | string |
lineItemId | string |
update | LineItemUpdate |
Returns
Promise
<Cart
>
-Promise
: the result of the update operation
-Cart
:
Defined in
medusa/src/services/cart.ts:999
updatePaymentSession
updatePaymentSession(cartId
, update
): Promise
<Cart
>
Updates the currently selected payment session.
Parameters
Name | Description |
---|---|
cartId | string |
update | Record<string , unknown > |
Returns
Promise
<Cart
>
-Promise
: the resulting cart
-Cart
:
Defined in
medusa/src/services/cart.ts:1663
updateShippingAddress_
Protected
updateShippingAddress_(cart
, addressOrId
, addrRepo
): Promise
<void
>
Updates the cart's shipping address.
Parameters
Name | Description |
---|---|
cart | Cart |
addressOrId | string | AddressPayload | Partial <Address > |
addrRepo | Repository <Address > |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Defined in
medusa/src/services/cart.ts:1438
updateUnitPrices_
Protected
updateUnitPrices_(cart
, regionId?
, customer_id?
): Promise
<void
>
Parameters
Name |
---|
cart |
regionId? |
customer_id? |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/cart.ts:2329
validateLineItem
Protected
validateLineItem(sales_channel_id
, lineItem
): Promise
<boolean
>
Check if line item's variant belongs to the cart's sales channel.
Parameters
Name | Description |
---|---|
sales_channel_id | object |
sales_channel_id.sales_channel_id | null | string |
lineItem | LineItemValidateData |
Returns
Promise
<boolean
>
-Promise
: a boolean indicating validation result
-boolean
: (optional)
Defined in
medusa/src/services/cart.ts:618
validateLineItemShipping_
Protected
validateLineItemShipping_(shippingMethods
, lineItemShippingProfiledId
): boolean
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
Name | Description |
---|---|
shippingMethods | ShippingMethod [] |
lineItemShippingProfiledId | string |
Returns
boolean
-boolean
: (optional) boolean representing whether shipping method is validated
Defined in
medusa/src/services/cart.ts:589
withTransaction
withTransaction(transactionManager?
): CartService
Parameters
Name |
---|
transactionManager? |
Returns
-CartService
:
Inherited from
TransactionBaseService.withTransaction