Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-calculatedPriceSet-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/core-flows": patch
---

Return an invalid data error when adding a cart line item for a variant without a price
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createContainer } from "@medusajs/framework/awilix"
import { MedusaError, ProductStatus } from "@medusajs/framework/utils"
import {
createWorkflow,
WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"
import { prepareVariantsAndItemsWithPricesStep } from "../get-variants-and-items-with-prices"

describe("prepareVariantsAndItemsWithPricesStep", () => {
it("throws an invalid data error when a variant does not have a price", async () => {
const workflow = createWorkflow(
"test-prepare-variant-without-price",
() => {
const result = prepareVariantsAndItemsWithPricesStep({
cart: { id: "cart_1" },
items: [{ variant_id: "variant_1", quantity: 1 }],
variantsData: [
{
id: "variant_1",
product: {
id: "product_1",
status: ProductStatus.PUBLISHED,
},
inventory_items: [],
},
],
calculatedPriceSets: {},
})

return new WorkflowResponse(result)
}
)

const execution = workflow(createContainer()).run()

await expect(execution).rejects.toMatchObject({
type: MedusaError.Types.INVALID_DATA,
message: "Variants with IDs variant_1 do not have a price",
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const prepareVariantsAndItemsWithPricesStep = createStep(
isCustomPrice: isCustomPrice,
}

if (variant && !isCustomPrice) {
if (variant && !isCustomPrice && calculatedPriceSet) {
input.unitPrice = calculatedPriceSet.calculated_amount
input.isTaxInclusive =
calculatedPriceSet.is_calculated_price_tax_inclusive
Expand Down
Loading