Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
27 KiB
displayed_sidebar
| displayed_sidebar |
|---|
| jsClientSidebar |
Class: OrderService
internal.internal.OrderService
Hierarchy
-
↳
OrderService
Properties
__configModule__
• Protected Optional Readonly __configModule__: Record<string, unknown>
Inherited from
TransactionBaseService.configModule
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:5
__container__
• Protected Readonly __container__: any
Inherited from
TransactionBaseService.container
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:4
__moduleDeclaration__
• Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>
Inherited from
TransactionBaseService.moduleDeclaration
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:6
addressRepository_
• Protected Readonly addressRepository_: Repository<Address>
Defined in
packages/medusa/dist/services/order.d.ts:72
cartService_
• Protected Readonly cartService_: CartService
Defined in
packages/medusa/dist/services/order.d.ts:71
customerService_
• Protected Readonly customerService_: CustomerService
Defined in
packages/medusa/dist/services/order.d.ts:59
discountService_
• Protected Readonly discountService_: DiscountService
Defined in
packages/medusa/dist/services/order.d.ts:63
draftOrderService_
• Protected Readonly draftOrderService_: DraftOrderService
Defined in
packages/medusa/dist/services/order.d.ts:74
eventBus_
• Protected Readonly eventBus_: EventBusService
Defined in
packages/medusa/dist/services/order.d.ts:76
featureFlagRouter_
• Protected Readonly featureFlagRouter_: FlagRouter
Defined in
packages/medusa/dist/services/order.d.ts:77
fulfillmentProviderService_
• Protected Readonly fulfillmentProviderService_: FulfillmentProviderService
Defined in
packages/medusa/dist/services/order.d.ts:64
fulfillmentService_
• Protected Readonly fulfillmentService_: FulfillmentService
Defined in
packages/medusa/dist/services/order.d.ts:65
getTotalsRelations
• Private getTotalsRelations: any
Defined in
packages/medusa/dist/services/order.d.ts:266
giftCardService_
• Protected Readonly giftCardService_: GiftCardService
Defined in
packages/medusa/dist/services/order.d.ts:73
inventoryService_
• Protected Readonly inventoryService_: IInventoryService
Defined in
packages/medusa/dist/services/order.d.ts:75
lineItemService_
• Protected Readonly lineItemService_: LineItemService
Defined in
packages/medusa/dist/services/order.d.ts:66
manager_
• Protected manager_: EntityManager
Inherited from
TransactionBaseService.manager_
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:7
newTotalsService_
• Protected Readonly newTotalsService_: NewTotalsService
Defined in
packages/medusa/dist/services/order.d.ts:68
orderRepository_
• Protected Readonly orderRepository_: Repository<Order> & { findOneWithRelations: (relations?: FindOptionsRelations<Order>, optionsWithoutRelations?: Omit<FindManyOptions<Order>, "relations">) => Promise<Order> ; findWithRelations: (relations?: FindOptionsRelations<Order>, optionsWithoutRelations?: Omit<FindManyOptions<Order>, "relations">) => Promise<Order[]> }
Defined in
packages/medusa/dist/services/order.d.ts:58
paymentProviderService_
• Protected Readonly paymentProviderService_: PaymentProviderService
Defined in
packages/medusa/dist/services/order.d.ts:60
productVariantInventoryService_
• Protected Readonly productVariantInventoryService_: ProductVariantInventoryService
Defined in
packages/medusa/dist/services/order.d.ts:78
regionService_
• Protected Readonly regionService_: RegionService
Defined in
packages/medusa/dist/services/order.d.ts:70
shippingOptionService_
• Protected Readonly shippingOptionService_: ShippingOptionService
Defined in
packages/medusa/dist/services/order.d.ts:61
shippingProfileService_
• Protected Readonly shippingProfileService_: ShippingProfileService
Defined in
packages/medusa/dist/services/order.d.ts:62
taxProviderService_
• Protected Readonly taxProviderService_: TaxProviderService
Defined in
packages/medusa/dist/services/order.d.ts:69
totalsService_
• Protected Readonly totalsService_: TotalsService
Defined in
packages/medusa/dist/services/order.d.ts:67
transactionManager_
• Protected transactionManager_: undefined | EntityManager
Inherited from
TransactionBaseService.transactionManager_
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:8
Events
▪ Static Readonly Events: Object
Type declaration
| Name | Type |
|---|---|
CANCELED |
string |
COMPLETED |
string |
FULFILLMENT_CANCELED |
string |
FULFILLMENT_CREATED |
string |
GIFT_CARD_CREATED |
string |
ITEMS_RETURNED |
string |
PAYMENT_CAPTURED |
string |
PAYMENT_CAPTURE_FAILED |
string |
PLACED |
string |
REFUND_CREATED |
string |
REFUND_FAILED |
string |
RETURN_ACTION_REQUIRED |
string |
RETURN_REQUESTED |
string |
SHIPMENT_CREATED |
string |
SWAP_CREATED |
string |
UPDATED |
string |
Defined in
packages/medusa/dist/services/order.d.ts:40
Accessors
activeManager_
• Protected get activeManager_(): EntityManager
Returns
EntityManager
Inherited from
TransactionBaseService.activeManager_
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:9
Methods
addShippingMethod
▸ addShippingMethod(orderId, optionId, data?, config?): Promise<Order>
Parameters
| Name | Type |
|---|---|
orderId |
string |
optionId |
string |
data? |
Record<string, unknown> |
config? |
CreateShippingMethodDto |
Returns
Promise<Order>
Defined in
packages/medusa/dist/services/order.d.ts:161
archive
▸ archive(orderId): Promise<Order>
Archives an order. It only alloved, if the order has been fulfilled and payment has been captured.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
the order to archive |
Returns
Promise<Order>
the result of the update operation
Defined in
packages/medusa/dist/services/order.d.ts:236
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.
Type parameters
| Name |
|---|
TResult |
TError |
Parameters
| Name | Type | Description |
|---|---|---|
work |
(transactionManager: EntityManager) => Promise<TResult> |
the transactional work to be done |
isolationOrErrorHandler? |
IsolationLevel | (error: TError) => Promise<void | TResult> |
the isolation level to be used for the work. |
maybeErrorHandlerOrDontFail? |
(error: TError) => Promise<void | TResult> |
Potential error handler |
Returns
Promise<TResult>
the result of the transactional work
Inherited from
TransactionBaseService.atomicPhase_
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:24
cancel
▸ cancel(orderId): Promise<Order>
Cancels an order. Throws if fulfillment process has been initiated. Throws if payment process has been initiated.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
id of order to cancel. |
Returns
Promise<Order>
result of the update operation.
Defined in
packages/medusa/dist/services/order.d.ts:179
cancelFulfillment
▸ cancelFulfillment(fulfillmentId): Promise<Order>
Cancels a fulfillment (if related to an order)
Parameters
| Name | Type | Description |
|---|---|---|
fulfillmentId |
string |
the ID of the fulfillment to cancel |
Returns
Promise<Order>
updated order
Defined in
packages/medusa/dist/services/order.d.ts:218
capturePayment
▸ capturePayment(orderId): Promise<Order>
Captures payment for an order.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
id of order to capture payment for. |
Returns
Promise<Order>
result of the update operation.
Defined in
packages/medusa/dist/services/order.d.ts:185
completeOrder
▸ completeOrder(orderId): Promise<Order>
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
id of the order to complete |
Returns
Promise<Order>
the result of the find operation
Defined in
packages/medusa/dist/services/order.d.ts:125
createFromCart
▸ createFromCart(cartOrId): Promise<Order>
Creates an order from a cart
Parameters
| Name | Type |
|---|---|
cartOrId |
string | Cart |
Returns
Promise<Order>
resolves to the creation result.
Defined in
packages/medusa/dist/services/order.d.ts:131
createFulfillment
▸ createFulfillment(orderId, itemsToFulfill, config?): Promise<Order>
Creates fulfillments for an order. In a situation where the order has more than one shipping method, we need to partition the order items, such that they can be sent to their respective fulfillment provider.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
id of order to fulfil. |
itemsToFulfill |
FulFillmentItemType[] |
items to fulfil. |
config? |
Object |
the config to fulfil. |
config.location_id? |
string |
- |
config.metadata? |
Record<string, unknown> |
- |
config.no_notification? |
boolean |
- |
Returns
Promise<Order>
result of the update operation.
Defined in
packages/medusa/dist/services/order.d.ts:208
createGiftCardsFromLineItem_
▸ Protected createGiftCardsFromLineItem_(order, lineItem, manager): Promise<GiftCard>[]
Parameters
| Name | Type |
|---|---|
order |
Order |
lineItem |
LineItem |
manager |
EntityManager |
Returns
Promise<GiftCard>[]
Defined in
packages/medusa/dist/services/order.d.ts:132
createRefund
▸ createRefund(orderId, refundAmount, reason, note?, config?): Promise<Order>
Refunds a given amount back to the customer.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
id of the order to refund. |
refundAmount |
number |
the amount to refund. |
reason |
string |
the reason to refund. |
note? |
string |
note for refund. |
config? |
Object |
the config for refund. |
config.no_notification? |
boolean |
- |
Returns
Promise<Order>
the result of the refund operation.
Defined in
packages/medusa/dist/services/order.d.ts:246
createShipment
▸ createShipment(orderId, fulfillmentId, trackingLinks?, config?): Promise<Order>
Adds a shipment to the order to indicate that an order has left the warehouse. Will ask the fulfillment provider for any documents that may have been created in regards to the shipment.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
the id of the order that has been shipped |
fulfillmentId |
string |
the fulfillment that has now been shipped |
trackingLinks? |
TrackingLink[] |
array of tracking numbers associated with the shipment |
config? |
Object |
the config of the order that has been shipped |
config.metadata |
Record<string, unknown> |
- |
config.no_notification? |
boolean |
- |
Returns
Promise<Order>
the resulting order following the update.
Defined in
packages/medusa/dist/services/order.d.ts:143
decorateTotals
▸ decorateTotals(order, totalsFields?): Promise<Order>
Parameters
| Name | Type |
|---|---|
order |
Order |
totalsFields? |
string[] |
Returns
Promise<Order>
Defined in
packages/medusa/dist/services/order.d.ts:250
▸ decorateTotals(order, context?): Promise<Order>
Parameters
| Name | Type |
|---|---|
order |
Order |
context? |
TotalsContext |
Returns
Promise<Order>
Defined in
packages/medusa/dist/services/order.d.ts:251
decorateTotalsLegacy
▸ Protected decorateTotalsLegacy(order, totalsFields?): Promise<Order>
Parameters
| Name | Type |
|---|---|
order |
Order |
totalsFields? |
string[] |
Returns
Promise<Order>
Defined in
packages/medusa/dist/services/order.d.ts:249
getFulfillmentItems
▸ Protected getFulfillmentItems(order, items, transformer): Promise<LineItem[]>
Retrieves the order line items, given an array of items.
Parameters
| Name | Type | Description |
|---|---|---|
order |
Order |
the order to get line items from |
items |
FulFillmentItemType[] |
the items to get |
transformer |
(item: undefined | LineItem, quantity: number) => unknown |
a function to apply to each of the items retrieved from the order, should return a line item. If the transformer returns an undefined value the line item will be filtered from the returned array. |
Returns
Promise<LineItem[]>
the line items generated by the transformer.
Defined in
packages/medusa/dist/services/order.d.ts:229
list
▸ list(selector, config?): Promise<Order[]>
Parameters
| Name | Type | Description |
|---|---|---|
selector |
Selector<Order> |
the query object for find |
config? |
FindConfig<Order> |
the config to be used for find |
Returns
Promise<Order[]>
the result of the find operation
Defined in
packages/medusa/dist/services/order.d.ts:85
listAndCount
▸ listAndCount(selector, config?): Promise<[Order[], number]>
Parameters
| Name | Type | Description |
|---|---|---|
selector |
QuerySelector<Order> |
the query object for find |
config? |
FindConfig<Order> |
the config to be used for find |
Returns
Promise<[Order[], number]>
the result of the find operation
Defined in
packages/medusa/dist/services/order.d.ts:91
registerReturnReceived
▸ registerReturnReceived(orderId, receivedReturn, customRefundAmount?): Promise<Order>
Handles receiving a return. This will create a refund to the customer. If the returned items don't match the requested items the return status will be updated to requires_action. This behaviour is useful in situations where a custom refund amount is requested, but the returned items are not matching the requested items. Setting the allowMismatch argument to true, will process the return, ignoring any mismatches.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
the order to return. |
receivedReturn |
Return |
the received return |
customRefundAmount? |
number |
the custom refund amount return |
Returns
Promise<Order>
the result of the update operation
Defined in
packages/medusa/dist/services/order.d.ts:265
retrieve
▸ retrieve(orderId, config?): Promise<Order>
Gets an order by id.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
id or selector of order to retrieve |
config? |
FindConfig<Order> |
config of order to retrieve |
Returns
Promise<Order>
the order document
Defined in
packages/medusa/dist/services/order.d.ts:103
retrieveByCartId
▸ retrieveByCartId(cartId, config?): Promise<Order>
Gets an order by cart id.
Parameters
| Name | Type | Description |
|---|---|---|
cartId |
string |
cart id to find order |
config? |
FindConfig<Order> |
the config to be used to find order |
Returns
Promise<Order>
the order document
Defined in
packages/medusa/dist/services/order.d.ts:112
retrieveByCartIdWithTotals
▸ retrieveByCartIdWithTotals(cartId, options?): Promise<Order>
Parameters
| Name | Type |
|---|---|
cartId |
string |
options? |
FindConfig<Order> |
Returns
Promise<Order>
Defined in
packages/medusa/dist/services/order.d.ts:113
retrieveByExternalId
▸ retrieveByExternalId(externalId, config?): Promise<Order>
Gets an order by id.
Parameters
| Name | Type | Description |
|---|---|---|
externalId |
string |
id of order to retrieve |
config? |
FindConfig<Order> |
query config to get order by |
Returns
Promise<Order>
the order document
Defined in
packages/medusa/dist/services/order.d.ts:120
retrieveLegacy
▸ Protected retrieveLegacy(orderIdOrSelector, config?): Promise<Order>
Parameters
| Name | Type |
|---|---|
orderIdOrSelector |
string | Selector<Order> |
config? |
FindConfig<Order> |
Returns
Promise<Order>
Defined in
packages/medusa/dist/services/order.d.ts:104
retrieveWithTotals
▸ retrieveWithTotals(orderId, options?, context?): Promise<Order>
Parameters
| Name | Type |
|---|---|
orderId |
string |
options? |
FindConfig<Order> |
context? |
TotalsContext |
Returns
Promise<Order>
Defined in
packages/medusa/dist/services/order.d.ts:105
shouldRetryTransaction_
▸ Protected shouldRetryTransaction_(err): boolean
Parameters
| Name | Type |
|---|---|
err |
Record<string, unknown> | { code: string } |
Returns
boolean
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:12
transformQueryForTotals
▸ Protected transformQueryForTotals(config): Object
Parameters
| Name | Type |
|---|---|
config |
FindConfig<Order> |
Returns
Object
| Name | Type |
|---|---|
relations |
undefined | string[] |
select |
undefined | keyof Order[] |
totalsToSelect |
undefined | keyof Order[] |
Defined in
packages/medusa/dist/services/order.d.ts:92
update
▸ update(orderId, update): Promise<Order>
Updates an order. Metadata updates should
use dedicated method, e.g. setMetadata etc. The function
will throw errors if metadata updates are attempted.
Parameters
| Name | Type | Description |
|---|---|---|
orderId |
string |
the id of the order. Must be a string that can be casted to an ObjectId |
update |
UpdateOrderInput |
an object with the update values. |
Returns
Promise<Order>
resolves to the update result.
Defined in
packages/medusa/dist/services/order.d.ts:171
updateBillingAddress
▸ Protected updateBillingAddress(order, address): Promise<void>
Updates the order's billing address.
Parameters
| Name | Type | Description |
|---|---|---|
order |
Order |
the order to update |
address |
Address |
the value to set the billing address to |
Returns
Promise<void>
the result of the update operation
Defined in
packages/medusa/dist/services/order.d.ts:153
updateShippingAddress
▸ Protected updateShippingAddress(order, address): Promise<void>
Updates the order's shipping address.
Parameters
| Name | Type | Description |
|---|---|---|
order |
Order |
the order to update |
address |
Address |
the value to set the shipping address to |
Returns
Promise<void>
the result of the update operation
Defined in
packages/medusa/dist/services/order.d.ts:160
validateFulfillmentLineItem
▸ Protected validateFulfillmentLineItem(item, quantity): null | LineItem
Checks that a given quantity of a line item can be fulfilled. Fails if the fulfillable quantity is lower than the requested fulfillment quantity. Fulfillable quantity is calculated by subtracting the already fulfilled quantity from the quantity that was originally purchased.
Parameters
| Name | Type | Description |
|---|---|---|
item |
LineItem |
the line item to check has sufficient fulfillable quantity. |
quantity |
number |
the quantity that is requested to be fulfilled. |
Returns
null | LineItem
a line item that has the requested fulfillment quantity set.
Defined in
packages/medusa/dist/services/order.d.ts:197
withTransaction
▸ withTransaction(transactionManager?): OrderService
Parameters
| Name | Type |
|---|---|
transactionManager? |
EntityManager |
Returns
Inherited from
TransactionBaseService.withTransaction
Defined in
packages/medusa/dist/interfaces/transaction-base-service.d.ts:11