feat(medusa): Revert pricing service setVariantPrices API (#4130)
This commit is contained in:
committed by
GitHub
parent
c4aae6b976
commit
bf18bd0c8a
6
.changeset/ten-pumpkins-sleep.md
Normal file
6
.changeset/ten-pumpkins-sleep.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"integration-tests-api": patch
|
||||
---
|
||||
|
||||
feat(medusa): Revert pricing service setVariantPrices API
|
||||
@@ -33,7 +33,7 @@ const {
|
||||
simpleCustomerGroupFactory,
|
||||
} = require("../../../factories/simple-customer-group-factory")
|
||||
|
||||
jest.setTimeout(3000000)
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/carts", () => {
|
||||
let medusaProcess
|
||||
|
||||
@@ -69,9 +69,7 @@ export default async (req, res) => {
|
||||
req.retrieveConfig
|
||||
)
|
||||
|
||||
const [variant] = await pricingService.setVariantPrices([
|
||||
{ variant: rawVariant },
|
||||
])
|
||||
const [variant] = await pricingService.setVariantPrices([rawVariant])
|
||||
|
||||
res.status(200).json({ variant })
|
||||
}
|
||||
|
||||
@@ -147,17 +147,14 @@ export default async (req, res) => {
|
||||
currencyCode = region.currency_code
|
||||
}
|
||||
|
||||
let variants = await pricingService.setVariantPrices(
|
||||
rawVariants.map((v) => ({ variant: v })),
|
||||
{
|
||||
cart_id: req.validatedQuery.cart_id,
|
||||
region_id: regionId,
|
||||
currency_code: currencyCode,
|
||||
customer_id: req.validatedQuery.customer_id,
|
||||
include_discount_prices: true,
|
||||
ignore_cache: true,
|
||||
}
|
||||
)
|
||||
let variants = await pricingService.setVariantPrices(rawVariants, {
|
||||
cart_id: req.validatedQuery.cart_id,
|
||||
region_id: regionId,
|
||||
currency_code: currencyCode,
|
||||
customer_id: req.validatedQuery.customer_id,
|
||||
include_discount_prices: true,
|
||||
ignore_cache: true,
|
||||
})
|
||||
|
||||
const inventoryService: IInventoryService | undefined =
|
||||
req.scope.resolve("inventoryService")
|
||||
|
||||
@@ -97,16 +97,13 @@ export default async (req, res) => {
|
||||
currencyCode = region.currency_code
|
||||
}
|
||||
|
||||
const variantRes = await pricingService.setVariantPrices(
|
||||
[{ variant: rawVariant }],
|
||||
{
|
||||
cart_id: validated.cart_id,
|
||||
customer_id: customer_id,
|
||||
region_id: regionId,
|
||||
currency_code: currencyCode,
|
||||
include_discount_prices: true,
|
||||
}
|
||||
)
|
||||
const variantRes = await pricingService.setVariantPrices([rawVariant], {
|
||||
cart_id: validated.cart_id,
|
||||
customer_id: customer_id,
|
||||
region_id: regionId,
|
||||
currency_code: currencyCode,
|
||||
include_discount_prices: true,
|
||||
})
|
||||
|
||||
const [variant] = await productVariantInventoryService.setVariantAvailability(
|
||||
variantRes,
|
||||
|
||||
@@ -156,16 +156,13 @@ export default async (req, res) => {
|
||||
currencyCode = region.currency_code
|
||||
}
|
||||
|
||||
const pricedVariants = await pricingService.setVariantPrices(
|
||||
rawVariants.map((v) => ({ variant: v })),
|
||||
{
|
||||
cart_id: validated.cart_id,
|
||||
region_id: regionId,
|
||||
currency_code: currencyCode,
|
||||
customer_id: customer_id,
|
||||
include_discount_prices: true,
|
||||
}
|
||||
)
|
||||
const pricedVariants = await pricingService.setVariantPrices(rawVariants, {
|
||||
cart_id: validated.cart_id,
|
||||
region_id: regionId,
|
||||
currency_code: currencyCode,
|
||||
customer_id: customer_id,
|
||||
include_discount_prices: true,
|
||||
})
|
||||
|
||||
const variants = await productVariantInventoryService.setVariantAvailability(
|
||||
pricedVariants,
|
||||
|
||||
@@ -5,7 +5,7 @@ export const PricingServiceMock = {
|
||||
setProductPrices: jest.fn().mockImplementation((prod) => {
|
||||
return Promise.resolve(prod)
|
||||
}),
|
||||
setVariantPrices: jest.fn().mockImplementation(([{ variant }]) => {
|
||||
setVariantPrices: jest.fn().mockImplementation(([variant]) => {
|
||||
return Promise.resolve([variant])
|
||||
}),
|
||||
setShippingOptionPrices: jest.fn().mockImplementation((opts) => {
|
||||
|
||||
@@ -451,61 +451,26 @@ class PricingService extends TransactionBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Set additional prices on a list of product variants.
|
||||
* @param variants
|
||||
* @param context
|
||||
* @param context - the price selection context to use
|
||||
* @return A list of products with variants decorated with prices
|
||||
*/
|
||||
async setVariantPrices(
|
||||
variants: ProductVariant[],
|
||||
context?: PriceSelectionContext
|
||||
): Promise<PricedVariant[]>
|
||||
|
||||
/**
|
||||
* Set additional prices on a list of product variants.
|
||||
* @param variantsData
|
||||
* @param context - the price selection context to use
|
||||
* @return A list of products with variants decorated with prices
|
||||
*/
|
||||
async setVariantPrices(
|
||||
variantsData: { variant: ProductVariant; quantity?: number }[],
|
||||
context?: PriceSelectionContext
|
||||
): Promise<PricedVariant[]>
|
||||
|
||||
/**
|
||||
* Set additional prices on a list of product variants.
|
||||
* @param variantsData
|
||||
* @param context - the price selection context to use
|
||||
* @return A list of products with variants decorated with prices
|
||||
*/
|
||||
async setVariantPrices(
|
||||
variantsData:
|
||||
| ProductVariant[]
|
||||
| { variant: ProductVariant; quantity?: number }[],
|
||||
context: PriceSelectionContext = {}
|
||||
): Promise<PricedVariant[]> {
|
||||
const pricingContext = await this.collectPricingContext(context)
|
||||
|
||||
let data = variantsData as {
|
||||
variant: ProductVariant
|
||||
quantity?: number
|
||||
}[]
|
||||
|
||||
if ("id" in variantsData) {
|
||||
data = (variantsData as ProductVariant[]).map((v) => ({
|
||||
variant: v,
|
||||
quantity: pricingContext.price_selection.quantity,
|
||||
}))
|
||||
}
|
||||
|
||||
const variantsPricingMap = await this.getProductVariantsPricing(
|
||||
data.map((v) => ({
|
||||
variantId: v.variant.id,
|
||||
quantity: v.quantity,
|
||||
variants.map((v) => ({
|
||||
variantId: v.id,
|
||||
quantity: context.quantity,
|
||||
})),
|
||||
pricingContext
|
||||
)
|
||||
|
||||
return data.map(({ variant }) => {
|
||||
return variants.map((variant) => {
|
||||
const variantPricing = variantsPricingMap[variant.id]
|
||||
Object.assign(variant, variantPricing)
|
||||
return variant as unknown as PricedVariant
|
||||
|
||||
Reference in New Issue
Block a user