chore: fix variant pricing validation for carts (#7344)
This commit is contained in:
@@ -367,6 +367,11 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const region = await regionModuleService.create({
|
||||
name: "US",
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
const priceSet = await pricingModule.create({
|
||||
prices: [
|
||||
{
|
||||
@@ -405,6 +410,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const { errors } = await createCartWorkflow(appContainer).run({
|
||||
input: {
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ export const findOneOrAnyRegionStep = createStep(
|
||||
)
|
||||
|
||||
if (!data.regionId) {
|
||||
// TODO: Pick up the default store region if none is provided
|
||||
const regions = await service.list({})
|
||||
|
||||
if (!regions?.length) {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { BigNumberInput } from "@medusajs/types"
|
||||
import { MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { MedusaError, isPresent } from "@medusajs/utils"
|
||||
import { createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
variants: {
|
||||
id: string
|
||||
calculated_price?: BigNumberInput
|
||||
calculated_price?: {
|
||||
calculated_amount?: BigNumberInput | null
|
||||
}
|
||||
}[]
|
||||
}
|
||||
|
||||
@@ -14,9 +16,8 @@ export const validateVariantPricesStep = createStep(
|
||||
validateVariantPricesStepId,
|
||||
async (data: StepInput, { container }) => {
|
||||
const priceNotFound: string[] = []
|
||||
|
||||
for (const variant of data.variants) {
|
||||
if (!isDefined(variant.calculated_price)) {
|
||||
if (!isPresent(variant?.calculated_price?.calculated_amount)) {
|
||||
priceNotFound.push(variant.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ListShippingOptionsForCartWorkflowInputDTO } from "@medusajs/types"
|
||||
import { deepFlatMap, MedusaError } from "@medusajs/utils"
|
||||
import { deepFlatMap, isPresent, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
createWorkflow,
|
||||
transform,
|
||||
@@ -78,7 +78,10 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
|
||||
({ shipping_options }) => {
|
||||
const { calculated_price, ...options } = shipping_options ?? {}
|
||||
|
||||
if (options?.id && !calculated_price) {
|
||||
if (
|
||||
options?.id &&
|
||||
!isPresent(calculated_price?.calculated_amount)
|
||||
) {
|
||||
optionsMissingPrices.push(options.id)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user