OrderService
OrderService
Contains methods relating to Order entities.
class OrderService {
constructor(connection: TransactionalConnection, configService: ConfigService, productVariantService: ProductVariantService, customerService: CustomerService, countryService: CountryService, orderCalculator: OrderCalculator, shippingCalculator: ShippingCalculator, orderStateMachine: OrderStateMachine, orderMerger: OrderMerger, paymentService: PaymentService, paymentMethodService: PaymentMethodService, fulfillmentService: FulfillmentService, listQueryBuilder: ListQueryBuilder, refundStateMachine: RefundStateMachine, historyService: HistoryService, promotionService: PromotionService, eventBus: EventBus, channelService: ChannelService, orderModifier: OrderModifier, customFieldRelationService: CustomFieldRelationService, requestCache: RequestContextCacheService, translator: TranslatorService, stockLevelService: StockLevelService)
getOrderProcessStates() => OrderProcessState[];
findAll(ctx: RequestContext, options?: OrderListOptions, relations?: RelationPaths<Order>) => Promise<PaginatedList<Order>>;
findOne(ctx: RequestContext, orderId: ID, relations?: RelationPaths<Order>) => Promise<Order | undefined>;
findOneByCode(ctx: RequestContext, orderCode: string, relations?: RelationPaths<Order>) => Promise<Order | undefined>;
findOneByOrderLineId(ctx: RequestContext, orderLineId: ID, relations?: RelationPaths<Order>) => Promise<Order | undefined>;
findByCustomerId(ctx: RequestContext, customerId: ID, options?: ListQueryOptions<Order>, relations?: RelationPaths<Order>) => Promise<PaginatedList<Order>>;
getOrderPayments(ctx: RequestContext, orderId: ID) => Promise<Payment[]>;
getOrderModifications(ctx: RequestContext, orderId: ID) => Promise<OrderModification[]>;
getPaymentRefunds(ctx: RequestContext, paymentId: ID) => Promise<Refund[]>;
getSellerOrders(ctx: RequestContext, order: Order) => Promise<Order[]>;
getAggregateOrder(ctx: RequestContext, order: Order) => Promise<Order | undefined>;
getOrderChannels(ctx: RequestContext, order: Order) => Promise<Channel[]>;
getActiveOrderForUser(ctx: RequestContext, userId: ID) => Promise<Order | undefined>;
create(ctx: RequestContext, userId?: ID) => Promise<Order>;
createDraft(ctx: RequestContext) => ;
updateCustomFields(ctx: RequestContext, orderId: ID, customFields: any) => ;
updateOrderCustomer(ctx: RequestContext, { customerId, orderId, note }: SetOrderCustomerInput) => ;
addItemToOrder(ctx: RequestContext, orderId: ID, productVariantId: ID, quantity: number, customFields?: { [key: string]: any }, relations?: RelationPaths<Order>) => Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>>;
addItemsToOrder(ctx: RequestContext, orderId: ID, items: Array<{
productVariantId: ID;
quantity: number;
customFields?: { [key: string]: any };
}>, relations?: RelationPaths<Order>) => Promise<{ order: Order; errorResults: Array<JustErrorResults<UpdateOrderItemsResult>> }>;
adjustOrderLine(ctx: RequestContext, orderId: ID, orderLineId: ID, quantity: number, customFields?: { [key: string]: any }, relations?: RelationPaths<Order>) => Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>>;
adjustOrderLines(ctx: RequestContext, orderId: ID, lines: Array<{ orderLineId: ID; quantity: number; customFields?: { [key: string]: any } }>, relations?: RelationPaths<Order>) => Promise<{ order: Order; errorResults: Array<JustErrorResults<UpdateOrderItemsResult>> }>;
removeItemFromOrder(ctx: RequestContext, orderId: ID, orderLineId: ID) => Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>>;
removeItemsFromOrder(ctx: RequestContext, orderId: ID, orderLineIds: ID[]) => Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>>;
removeAllItemsFromOrder(ctx: RequestContext, orderId: ID) => Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>>;
addSurchargeToOrder(ctx: RequestContext, orderId: ID, surchargeInput: Partial<Omit<Surcharge, 'id' | 'createdAt' | 'updatedAt' | 'order'>>) => Promise<Order>;
removeSurchargeFromOrder(ctx: RequestContext, orderId: ID, surchargeId: ID) => Promise<Order>;
applyCouponCode(ctx: RequestContext, orderId: ID, couponCode: string) => Promise<ErrorResultUnion<ApplyCouponCodeResult, Order>>;
removeCouponCode(ctx: RequestContext, orderId: ID, couponCode: string) => ;
getOrderPromotions(ctx: RequestContext, orderId: ID) => Promise<Promotion[]>;
getNextOrderStates(order: Order) => readonly OrderState[];
setShippingAddress(ctx: RequestContext, orderId: ID, input: CreateAddressInput) => Promise<Order>;
setBillingAddress(ctx: RequestContext, orderId: ID, input: CreateAddressInput) => Promise<Order>;
unsetShippingAddress(ctx: RequestContext, orderId: ID) => Promise<Order>;
unsetBillingAddress(ctx: RequestContext, orderId: ID) => Promise<Order>;
getEligibleShippingMethods(ctx: RequestContext, orderId: ID) => Promise<ShippingMethodQuote[]>;
getEligiblePaymentMethods(ctx: RequestContext, orderId: ID) => Promise<PaymentMethodQuote[]>;
setShippingMethod(ctx: RequestContext, orderId: ID, shippingMethodIds: ID[]) => Promise<ErrorResultUnion<SetOrderShippingMethodResult, Order>>;
transitionToState(ctx: RequestContext, orderId: ID, state: OrderState) => Promise<Order | OrderStateTransitionError>;
transitionFulfillmentToState(ctx: RequestContext, fulfillmentId: ID, state: FulfillmentState) => Promise<Fulfillment | FulfillmentStateTransitionError>;
transitionRefundToState(ctx: RequestContext, refundId: ID, state: RefundState, transactionId?: string) => Promise<Refund | RefundStateTransitionError>;
modifyOrder(ctx: RequestContext, input: ModifyOrderInput) => Promise<ErrorResultUnion<ModifyOrderResult, Order>>;
transitionPaymentToState(ctx: RequestContext, paymentId: ID, state: PaymentState) => Promise<ErrorResultUnion<TransitionPaymentToStateResult, Payment>>;
addPaymentToOrder(ctx: RequestContext, orderId: ID, input: PaymentInput) => Promise<ErrorResultUnion<AddPaymentToOrderResult, Order>>;
addManualPaymentToOrder(ctx: RequestContext, input: ManualPaymentInput) => Promise<ErrorResultUnion<AddManualPaymentToOrderResult, Order>>;
settlePayment(ctx: RequestContext, paymentId: ID) => Promise<ErrorResultUnion<SettlePaymentResult, Payment>>;
cancelPayment(ctx: RequestContext, paymentId: ID) => Promise<ErrorResultUnion<CancelPaymentResult, Payment>>;
createFulfillment(ctx: RequestContext, input: FulfillOrderInput) => Promise<ErrorResultUnion<AddFulfillmentToOrderResult, Fulfillment>>;
getOrderFulfillments(ctx: RequestContext, order: Order) => Promise<Fulfillment[]>;
getOrderSurcharges(ctx: RequestContext, orderId: ID) => Promise<Surcharge[]>;
cancelOrder(ctx: RequestContext, input: CancelOrderInput) => Promise<ErrorResultUnion<CancelOrderResult, Order>>;
refundOrder(ctx: RequestContext, input: RefundOrderInput) => Promise<ErrorResultUnion<RefundOrderResult, Refund>>;
settleRefund(ctx: RequestContext, input: SettleRefundInput) => Promise<Refund>;
addCustomerToOrder(ctx: RequestContext, orderIdOrOrder: ID | Order, customer: Customer) => Promise<Order>;
addNoteToOrder(ctx: RequestContext, input: AddNoteToOrderInput) => Promise<Order>;
updateOrderNote(ctx: RequestContext, input: UpdateOrderNoteInput) => Promise<HistoryEntry>;
deleteOrderNote(ctx: RequestContext, id: ID) => Promise<DeletionResponse>;
deleteOrder(ctx: RequestContext, orderOrId: ID | Order) => ;
mergeOrders(ctx: RequestContext, user: User, guestOrder?: Order, existingOrder?: Order) => Promise<Order | undefined>;
applyPriceAdjustments(ctx: RequestContext, order: Order, updatedOrderLines?: OrderLine[], relations?: RelationPaths<Order>) => Promise<Order>;
}
constructor
(connection: TransactionalConnection, configService: ConfigService, productVariantService: ProductVariantService, customerService: CustomerService, countryService: CountryService, orderCalculator: OrderCalculator, shippingCalculator: ShippingCalculator, orderStateMachine: OrderStateMachine, orderMerger: OrderMerger, paymentService: PaymentService, paymentMethodService: PaymentMethodService, fulfillmentService: FulfillmentService, listQueryBuilder: ListQueryBuilder, refundStateMachine: RefundStateMachine, historyService: HistoryService, promotionService: PromotionService, eventBus: EventBus, channelService: ChannelService, orderModifier: OrderModifier, customFieldRelationService: CustomFieldRelationService, requestCache: RequestContextCacheService, translator: TranslatorService, stockLevelService: StockLevelService) => OrderService
getOrderProcessStates
() => OrderProcessState[]
Returns an array of all the configured states and transitions of the order process. This is
based on the default order process plus all configured OrderProcess objects
defined in the OrderOptions process
array.
findAll
(ctx: RequestContext, options?: OrderListOptions, relations?: RelationPaths<Order>) => Promise<PaginatedList<Order>>
findOne
(ctx: RequestContext, orderId: ID, relations?: RelationPaths<Order>) => Promise<Order | undefined>
findOneByCode
(ctx: RequestContext, orderCode: string, relations?: RelationPaths<Order>) => Promise<Order | undefined>
findOneByOrderLineId
(ctx: RequestContext, orderLineId: ID, relations?: RelationPaths<Order>) => Promise<Order | undefined>
findByCustomerId
(ctx: RequestContext, customerId: ID, options?: ListQueryOptions<Order>, relations?: RelationPaths<Order>) => Promise<PaginatedList<Order>>
getOrderPayments
(ctx: RequestContext, orderId: ID) => Promise<Payment[]>
Returns all Payment entities associated with the Order.
getOrderModifications
(ctx: RequestContext, orderId: ID) => Promise<OrderModification[]>
Returns an array of any OrderModification entities associated with the Order.
getPaymentRefunds
(ctx: RequestContext, paymentId: ID) => Promise<Refund[]>
Returns any Refunds associated with a Payment.
getSellerOrders
(ctx: RequestContext, order: Order) => Promise<Order[]>
getAggregateOrder
(ctx: RequestContext, order: Order) => Promise<Order | undefined>
getOrderChannels
(ctx: RequestContext, order: Order) => Promise<Channel[]>
getActiveOrderForUser
(ctx: RequestContext, userId: ID) => Promise<Order | undefined>
Returns any Order associated with the specified User's Customer account
that is still in the active
state.
create
(ctx: RequestContext, userId?: ID) => Promise<Order>
Creates a new, empty Order. If a userId
is passed, the Order will get associated with that
User's Customer account.
createDraft
(ctx: RequestContext) =>
updateCustomFields
(ctx: RequestContext, orderId: ID, customFields: any) =>
Updates the custom fields of an Order.
updateOrderCustomer
Updates the Customer which is assigned to a given Order. The target Customer must be assigned to the same Channels as the Order, otherwise an error will be thrown.
addItemToOrder
(ctx: RequestContext, orderId: ID, productVariantId: ID, quantity: number, customFields?: { [key: string]: any }, relations?: RelationPaths<Order>) => Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>>
Adds an item to the Order, either creating a new OrderLine or incrementing an existing one.
If you need to add multiple items to an Order, use addItemsToOrder()
instead.
addItemsToOrder
(ctx: RequestContext, orderId: ID, items: Array<{ productVariantId: ID; quantity: number; customFields?: { [key: string]: any }; }>, relations?: RelationPaths<Order>) => Promise<{ order: Order; errorResults: Array<JustErrorResults<UpdateOrderItemsResult>> }>
Adds multiple items to an Order. This method is more efficient than calling addItemToOrder
multiple times, as it only needs to fetch the entire Order once, and only performs
price adjustments once at the end.
Since this method can return multiple error results, it is recommended to check the errorResults
array to determine if any errors occurred.
adjustOrderLine
(ctx: RequestContext, orderId: ID, orderLineId: ID, quantity: number, customFields?: { [key: string]: any }, relations?: RelationPaths<Order>) => Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>>
Adjusts the quantity and/or custom field values of an existing OrderLine.
If you need to adjust multiple OrderLines, use adjustOrderLines()
instead.
adjustOrderLines
(ctx: RequestContext, orderId: ID, lines: Array<{ orderLineId: ID; quantity: number; customFields?: { [key: string]: any } }>, relations?: RelationPaths<Order>) => Promise<{ order: Order; errorResults: Array<JustErrorResults<UpdateOrderItemsResult>> }>
Adjusts the quantity and/or custom field values of existing OrderLines.
This method is more efficient than calling adjustOrderLine
multiple times, as it only needs to fetch
the entire Order once, and only performs price adjustments once at the end.
Since this method can return multiple error results, it is recommended to check the errorResults
array to determine if any errors occurred.
removeItemFromOrder
(ctx: RequestContext, orderId: ID, orderLineId: ID) => Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>>
Removes the specified OrderLine from the Order.
If you need to remove multiple OrderLines, use removeItemsFromOrder()
instead.