|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
|
|
3
|
export function isReturnOption(shippingOption: HttpTypes.AdminShippingOption) { |
|
4
|
return !!shippingOption.rules?.find( |
|
5
|
(r) => |
|
6
|
r.attribute === "is_return" && r.value === "true" && r.operator === "eq" |
|
7
|
) |
|
8
|
} |
|
9
|
|
|
10
|
export function isOptionEnabledInStore( |
|
11
|
shippingOption: HttpTypes.AdminShippingOption |
|
12
|
) { |
|
13
|
return !!shippingOption.rules?.find( |
|
14
|
(r) => |
|
15
|
r.attribute === "enabled_in_store" && |
|
16
|
r.value === "true" && |
|
17
|
r.operator === "eq" |
|
18
|
) |
|
19
|
} |
|
20
|
|
|
21
|
/** |
|
22
|
* Return a name for the shipping option location or generate one based on the locations address |
|
23
|
*/ |
|
24
|
export function getFormattedShippingOptionLocationName( |
|
25
|
shippingOption: HttpTypes.AdminShippingOption |
|
26
|
) { |
|
27
|
const location = shippingOption.service_zone.fulfillment_set.location |
|
28
|
|
|
29
|
if (!location) { |
|
30
|
return "N/A" |
|
31
|
} |
|
32
|
|
|
33
|
if (location.name) { |
|
34
|
return `${location.name}` |
|
35
|
} |
|
36
|
|
|
37
|
let name = "" |
|
38
|
|
|
39
|
if (location.address) { |
|
40
|
if (location.address.address_1) { |
|
41
|
name += `${location.address.address_1}` |
|
42
|
} |
|
43
|
|
|
44
|
if (location.address.address_2) { |
|
45
|
name += `${location.address.address_2}` |
|
46
|
} |
|
47
|
|
|
48
|
if (location.address.city) { |
|
49
|
name += `${location.address.city}` |
|
50
|
} |
|
51
|
|
|
52
|
if (location.address.postal_code) { |
|
53
|
name += `${location.address.postal_code}` |
|
54
|
} |
|
55
|
|
|
56
|
if (location.address.country_code) { |
|
57
|
name += `, ${location.address.country_code}` |
|
58
|
} |
|
59
|
} |
|
60
|
|
|
61
|
return name || "N/A" |
|
62
|
} |