-
-
Notifications
You must be signed in to change notification settings - Fork 932
/
shipping-line-assignment-strategy.ts
58 lines (58 loc) · 2.07 KB
/
shipping-line-assignment-strategy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { RequestContext } from '../../api/common/request-context';
import { InjectableStrategy } from '../../common/types/injectable-strategy';
import { Order } from '../../entity/order/order.entity';
import { OrderLine } from '../../entity/order-line/order-line.entity';
import { ShippingLine } from '../../entity/shipping-line/shipping-line.entity';
/**
* @description
* This strategy is used to assign a given {@link ShippingLine} to one or more {@link OrderLine}s of the Order.
* This allows you to set multiple shipping methods for a single order, each assigned a different subset of
* OrderLines.
*
* The {@link DefaultShippingLineAssignmentStrategy} simply assigns _all_ OrderLines, so is suitable for the
* most common scenario of a single shipping method per Order.
*
* :::info
*
* This is configured via the `shippingOptions.shippingLineAssignmentStrategy` property of
* your VendureConfig.
*
* :::
*
* Here's an example of a custom ShippingLineAssignmentStrategy which assigns digital products to a
* different ShippingLine to physical products:
*
* ```ts
* import {
* Order,
* OrderLine,
* RequestContext,
* ShippingLine,
* ShippingLineAssignmentStrategy,
* } from '\@vendure/core';
*
* export class DigitalShippingLineAssignmentStrategy implements ShippingLineAssignmentStrategy {
* assignShippingLineToOrderLines(
* ctx: RequestContext,
* shippingLine: ShippingLine,
* order: Order,
* ): OrderLine[] | Promise<OrderLine[]> {
* if (shippingLine.shippingMethod.customFields.isDigital) {
* return order.lines.filter(l => l.productVariant.customFields.isDigital);
* } else {
* return order.lines.filter(l => !l.productVariant.customFields.isDigital);
* }
* }
* }
* ```
*
* @since 2.0.0
* @docsCategory shipping
*/
export interface ShippingLineAssignmentStrategy extends InjectableStrategy {
assignShippingLineToOrderLines(
ctx: RequestContext,
shippingLine: ShippingLine,
order: Order,
): OrderLine[] | Promise<OrderLine[]>;
}