This also includes rework of the currency model for the Store module. This change is breaking as existing stores won't have any supported currencies set, so users would need to go to the store settings again and choose the supported currencies there.
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { createDefaultsWorkflow } from "@medusajs/core-flows"
|
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
import {
|
|
IRegionModuleService,
|
|
IStoreModuleService,
|
|
MedusaContainer,
|
|
} from "@medusajs/types"
|
|
|
|
export const seedStorefrontDefaults = async (
|
|
container: MedusaContainer,
|
|
defaultCurrency: string = "usd"
|
|
) => {
|
|
const regionModule: IRegionModuleService = container.resolve(
|
|
ModuleRegistrationName.REGION
|
|
)
|
|
const storeModule: IStoreModuleService = container.resolve(
|
|
ModuleRegistrationName.STORE
|
|
)
|
|
|
|
// Creates the stores & default sales channel
|
|
await createDefaultsWorkflow(container).run()
|
|
|
|
const region = await regionModule.createRegions({
|
|
name: "Default Region",
|
|
currency_code: defaultCurrency,
|
|
})
|
|
|
|
let [store] = await storeModule.listStores({})
|
|
|
|
store = await storeModule.updateStores(store.id, {
|
|
default_region_id: region.id,
|
|
supported_currencies: [
|
|
{ currency_code: region.currency_code, is_default: true },
|
|
],
|
|
})
|
|
|
|
return {
|
|
region,
|
|
store,
|
|
}
|
|
}
|