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