|
1
|
import { AbstractFulfillmentProviderService } from "@medusajs/framework/utils" |
|
2
|
|
|
3
|
export class ManualFulfillmentService extends AbstractFulfillmentProviderService { |
|
4
|
static identifier = "manual-calculated" |
|
5
|
|
|
6
|
constructor() { |
|
7
|
super() |
|
8
|
} |
|
9
|
|
|
10
|
async getFulfillmentOptions() { |
|
11
|
return [ |
|
12
|
{ |
|
13
|
id: "manual-fulfillment-calculated", |
|
14
|
}, |
|
15
|
{ |
|
16
|
id: "manual-fulfillment-return-calculated", |
|
17
|
is_return: true, |
|
18
|
}, |
|
19
|
] |
|
20
|
} |
|
21
|
|
|
22
|
async validateFulfillmentData(optionData, data, context) { |
|
23
|
return data |
|
24
|
} |
|
25
|
|
|
26
|
async calculatePrice(optionData, data, context) { |
|
27
|
if (context.exchange_id) { |
|
28
|
return { |
|
29
|
calculated_amount: |
|
30
|
context.exchange_items.reduce((acc, i) => acc + i.quantity, 0) * 2.5, // mock return cost as 2 per item |
|
31
|
is_calculated_price_tax_inclusive: false, |
|
32
|
} |
|
33
|
} |
|
34
|
if (context.claim_id) { |
|
35
|
return { |
|
36
|
calculated_amount: |
|
37
|
context.claim_items.reduce((acc, i) => acc + i.quantity, 0) * 2.5, // mock return cost as 2 per item |
|
38
|
is_calculated_price_tax_inclusive: false, |
|
39
|
} |
|
40
|
} |
|
41
|
|
|
42
|
if (context.return_id) { |
|
43
|
return { |
|
44
|
calculated_amount: |
|
45
|
context.return_items.reduce((acc, i) => acc + i.quantity, 0) * 2, // mock return cost as 2 per item |
|
46
|
is_calculated_price_tax_inclusive: false, |
|
47
|
} |
|
48
|
} |
|
49
|
|
|
50
|
return { |
|
51
|
calculated_amount: |
|
52
|
context.items.reduce((acc, i) => acc + i.quantity, 0) * 1.5, // mock caluclation as 1.5 per item |
|
53
|
is_calculated_price_tax_inclusive: false, |
|
54
|
} |
|
55
|
} |
|
56
|
|
|
57
|
async canCalculate() { |
|
58
|
return true |
|
59
|
} |
|
60
|
|
|
61
|
async validateOption(data) { |
|
62
|
return true |
|
63
|
} |
|
64
|
|
|
65
|
async createFulfillment() { |
|
66
|
// No data is being sent anywhere |
|
67
|
return { |
|
68
|
data: {}, |
|
69
|
labels: [], |
|
70
|
} |
|
71
|
} |
|
72
|
|
|
73
|
async cancelFulfillment() { |
|
74
|
return {} |
|
75
|
} |
|
76
|
|
|
77
|
async createReturnFulfillment() { |
|
78
|
return { data: {}, labels: [] } |
|
79
|
} |
|
80
|
} |