payloadcms/payload · error · Error

Variant with ID ${variant.id} does not have a price in ${cur

Error message

Variant with ID ${variant.id} does not have a price in ${currency}.

What it means

Thrown by defaultProductsValidation when a variant is supplied but has no value for the dynamic price field priceIn<CURRENCY> (e.g. priceInUSD). The validator checks `!variant[priceField]`, so a variant defined without a price in the requested currency fails. This is a data-completeness error on the variant record.

Source

Thrown at packages/plugin-ecommerce/src/utilities/defaultProductsValidation.ts:20

import { MissingPrice, OutOfStock } from './errorCodes.js'

export const defaultProductsValidation: ProductsValidation = ({
  currenciesConfig,
  currency,
  product,
  quantity = 1,
  variant,
}) => {
  if (!currency) {
    throw new Error('Currency must be provided for product validation.')
  }

  const priceField = `priceIn${currency.toUpperCase()}`

  if (variant) {
    if (!variant[priceField]) {
      throw new Error(`Variant with ID ${variant.id} does not have a price in ${currency}.`)
    }

    if (variant.inventory === 0 || (variant.inventory && variant.inventory < quantity)) {
      throw new Error(
        `Variant with ID ${variant.id} is out of stock or does not have enough inventory.`,
      )
    }
  } else if (product) {
    // Validate the product's details only if the variant is not provided as it can have its own inventory and price
    if (!product[priceField]) {
      throw new Error(`Product does not have a price in.`, {
        cause: { code: MissingPrice, codes: [product.id, currency] },
      })
    }

    if (product.inventory === 0 || (product.inventory && product.inventory < quantity)) {
      throw new Error(`Product is out of stock or does not have enough inventory.`, {
        cause: { code: OutOfStock, codes: [product.id] },

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Backfill the missing price field on the variant for the requested currency.
  2. Restrict checkout to currencies for which the variant has a price, or hide the variant for unsupported currencies.
  3. Validate variant price completeness when creating/updating variants (admin hook) so gaps never reach checkout.
  4. Confirm the currency string matches the suffix in the price field name (case-insensitive — the code uppercases it).

Example fix

// before: variant has priceInUSD but not priceInEUR
const variant = { id: 1, priceInUSD: 1000 } // EUR checkout fails
// after: backfill or restrict currency
const variant = { id: 1, priceInUSD: 1000, priceInEUR: 920 }
Defensive patterns

Strategy: validation

Validate before calling

function variantHasPriceInCurrency(variant: Record<string, unknown>, currency: string): boolean {
  const field = `priceIn${currency.toUpperCase()}`
  const v = variant[field]
  return typeof v === 'number' ? v > 0 : Boolean(v)
}

if (!variantHasPriceInCurrency(variant, currency)) {
  throw new Error(`Variant ${variant.id} has no price in ${currency}`)
}

Type guard

export function variantHasPrice(variant: Record<string, unknown>, currency: string): boolean {
  const v = variant[`priceIn${currency.toUpperCase()}`]
  return typeof v === 'number' ? v > 0 : Boolean(v)
}

Try / catch

try {
  defaultProductsValidation({ currency, variant, quantity })
} catch (err) {
  if (err instanceof Error && /does not have a price in/.test(err.message)) {
    // hide the variant for this currency, or prompt admin to backfill
    return { ok: false, reason: 'variant-missing-price', variantId: variant.id, currency }
  }
  throw err
}

Prevention

When it happens

Trigger: A cart item references a variant whose priceIn<CURRENCY> field is unset/zero/falsy for the currency the customer is checking out in. Triggered during cart validation or checkout when quantity is being confirmed against a variant.

Common situations: Multi-currency store where the variant has prices for some currencies but not the one selected; new variant created without filling all configured currency price fields; currency recently added to currenciesConfig but existing variants not backfilled; variant imported with partial price data.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/2433f1cdded2d166. Report an issue: GitHub.