feat(core-flows,medusa,types,utils): rename psma to prices (#6796)
What: Renames pricesetmoneyamount to prices Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
parent
fbc369705d
commit
9073d7aba3
@@ -14,9 +14,7 @@ export function buildPriceListResponse(
|
||||
): AdminPriceListRemoteQueryDTO[] {
|
||||
for (const priceList of priceLists) {
|
||||
priceList.rules = buildPriceListRules(priceList.price_list_rules || [])
|
||||
priceList.prices = buildPriceSetPricesForCore(
|
||||
priceList.price_set_money_amounts || []
|
||||
)
|
||||
priceList.prices = buildPriceSetPricesForCore(priceList.prices || [])
|
||||
}
|
||||
|
||||
return priceLists.map((priceList) => cleanResponseData(priceList, apiFields))
|
||||
|
||||
@@ -13,17 +13,17 @@ export const adminPriceListRemoteQueryFields = [
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"price_set_money_amounts.id",
|
||||
"price_set_money_amounts.currency_code",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.min_quantity",
|
||||
"price_set_money_amounts.max_quantity",
|
||||
"price_set_money_amounts.created_at",
|
||||
"price_set_money_amounts.deleted_at",
|
||||
"price_set_money_amounts.updated_at",
|
||||
"price_set_money_amounts.price_set.variant.id",
|
||||
"price_set_money_amounts.price_rules.value",
|
||||
"price_set_money_amounts.price_rules.rule_type.rule_attribute",
|
||||
"prices.id",
|
||||
"prices.currency_code",
|
||||
"prices.amount",
|
||||
"prices.min_quantity",
|
||||
"prices.max_quantity",
|
||||
"prices.created_at",
|
||||
"prices.deleted_at",
|
||||
"prices.updated_at",
|
||||
"prices.price_set.variant.id",
|
||||
"prices.price_rules.value",
|
||||
"prices.price_rules.rule_type.rule_attribute",
|
||||
"price_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
]
|
||||
@@ -50,7 +50,6 @@ export const defaultAdminPriceListFields = [
|
||||
]
|
||||
|
||||
export const defaultAdminPriceListRelations = []
|
||||
|
||||
export const allowedAdminPriceListRelations = [PriceListRelations.PRICES]
|
||||
|
||||
export const adminListTransformQueryConfig = {
|
||||
|
||||
@@ -15,10 +15,7 @@ export const remapKeysForProduct = (selectFields: string[]) => {
|
||||
const pricingFields = selectFields
|
||||
.filter((fieldName: string) => isPricing(fieldName))
|
||||
.map((fieldName: string) =>
|
||||
fieldName.replace(
|
||||
"variants.prices.",
|
||||
"variants.price_set.price_set_money_amounts."
|
||||
)
|
||||
fieldName.replace("variants.prices.", "variants.price_set.prices.")
|
||||
)
|
||||
|
||||
return [...productFields, ...pricingFields]
|
||||
@@ -31,7 +28,7 @@ export const remapKeysForVariant = (selectFields: string[]) => {
|
||||
const pricingFields = selectFields
|
||||
.filter((fieldName: string) => isPricing(fieldName))
|
||||
.map((fieldName: string) =>
|
||||
fieldName.replace("prices.", "price_set.price_set_money_amounts.")
|
||||
fieldName.replace("prices.", "price_set.prices.")
|
||||
)
|
||||
|
||||
return [...variantFields, ...pricingFields]
|
||||
@@ -47,8 +44,8 @@ export const remapProduct = (p: ProductDTO) => {
|
||||
export const remapVariant = (v: ProductVariantDTO) => {
|
||||
return {
|
||||
...v,
|
||||
prices: (v as any).price_set?.price_set_money_amounts?.map((psma) => ({
|
||||
...psma,
|
||||
prices: (v as any).price_set?.prices?.map((price) => ({
|
||||
...price,
|
||||
variant_id: v.id,
|
||||
})),
|
||||
price_set: undefined,
|
||||
|
||||
@@ -19,7 +19,7 @@ export function maybeApplyPriceListsFilter() {
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "price_list",
|
||||
fields: ["price_set_money_amounts.price_set.variant.id"],
|
||||
fields: ["prices.price_set.variant.id"],
|
||||
variables: {
|
||||
id: priceListIds,
|
||||
},
|
||||
@@ -33,8 +33,9 @@ export function maybeApplyPriceListsFilter() {
|
||||
const priceLists = await remoteQuery(queryObject)
|
||||
|
||||
priceLists.forEach((priceList) => {
|
||||
priceList.price_set_money_amounts?.forEach((psma) => {
|
||||
const variantId = psma.price_set?.variant?.id
|
||||
priceList.prices?.forEach((price) => {
|
||||
const variantId = price.price_set?.variant?.id
|
||||
|
||||
if (variantId) {
|
||||
variantIds.push(variantId)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import middlewares, {
|
||||
import {
|
||||
defaultAdminProductFields,
|
||||
defaultAdminProductRelations,
|
||||
defaultAdminProductRemoteQueryObject,
|
||||
} from "../products"
|
||||
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
@@ -87,56 +86,6 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
||||
return app
|
||||
}
|
||||
|
||||
export const defaultAdminPriceListRemoteQueryObject = {
|
||||
fields: [
|
||||
"created_at",
|
||||
"deleted_at",
|
||||
"description",
|
||||
"ends_at",
|
||||
"id",
|
||||
"title",
|
||||
"starts_at",
|
||||
"status",
|
||||
"type",
|
||||
"updated_at",
|
||||
],
|
||||
price_list_rules: {
|
||||
price_list_rule_values: {
|
||||
fields: ["value"],
|
||||
},
|
||||
rule_type: {
|
||||
fields: ["rule_attribute"],
|
||||
},
|
||||
},
|
||||
price_set_money_amounts: {
|
||||
money_amount: {
|
||||
fields: [
|
||||
"id",
|
||||
"currency_code",
|
||||
"amount",
|
||||
"min_quantity",
|
||||
"max_quantity",
|
||||
"created_at",
|
||||
"deleted_at",
|
||||
"updated_at",
|
||||
],
|
||||
},
|
||||
price_rules: {
|
||||
fields: ["value"],
|
||||
rule_type: {
|
||||
fields: ["rule_attribute"],
|
||||
},
|
||||
},
|
||||
price_set: {
|
||||
variant_link: {
|
||||
variant: {
|
||||
fields: defaultAdminProductRemoteQueryObject.variants.fields,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const defaultAdminPriceListFields = [
|
||||
"id",
|
||||
"name",
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { MedusaContainer } from "@medusajs/types"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { PriceList } from "../../../../../models"
|
||||
import { listAndCountPriceListPricingModule } from "./list-and-count-price-lists"
|
||||
|
||||
export async function getPriceListPricingModule(
|
||||
id: string,
|
||||
{
|
||||
container,
|
||||
}: {
|
||||
container: MedusaContainer
|
||||
}
|
||||
): Promise<PriceList> {
|
||||
const [priceLists, count] = await listAndCountPriceListPricingModule({
|
||||
filters: { id: [id] },
|
||||
container,
|
||||
})
|
||||
|
||||
if (count === 0) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`Price list with id: ${id} was not found`
|
||||
)
|
||||
}
|
||||
|
||||
return priceLists[0]
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./get-price-list"
|
||||
export * from "./list-and-count-price-lists"
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
import { LinkModuleUtils, ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { FilterablePriceListProps, MedusaContainer } from "@medusajs/types"
|
||||
import { CustomerGroup, MoneyAmount, PriceList } from "../../../../../models"
|
||||
import { FindConfig } from "../../../../../types/common"
|
||||
import { defaultAdminPriceListRemoteQueryObject } from "../index"
|
||||
|
||||
export async function listAndCountPriceListPricingModule({
|
||||
filters,
|
||||
listConfig = { skip: 0 },
|
||||
container,
|
||||
}: {
|
||||
container: MedusaContainer
|
||||
filters?: FilterablePriceListProps
|
||||
listConfig?: FindConfig<PriceList>
|
||||
}): Promise<[PriceList[], number]> {
|
||||
const remoteQuery = container.resolve(LinkModuleUtils.REMOTE_QUERY)
|
||||
const customerModule = container.resolve(ModuleRegistrationName.CUSTOMER)
|
||||
|
||||
const query = {
|
||||
price_list: {
|
||||
__args: { filters, ...listConfig },
|
||||
...defaultAdminPriceListRemoteQueryObject,
|
||||
},
|
||||
}
|
||||
|
||||
const {
|
||||
rows: priceLists,
|
||||
metadata: { count },
|
||||
} = await remoteQuery(query)
|
||||
|
||||
if (!count) {
|
||||
return [[], 0]
|
||||
}
|
||||
|
||||
const customerGroupIds: string[] = priceLists
|
||||
.map((priceList) =>
|
||||
priceList.price_list_rules
|
||||
.filter((rule) => rule.rule_type.rule_attribute === "customer_group_id")
|
||||
.map((rule) =>
|
||||
rule.price_list_rule_values.map((rule_value) => rule_value.value)
|
||||
)
|
||||
)
|
||||
.flat(2)
|
||||
|
||||
const customerGroups = await customerModule.list({ id: customerGroupIds }, {})
|
||||
const customerGroupIdMap = new Map(customerGroups.map((cg) => [cg.id, cg]))
|
||||
|
||||
for (const priceList of priceLists) {
|
||||
const priceSetMoneyAmounts = priceList.price_set_money_amounts || []
|
||||
const priceListRulesData = priceList.price_list_rules || []
|
||||
delete priceList.price_set_money_amounts
|
||||
delete priceList.price_list_rules
|
||||
|
||||
priceList.prices = priceSetMoneyAmounts.map((priceSetMoneyAmount) => {
|
||||
const productVariant = priceSetMoneyAmount.price_set.variant_link.variant
|
||||
|
||||
const rules = priceSetMoneyAmount.price_rules.reduce((acc, curr) => {
|
||||
acc[curr.rule_type.rule_attribute] = curr.value
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return {
|
||||
...(priceSetMoneyAmount.money_amount as MoneyAmount),
|
||||
price_list_id: priceList.id,
|
||||
variant_id: productVariant?.id ?? null,
|
||||
variant: productVariant ?? null,
|
||||
region_id: rules["region_id"] ?? null,
|
||||
rules,
|
||||
}
|
||||
})
|
||||
|
||||
priceList.name = priceList.title
|
||||
delete priceList.title
|
||||
|
||||
const customerGroupRule = priceListRulesData.find(
|
||||
(plr) => plr.rule_type.rule_attribute === "customer_group_id"
|
||||
)
|
||||
|
||||
priceList.customer_groups =
|
||||
customerGroupRule?.price_list_rule_values
|
||||
.map((cgr) => customerGroupIdMap.get(cgr.value))
|
||||
.filter((cg): cg is CustomerGroup => !!cg) || []
|
||||
}
|
||||
|
||||
return [priceLists, count]
|
||||
}
|
||||
@@ -1,15 +1,5 @@
|
||||
import {
|
||||
CalculatedPriceSet,
|
||||
IPricingModuleService,
|
||||
PriceSetMoneyAmountDTO,
|
||||
RemoteQueryFunction,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
FlagRouter,
|
||||
MedusaV2Flag,
|
||||
promiseAll,
|
||||
removeNullish,
|
||||
} from "@medusajs/utils"
|
||||
import { IPricingModuleService, RemoteQueryFunction } from "@medusajs/types"
|
||||
import { FlagRouter, promiseAll } from "@medusajs/utils"
|
||||
import {
|
||||
CustomerService,
|
||||
ProductVariantService,
|
||||
@@ -20,13 +10,7 @@ import {
|
||||
IPriceSelectionStrategy,
|
||||
PriceSelectionContext,
|
||||
} from "../interfaces/price-selection-strategy"
|
||||
import {
|
||||
MoneyAmount,
|
||||
Product,
|
||||
ProductVariant,
|
||||
Region,
|
||||
ShippingOption,
|
||||
} from "../models"
|
||||
import { Product, ProductVariant, Region, ShippingOption } from "../models"
|
||||
import {
|
||||
PricedProduct,
|
||||
PricedShippingOption,
|
||||
@@ -197,128 +181,6 @@ class PricingService extends TransactionBaseService {
|
||||
return taxedPricing
|
||||
}
|
||||
|
||||
private async getProductVariantPricingModulePricing_(
|
||||
variantPriceData: {
|
||||
variantId: string
|
||||
quantity?: number
|
||||
}[],
|
||||
context: PricingContext
|
||||
) {
|
||||
const variables = {
|
||||
variant_id: variantPriceData.map((pricedata) => pricedata.variantId),
|
||||
take: null,
|
||||
}
|
||||
|
||||
const query = {
|
||||
product_variant_price_set: {
|
||||
__args: variables,
|
||||
fields: ["variant_id", "price_set_id"],
|
||||
},
|
||||
}
|
||||
|
||||
const variantPriceSets = await this.remoteQuery(query)
|
||||
|
||||
const variantIdToPriceSetIdMap: Map<string, string> = new Map(
|
||||
variantPriceSets.map((variantPriceSet) => [
|
||||
variantPriceSet.variant_id,
|
||||
variantPriceSet.price_set_id,
|
||||
])
|
||||
)
|
||||
|
||||
const priceSetIds: string[] = variantPriceSets.map(
|
||||
(variantPriceSet) => variantPriceSet.price_set_id
|
||||
)
|
||||
|
||||
const queryContext: PriceSelectionContext & {
|
||||
customer_group_id?: string[]
|
||||
} = removeNullish(context.price_selection)
|
||||
|
||||
if (queryContext.customer_id) {
|
||||
const { groups } = await this.customerService_.retrieve(
|
||||
queryContext.customer_id,
|
||||
{ relations: ["groups"] }
|
||||
)
|
||||
|
||||
if (groups?.length) {
|
||||
queryContext.customer_group_id = groups.map((group) => group.id)
|
||||
}
|
||||
}
|
||||
|
||||
let calculatedPrices: CalculatedPriceSet[] = []
|
||||
|
||||
if (queryContext.currency_code) {
|
||||
calculatedPrices = (await this.pricingModuleService.calculatePrices(
|
||||
{ id: priceSetIds },
|
||||
{
|
||||
context: queryContext as any,
|
||||
}
|
||||
)) as unknown as CalculatedPriceSet[]
|
||||
}
|
||||
|
||||
const calculatedPriceMap = new Map<string, CalculatedPriceSet>(
|
||||
calculatedPrices.map((priceSet) => [priceSet.id, priceSet])
|
||||
)
|
||||
|
||||
const pricingResultMap = new Map()
|
||||
|
||||
variantPriceData.forEach(({ variantId }) => {
|
||||
const priceSetId = variantIdToPriceSetIdMap.get(variantId)
|
||||
|
||||
const pricingResult: ProductVariantPricing = {
|
||||
prices: [] as MoneyAmount[],
|
||||
original_price: null,
|
||||
calculated_price: null,
|
||||
calculated_price_type: null,
|
||||
original_price_includes_tax: null,
|
||||
calculated_price_includes_tax: null,
|
||||
original_price_incl_tax: null,
|
||||
calculated_price_incl_tax: null,
|
||||
original_tax: null,
|
||||
calculated_tax: null,
|
||||
tax_rates: null,
|
||||
}
|
||||
|
||||
if (priceSetId) {
|
||||
const calculatedPrices: CalculatedPriceSet | undefined =
|
||||
calculatedPriceMap.get(priceSetId)
|
||||
|
||||
if (calculatedPrices) {
|
||||
pricingResult.prices.push({
|
||||
id: calculatedPrices?.original_price?.id,
|
||||
currency_code: calculatedPrices.currency_code,
|
||||
amount: calculatedPrices.original_amount,
|
||||
min_quantity: calculatedPrices.original_price?.min_quantity,
|
||||
max_quantity: calculatedPrices.original_price?.max_quantity,
|
||||
price_list_id: calculatedPrices.original_price?.price_list_id,
|
||||
} as MoneyAmount)
|
||||
|
||||
if (
|
||||
calculatedPrices.calculated_price?.id !==
|
||||
calculatedPrices.original_price?.id
|
||||
) {
|
||||
pricingResult.prices.push({
|
||||
id: calculatedPrices.calculated_price?.id,
|
||||
currency_code: calculatedPrices.currency_code,
|
||||
amount: calculatedPrices.calculated_amount,
|
||||
min_quantity: calculatedPrices.calculated_price?.min_quantity,
|
||||
max_quantity: calculatedPrices.calculated_price?.max_quantity,
|
||||
price_list_id: calculatedPrices.calculated_price?.price_list_id,
|
||||
} as MoneyAmount)
|
||||
}
|
||||
|
||||
pricingResult.original_price = calculatedPrices?.original_amount
|
||||
pricingResult.calculated_price = calculatedPrices?.calculated_amount
|
||||
pricingResult.calculated_price_type =
|
||||
calculatedPrices?.calculated_price?.price_list_type
|
||||
}
|
||||
}
|
||||
|
||||
pricingResultMap.set(variantId, pricingResult)
|
||||
})
|
||||
|
||||
return pricingResultMap
|
||||
}
|
||||
|
||||
private async getProductVariantPricing_(
|
||||
data: {
|
||||
variantId: string
|
||||
@@ -326,10 +188,6 @@ class PricingService extends TransactionBaseService {
|
||||
}[],
|
||||
context: PricingContext
|
||||
): Promise<Map<string, ProductVariantPricing>> {
|
||||
if (this.featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||
return await this.getProductVariantPricingModulePricing_(data, context)
|
||||
}
|
||||
|
||||
const variantsPricing = await this.priceSelectionStrategy
|
||||
.withTransaction(this.activeManager_)
|
||||
.calculateVariantPrice(data, context.price_selection)
|
||||
@@ -681,163 +539,17 @@ class PricingService extends TransactionBaseService {
|
||||
})
|
||||
}
|
||||
|
||||
private async getPricingModuleVariantMoneyAmounts(
|
||||
variantIds: string[]
|
||||
): Promise<Map<string, MoneyAmount[]>> {
|
||||
const variables = {
|
||||
variant_id: variantIds,
|
||||
take: null,
|
||||
}
|
||||
|
||||
const query = {
|
||||
product_variant_price_set: {
|
||||
__args: variables,
|
||||
fields: ["variant_id", "price_set_id"],
|
||||
},
|
||||
}
|
||||
|
||||
const variantPriceSets = await this.remoteQuery(query)
|
||||
|
||||
const priceSetIdToVariantIdMap: Map<string, string> = new Map(
|
||||
variantPriceSets.map((variantPriceSet) => [
|
||||
variantPriceSet.price_set_id,
|
||||
variantPriceSet.variant_id,
|
||||
])
|
||||
)
|
||||
|
||||
const priceSetIds: string[] = variantPriceSets.map(
|
||||
(variantPriceSet) => variantPriceSet.price_set_id
|
||||
)
|
||||
|
||||
const priceSetMoneyAmounts: PriceSetMoneyAmountDTO[] =
|
||||
await this.pricingModuleService.listPriceSetMoneyAmounts(
|
||||
{
|
||||
price_set_id: priceSetIds,
|
||||
},
|
||||
{
|
||||
take: null,
|
||||
relations: [
|
||||
"money_amount",
|
||||
"price_list",
|
||||
"price_set",
|
||||
"price_rules",
|
||||
"price_rules.rule_type",
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
const variantIdMoneyAmountMap = priceSetMoneyAmounts.reduce(
|
||||
(map, priceSetMoneyAmount) => {
|
||||
const variantId = priceSetIdToVariantIdMap.get(
|
||||
priceSetMoneyAmount.price_set!.id
|
||||
)
|
||||
if (!variantId) {
|
||||
return map
|
||||
}
|
||||
|
||||
const regionId = priceSetMoneyAmount.price_rules!.find(
|
||||
(pr) => pr.rule_type.rule_attribute === "region_id"
|
||||
)?.value
|
||||
|
||||
delete priceSetMoneyAmount.money_amount?.price_set_money_amount
|
||||
const moneyAmount = {
|
||||
...priceSetMoneyAmount.money_amount,
|
||||
region_id: null as null | string,
|
||||
price_list_id: priceSetMoneyAmount.price_list?.id ?? null,
|
||||
price_list: priceSetMoneyAmount.price_list ?? null,
|
||||
}
|
||||
|
||||
if (regionId) {
|
||||
moneyAmount.region_id = regionId
|
||||
}
|
||||
|
||||
if (map.has(variantId)) {
|
||||
map.get(variantId).push(moneyAmount)
|
||||
} else {
|
||||
map.set(variantId, [moneyAmount])
|
||||
}
|
||||
return map
|
||||
},
|
||||
new Map()
|
||||
)
|
||||
|
||||
return variantIdMoneyAmountMap
|
||||
}
|
||||
|
||||
async setAdminVariantPricing(
|
||||
variants: ProductVariant[],
|
||||
context: PriceSelectionContext = {}
|
||||
): Promise<PricedVariant[]> {
|
||||
if (!this.featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||
return await this.setVariantPrices(variants, context)
|
||||
}
|
||||
|
||||
const variantIds = variants.map((variant) => variant.id)
|
||||
|
||||
const variantIdMoneyAmountMap =
|
||||
await this.getPricingModuleVariantMoneyAmounts(variantIds)
|
||||
|
||||
return variants.map((variant) => {
|
||||
const pricing: ProductVariantPricing = {
|
||||
prices: variantIdMoneyAmountMap.get(variant.id) ?? [],
|
||||
original_price: null,
|
||||
calculated_price: null,
|
||||
calculated_price_type: null,
|
||||
original_price_includes_tax: null,
|
||||
calculated_price_includes_tax: null,
|
||||
original_price_incl_tax: null,
|
||||
calculated_price_incl_tax: null,
|
||||
original_tax: null,
|
||||
calculated_tax: null,
|
||||
tax_rates: null,
|
||||
}
|
||||
|
||||
Object.assign(variant, pricing)
|
||||
return variant as unknown as PricedVariant
|
||||
})
|
||||
return await this.setVariantPrices(variants, context)
|
||||
}
|
||||
|
||||
async setAdminProductPricing(
|
||||
products: Product[]
|
||||
): Promise<(Product | PricedProduct)[]> {
|
||||
if (!this.featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||
return await this.setProductPrices(products)
|
||||
}
|
||||
|
||||
const variantIds = products
|
||||
.map((product) => product.variants.map((variant) => variant.id).flat())
|
||||
.flat()
|
||||
|
||||
const variantIdMoneyAmountMap =
|
||||
await this.getPricingModuleVariantMoneyAmounts(variantIds)
|
||||
|
||||
return products.map((product) => {
|
||||
if (!product?.variants?.length) {
|
||||
return product
|
||||
}
|
||||
|
||||
product.variants.map((productVariant): PricedVariant => {
|
||||
const pricing: ProductVariantPricing = {
|
||||
prices: variantIdMoneyAmountMap.get(productVariant.id) ?? [],
|
||||
original_price: null,
|
||||
calculated_price: null,
|
||||
calculated_price_type: null,
|
||||
original_price_includes_tax: null,
|
||||
calculated_price_includes_tax: null,
|
||||
original_price_incl_tax: null,
|
||||
calculated_price_incl_tax: null,
|
||||
original_tax: null,
|
||||
calculated_tax: null,
|
||||
tax_rates: null,
|
||||
}
|
||||
|
||||
Object.assign(productVariant, pricing)
|
||||
|
||||
return productVariant as unknown as PricedVariant
|
||||
})
|
||||
|
||||
return product
|
||||
})
|
||||
return await this.setProductPrices(products)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,11 +5,10 @@ export async function getVariantsFromPriceList(
|
||||
priceListId: string
|
||||
) {
|
||||
const remoteQuery = container.resolve("remoteQuery")
|
||||
|
||||
const query = {
|
||||
price_list: {
|
||||
__args: { id: [priceListId] },
|
||||
price_set_money_amounts: {
|
||||
prices: {
|
||||
price_set: {
|
||||
variant_link: { variant: { fields: ["id", "product_id"] } },
|
||||
},
|
||||
@@ -21,8 +20,8 @@ export async function getVariantsFromPriceList(
|
||||
const variants: ProductVariantDTO[] = []
|
||||
|
||||
priceLists.forEach((priceList) => {
|
||||
priceList.price_set_money_amounts?.forEach((psma) => {
|
||||
const variant = psma.price_set?.variant_link?.variant
|
||||
priceList.prices?.forEach((price) => {
|
||||
const variant = price.price_set?.variant_link?.variant
|
||||
|
||||
if (variant) {
|
||||
variants.push(variant)
|
||||
|
||||
Reference in New Issue
Block a user