{"record":{"id":"7724eb046bde5c01","repo":"medusajs/medusa","slug":"max-quantity-maxquantity-must-be-greater-than","errorCode":null,"errorMessage":"max_quantity (${maxQuantity}) must be greater than or equal to apply_to_quantity (${applyToQuantity}) for BUYGET promotions.","messagePattern":"max_quantity \\((.+?)\\) must be greater than or equal to apply_to_quantity \\((.+?)\\) for BUYGET promotions\\.","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/modules/promotion/src/utils/validations/application-method.ts","lineNumber":89,"sourceCode":"      )\n    }\n\n    if (!isPresent(maxQuantity)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `application_method.max_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`\n      )\n    }\n\n    if (!isPresent(applyToQuantity)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `application_method.apply_to_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`\n      )\n    }\n\n    if (MathBN.lt(maxQuantity!, applyToQuantity!)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `max_quantity (${maxQuantity}) must be greater than or equal to apply_to_quantity (${applyToQuantity}) for BUYGET promotions.`\n      )\n    }\n  }\n\n  if (\n    allocation === ApplicationMethodAllocation.ACROSS &&\n    isPresent(maxQuantity)\n  ) {\n    throw new MedusaError(\n      MedusaError.Types.INVALID_DATA,\n      `application_method.max_quantity is not allowed to be set for allocation (${ApplicationMethodAllocation.ACROSS})`\n    )\n  }\n\n  if (!allTargetTypes.includes(targetType)) {\n    throw new MedusaError(","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/promotion/src/utils/validations/application-method.ts#L71-L107","documentation":"For buy-get promotions, max_quantity must be >= apply_to_quantity. You cannot cap the number of discounted items below the number of items the promotion says it discounts; violation throws INVALID_DATA.","triggerScenarios":"Creating/updating a buyget promotion with e.g. apply_to_quantity: 3 and max_quantity: 1 (or max_quantity: 0).","commonSituations":"Misunderstanding the semantics (thinking max_quantity limits the buy side), form defaults setting max_quantity to 1 while apply_to_quantity is higher, data entry errors.","solutions":["Set max_quantity equal to or greater than apply_to_quantity (a common correct pair is apply_to_quantity=1, max_quantity=1)","Validate the invariant in the form before submission","Fix the data and resubmit the create/update"],"exampleFix":"// before\napplication_method: { apply_to_quantity: 2, buy_rules_min_quantity: 1, max_quantity: 1 }\n\n// after\napplication_method: { apply_to_quantity: 2, buy_rules_min_quantity: 1, max_quantity: 2 }","handlingStrategy":"validation","validationCode":"if (MathBN.lt(maxQuantity, applyToQuantity)) {\n  maxQuantity = applyToQuantity // or reject with a clear form error\n}","typeGuard":"const quantitiesConsistent = (am: { max_quantity?: number; apply_to_quantity?: number }): boolean => am.max_quantity == null || am.apply_to_quantity == null || am.max_quantity >= am.apply_to_quantity","tryCatchPattern":"try { await createPromotions(...) } catch (e) { if (e.type === MedusaError.Types.INVALID_DATA && /must be greater than or equal to/.test(e.message)) { /* set max_quantity = apply_to_quantity and resubmit */ } throw e }","preventionTips":["Enforce max_quantity >= apply_to_quantity in form validation","Document that max_quantity caps the get side","Pair the two fields in one UI control"],"tags":["promotion","buy-get","quantity","validation","medusa"],"backgroundTag":"value-out-of-range","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}