|
1
|
import { createDefaultsWorkflow } from "@medusajs/core-flows" |
|
2
|
import { |
|
3
|
IRegionModuleService, |
|
4
|
IStoreModuleService, |
|
5
|
MedusaContainer, |
|
6
|
} from "@medusajs/framework/types" |
|
7
|
import { Modules } from "@medusajs/framework/utils" |
|
8
|
|
|
9
|
import { linkRegionPaymentProviders } from "./link-region-payment-providers" |
|
10
|
|
|
11
|
export const seedStorefrontDefaults = async ( |
|
12
|
container: MedusaContainer, |
|
13
|
defaultCurrency: string = "usd" |
|
14
|
) => { |
|
15
|
const regionModule: IRegionModuleService = container.resolve(Modules.REGION) |
|
16
|
const storeModule: IStoreModuleService = container.resolve(Modules.STORE) |
|
17
|
|
|
18
|
// Creates the stores & default sales channel |
|
19
|
await createDefaultsWorkflow(container).run() |
|
20
|
|
|
21
|
const region = await regionModule.createRegions({ |
|
22
|
name: "Default Region", |
|
23
|
currency_code: defaultCurrency, |
|
24
|
}) |
|
25
|
|
|
26
|
await linkRegionPaymentProviders(container, region.id) |
|
27
|
|
|
28
|
let [store] = await storeModule.listStores({}) |
|
29
|
|
|
30
|
store = await storeModule.updateStores(store.id, { |
|
31
|
default_region_id: region.id, |
|
32
|
supported_currencies: [ |
|
33
|
{ currency_code: region.currency_code, is_default: true }, |
|
34
|
], |
|
35
|
}) |
|
36
|
|
|
37
|
return { |
|
38
|
region, |
|
39
|
store, |
|
40
|
} |
|
41
|
} |