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 // mock caluclation as 1.5 per item, converted with a per-currency rate to
28 // assert the currency is part of the context in every calculation path
29 const rate = context.currency_code === "dkk" ? 2 : 1
30 // set by the `setCalculatedShippingPricingContext` workflow hook and merged
31 // into `context`, so tests can assert the additional context reaches the provider
32 const multiplier = context.price_multiplier ?? 1
33
34 return {
35 calculated_amount:
36 context.items.reduce((acc, i) => acc + i.quantity, 0) *
37 1.5 *
38 rate *
39 multiplier,
40 is_calculated_price_tax_inclusive: false,
41 }
42 }
43
44 async canCalculate() {
45 return true
46 }
47
48 async validateOption(data) {
49 return true
50 }
51
52 async createFulfillment() {
53 // No data is being sent anywhere
54 return {
55 data: {},
56 labels: [],
57 }
58 }
59
60 async cancelFulfillment() {
61 return {}
62 }
63
64 async createReturnFulfillment() {
65 return { data: {}, labels: [] }
66 }
67 }