-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathgenerate_delivery_run.liquid
89 lines (85 loc) · 2.49 KB
/
generate_delivery_run.liquid
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{%- if flavor contains "vanilla-js" -%}
// @ts-check
import { DeliveryDiscountSelectionStrategy} from '../generated/api';
/**
* @typedef {import("../generated/api").DeliveryInput} RunInput
* @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult
*/
/**
* generateDeliveryRun
* @param {RunInput} input - The DeliveryInput
* @returns {CartDeliveryOptionsDiscountsGenerateRunResult} - The function result with discounts.
*/
export function generateDeliveryRun(input) {
const firstDeliveryGroup = input.cart.deliveryGroups[0];
if (!firstDeliveryGroup) {
throw new Error('No delivery groups found');
}
return {
operations: [
{
deliveryDiscountsAdd: {
candidates: [
{
message: 'FREE DELIVERY',
targets: [
{
deliveryGroup: {
id: firstDeliveryGroup.id,
},
},
],
value: {
percentage: {
value: 100,
},
},
},
],
selectionStrategy: DeliveryDiscountSelectionStrategy.All,
},
},
],
};
}
{%- elsif flavor contains "typescript" -%}
import {
DeliveryDiscountSelectionStrategy,
DeliveryInput,
CartDeliveryOptionsDiscountsGenerateRunResult,
} from '../generated/api';
export function generateDeliveryRun(
input: DeliveryInput,
): CartDeliveryOptionsDiscountsGenerateRunResult {
const firstDeliveryGroup = input.cart.deliveryGroups[0];
if (!firstDeliveryGroup) {
throw new Error('No delivery groups found');
}
return {
operations: [
{
deliveryDiscountsAdd: {
candidates: [
{
message: 'FREE DELIVERY',
targets: [
{
deliveryGroup: {
id: firstDeliveryGroup.id,
},
},
],
value: {
percentage: {
value: 100,
},
},
},
],
selectionStrategy: DeliveryDiscountSelectionStrategy.All,
},
},
],
};
}
{%- endif -%}