**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { MedusaContainer, Modules } from "@medusajs/modules-sdk"
|
|
import {
|
|
CreatePriceSetDTO,
|
|
IPricingModuleService,
|
|
PriceSetDTO,
|
|
} from "@medusajs/types"
|
|
|
|
const defaultPrices = [
|
|
{
|
|
amount: 3000,
|
|
currency_code: "usd",
|
|
},
|
|
]
|
|
|
|
const defaultPriceSetRules = [{ rule_attribute: "region_id" }]
|
|
|
|
export const createVariantPriceSet = async ({
|
|
container,
|
|
variantId,
|
|
prices = defaultPrices,
|
|
rules = defaultPriceSetRules,
|
|
}: {
|
|
container: MedusaContainer
|
|
variantId: string
|
|
prices?: CreatePriceSetDTO["prices"]
|
|
rules?: CreatePriceSetDTO["rules"]
|
|
}): Promise<PriceSetDTO> => {
|
|
const remoteLink = container.resolve("remoteLink")
|
|
const pricingModuleService: IPricingModuleService = container.resolve(
|
|
"pricingModuleService"
|
|
)
|
|
|
|
const priceSet = await pricingModuleService.createPriceSets({
|
|
rules,
|
|
prices,
|
|
})
|
|
|
|
await remoteLink.create({
|
|
[Modules.PRODUCT]: { variant_id: variantId },
|
|
[Modules.PRICING]: { price_set_id: priceSet.id },
|
|
})
|
|
|
|
return await pricingModuleService.retrievePriceSet(priceSet.id, {
|
|
relations: ["prices"],
|
|
})
|
|
}
|