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)
async constrainQuantityToSaleable(ctx: RequestContext, variant: ProductVariant, quantity: number, existingQuantity: = 0) => ;
async getExistingOrderLine(ctx: RequestContext, order: Order, productVariantId: ID, customFields?: { [key: string]: any }) => Promise<OrderLine | undefined>;
async getOrCreateOrderLine(ctx: RequestContext, order: Order, productVariantId: ID, customFields?: { [key: string]: any }) => ;
async updateOrderLineQuantity(ctx: RequestContext, orderLine: OrderLine, quantity: number, order: Order) => Promise<OrderLine>;
async cancelOrderByOrderLines(ctx: RequestContext, input: CancelOrderInput, lineInputs: OrderLineInput[]) => ;
async modifyOrder(ctx: RequestContext, input: ModifyOrderInput, order: Order) => Promise<JustErrorResults<ModifyOrderResult> | { order: Order; modification: OrderModification }>;
}
Members
constructor
method
type:
(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
type:
(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
type:
(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
type:
(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
type:
(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
type:
(ctx: RequestContext, input: CancelOrderInput, lineInputs: OrderLineInput[]) =>
modifyOrder
method
type:
(ctx: RequestContext, input: ModifyOrderInput, order: Order) => Promise<JustErrorResults<ModifyOrderResult> | { order: Order; modification: OrderModification }>