|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
|
|
3
|
export function getUniqueShippingProfiles( |
|
4
|
items: HttpTypes.AdminOrderLineItem[] |
|
5
|
): HttpTypes.AdminShippingProfile[] { |
|
6
|
const profiles = new Map<string, HttpTypes.AdminShippingProfile>() |
|
7
|
items.forEach((item) => { |
|
8
|
const profile = item.variant?.product?.shipping_profile |
|
9
|
if (profile) { |
|
10
|
profiles.set(profile.id, profile) |
|
11
|
} |
|
12
|
}) |
|
13
|
return Array.from(profiles.values()) |
|
14
|
} |
|
15
|
|
|
16
|
export function getItemsWithShippingProfile( |
|
17
|
shipping_profile_id: string, |
|
18
|
items: HttpTypes.AdminOrderLineItem[] |
|
19
|
) { |
|
20
|
return items.filter( |
|
21
|
(item) => |
|
22
|
item.variant?.product?.shipping_profile?.id === shipping_profile_id |
|
23
|
) |
|
24
|
} |
|
25
|
|
|
26
|
export function getOrderCustomer(obj: HttpTypes.AdminOrder) { |
|
27
|
const { first_name: sFirstName, last_name: sLastName } = |
|
28
|
obj.shipping_address || {} |
|
29
|
const { first_name: bFirstName, last_name: bLastName } = |
|
30
|
obj.billing_address || {} |
|
31
|
const { first_name: cFirstName, last_name: cLastName } = obj.customer || {} |
|
32
|
|
|
33
|
const customerName = [cFirstName, cLastName].filter(Boolean).join(" ") |
|
34
|
const shippingName = [sFirstName, sLastName].filter(Boolean).join(" ") |
|
35
|
const billingName = [bFirstName, bLastName].filter(Boolean).join(" ") |
|
36
|
|
|
37
|
const name = customerName || shippingName || billingName |
|
38
|
|
|
39
|
return name |
|
40
|
} |