fix: Only list price set prices when calling the price set methods (#7889)
FIXES CORE-2417
This commit is contained in:
@@ -29,7 +29,6 @@ import {
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
promiseAll,
|
||||
removeNullish,
|
||||
@@ -130,6 +129,22 @@ export default class PricingModuleService
|
||||
return pricingContext
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
// @ts-expect-error
|
||||
async retrievePriceSet(
|
||||
id: string,
|
||||
config?: FindConfig<PriceSetDTO> | undefined,
|
||||
sharedContext?: Context | undefined
|
||||
): Promise<PriceSetDTO> {
|
||||
const priceSet = await this.priceSetService_.retrieve(
|
||||
id,
|
||||
this.normalizePriceSetConfig(config),
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<PriceSetDTO>(priceSet)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
// @ts-expect-error
|
||||
async listPriceSets(
|
||||
@@ -137,9 +152,17 @@ export default class PricingModuleService
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PriceSetDTO[]> {
|
||||
const pricingContext = this.setupCalculatedPriceConfig_(filters, config)
|
||||
const normalizedConfig = this.normalizePriceSetConfig(config)
|
||||
const pricingContext = this.setupCalculatedPriceConfig_(
|
||||
filters,
|
||||
normalizedConfig
|
||||
)
|
||||
|
||||
const priceSets = await super.listPriceSets(filters, config, sharedContext)
|
||||
const priceSets = await super.listPriceSets(
|
||||
filters,
|
||||
normalizedConfig,
|
||||
sharedContext
|
||||
)
|
||||
if (!pricingContext || !priceSets.length) {
|
||||
return priceSets
|
||||
}
|
||||
@@ -170,11 +193,15 @@ export default class PricingModuleService
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[PriceSetDTO[], number]> {
|
||||
const pricingContext = this.setupCalculatedPriceConfig_(filters, config)
|
||||
const normalizedConfig = this.normalizePriceSetConfig(config)
|
||||
const pricingContext = this.setupCalculatedPriceConfig_(
|
||||
filters,
|
||||
normalizedConfig
|
||||
)
|
||||
|
||||
const [priceSets, count] = await super.listAndCountPriceSets(
|
||||
filters,
|
||||
config,
|
||||
normalizedConfig,
|
||||
sharedContext
|
||||
)
|
||||
if (!pricingContext || !priceSets.length) {
|
||||
@@ -299,9 +326,9 @@ export default class PricingModuleService
|
||||
// TODO: Remove the need to refetch the data here
|
||||
const dbPriceSets = await this.listPriceSets(
|
||||
{ id: priceSets.map((p) => p.id) },
|
||||
{
|
||||
this.normalizePriceSetConfig({
|
||||
relations: ["prices", "prices.price_rules"],
|
||||
},
|
||||
}),
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -1296,4 +1323,15 @@ export default class PricingModuleService
|
||||
return priceListData
|
||||
})
|
||||
}
|
||||
|
||||
protected normalizePriceSetConfig(
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> | undefined
|
||||
) {
|
||||
return {
|
||||
options: {
|
||||
populateWhere: { prices: { price_list_id: null } },
|
||||
},
|
||||
...config,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user