chore: fix variant pricing validation for carts (#7344)

This commit is contained in:
Riqwan Thamir
2024-05-16 09:03:37 +02:00
committed by GitHub
parent 22f30f54fd
commit b78703b8c6
4 changed files with 17 additions and 6 deletions

View File

@@ -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: [
{

View File

@@ -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) {

View File

@@ -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)
}
}

View File

@@ -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)
}