File tree Expand file tree Collapse file tree 5 files changed +35
-4
lines changed
integration-tests/http/__tests__/exchanges
core-flows/src/order/workflows
types/src/promotion/common
modules/promotion/src/services Expand file tree Collapse file tree 5 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @medusajs/promotion " : patch
3+ " @medusajs/core-flows " : patch
4+ " @medusajs/types " : patch
5+ ---
6+
7+ fix: skip promotion usage limit checks on edit flows
Original file line number Diff line number Diff line change @@ -1437,6 +1437,16 @@ medusaIntegrationTestRunner({
14371437 adminHeaders
14381438 )
14391439
1440+ const promotionModule = getContainer ( ) . resolve ( Modules . PROMOTION )
1441+
1442+ // check that adjustments are computed for promotions that exceeded usage limit (we ignore usage limits on edit flows)
1443+ // @ts -ignore
1444+ await promotionModule . updatePromotions ( {
1445+ id : appliedPromotion . id ,
1446+ limit : 1 ,
1447+ used : 1 ,
1448+ } )
1449+
14401450 let result = await api . post (
14411451 "/admin/exchanges" ,
14421452 {
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export type ComputeAdjustmentsForPreviewWorkflowInput = {
2929 /**
3030 * The order's details.
3131 */
32- order : OrderDTO & {
32+ order : OrderDTO & {
3333 /**
3434 * The promotions applied to the order.
3535 */
@@ -52,7 +52,7 @@ export const computeAdjustmentsForPreviewWorkflowId =
5252 *
5353 * You can use this workflow within your customizations or your own custom workflows, allowing you to compute adjustments
5454 * in your custom flows.
55- *
55+ *
5656 * @since v2.12.0
5757 *
5858 * @example
@@ -110,6 +110,9 @@ export const computeAdjustmentsForPreviewWorkflow = createWorkflow(
110110 const actions = getActionsToComputeFromPromotionsStep ( {
111111 computeActionContext : actionsToComputeItemsInput ,
112112 promotionCodesToApply : orderPromotions ,
113+ options : {
114+ skip_usage_limit_checks : true ,
115+ } ,
113116 } )
114117
115118 const { lineItemAdjustmentsToCreate } =
Original file line number Diff line number Diff line change @@ -295,4 +295,11 @@ export interface ComputeActionOptions {
295295 * automatically. If not provided, the automatic promotions are applied.
296296 */
297297 prevent_auto_promotions ?: boolean
298+
299+ /**
300+ * Whether to skip the usage limit checks.
301+ * Useful when recomputing adjustment for promotions that are already applied as a part of edit/exchange flows.
302+ *
303+ */
304+ skip_usage_limit_checks ?: boolean
298305}
Original file line number Diff line number Diff line change @@ -634,7 +634,10 @@ export default class PromotionModuleService
634634 options : PromotionTypes . ComputeActionOptions = { } ,
635635 @MedusaContext ( ) sharedContext : Context = { }
636636 ) : Promise < PromotionTypes . ComputeActions [ ] > {
637- const { prevent_auto_promotions : preventAutoPromotions } = options
637+ const {
638+ prevent_auto_promotions : preventAutoPromotions ,
639+ skip_usage_limit_checks : skipUsageLimitChecks ,
640+ } = options
638641 const computedActions : PromotionTypes . ComputeActions [ ] = [ ]
639642 const { items = [ ] , shipping_methods : shippingMethods = [ ] } =
640643 applicationContext
@@ -806,6 +809,7 @@ export default class PromotionModuleService
806809 } = promotion
807810
808811 if (
812+ ! skipUsageLimitChecks &&
809813 promotion . campaign ?. budget ?. type === CampaignBudgetType . USE_BY_ATTRIBUTE
810814 ) {
811815 const attribute = promotion . campaign ?. budget ?. attribute !
@@ -847,7 +851,7 @@ export default class PromotionModuleService
847851 }
848852
849853 // Check promotion usage limit
850- if ( typeof promotion . limit === "number" ) {
854+ if ( ! skipUsageLimitChecks && typeof promotion . limit === "number" ) {
851855 if ( ( promotion . used ?? 0 ) >= promotion . limit ) {
852856 computedActions . push ( {
853857 action : ComputedActions . PROMOTION_LIMIT_EXCEEDED ,
You can’t perform that action at this time.
0 commit comments