Skip to main content

OrderModifier

OrderModifier

This helper is responsible for modifying the contents of an Order.

Note: There is not a clear separation of concerns between the OrderService and this, since the OrderService also contains some method which modify the Order (e.g. removeItemFromOrder). So this helper was mainly extracted to isolate the huge modifyOrder method since the OrderService was just growing too large. Future refactoring could improve the organization of these Order-related methods into a more clearly-delineated set of classes.

Signature
class OrderModifier {
constructor(connection: TransactionalConnection, configService: ConfigService, orderCalculator: OrderCalculator, paymentService: PaymentService, countryService: CountryService, stockMovementService: StockMovementService, productVariantService: ProductVariantService, customFieldRelationService: CustomFieldRelationService, promotionService: PromotionService, eventBus: EventBus, entityHydrator: EntityHydrator, historyService: HistoryService, translator: TranslatorService)
constrainQuantityToSaleable(ctx: RequestContext, variant: ProductVariant, quantity: number, existingQuantity: = 0) => ;
getExistingOrderLine(ctx: RequestContext, order: Order, productVariantId: ID, customFields?: { [key: string]: any }) => Promise<OrderLine | undefined>;
getOrCreateOrderLine(ctx: RequestContext, order: Order, productVariantId: ID, customFields?: { [key: string]: any }) => ;
updateOrderLineQuantity(ctx: RequestContext, orderLine: OrderLine, quantity: number, order: Order) => Promise<OrderLine>;
cancelOrderByOrderLines(ctx: RequestContext, input: CancelOrderInput, lineInputs: OrderLineInput[]) => ;
modifyOrder(ctx: RequestContext, input: ModifyOrderInput, order: Order) => Promise<JustErrorResults<ModifyOrderResult> | { order: Order; modification: OrderModification }>;
}

constructor

method
(connection: TransactionalConnection, configService: ConfigService, orderCalculator: OrderCalculator, paymentService: PaymentService, countryService: CountryService, stockMovementService: StockMovementService, productVariantService: ProductVariantService, customFieldRelationService: CustomFieldRelationService, promotionService: PromotionService, eventBus: EventBus, entityHydrator: EntityHydrator, historyService: HistoryService, translator: TranslatorService) => OrderModifier

constrainQuantityToSaleable

method
(ctx: RequestContext, variant: ProductVariant, quantity: number, existingQuantity: = 0) =>

Ensure that the ProductVariant has sufficient saleable stock to add the given quantity to an Order.

getExistingOrderLine

method
(ctx: RequestContext, order: Order, productVariantId: ID, customFields?: { [key: string]: any }) => Promise<OrderLine | undefined>

Given a ProductVariant ID and optional custom fields, this method will return an existing OrderLine that matches, or undefined if no match is found.

getOrCreateOrderLine

method
(ctx: RequestContext, order: Order, productVariantId: ID, customFields?: { [key: string]: any }) =>

Returns the OrderLine containing the given ProductVariant, taking into account any custom field values. If no existing OrderLine is found, a new OrderLine will be created.

updateOrderLineQuantity

method
(ctx: RequestContext, orderLine: OrderLine, quantity: number, order: Order) => Promise<OrderLine>

Updates the quantity of an OrderLine, taking into account the available saleable stock level. Returns the actual quantity that the OrderLine was updated to (which may be less than the quantity argument if insufficient stock was available.

cancelOrderByOrderLines

method
(ctx: RequestContext, input: CancelOrderInput, lineInputs: OrderLineInput[]) =>

modifyOrder

method
(ctx: RequestContext, input: ModifyOrderInput, order: Order) => Promise<JustErrorResults<ModifyOrderResult> | { order: Order; modification: OrderModification }>