Skip to main content
Skip to main content

Promotion Actions

In this document, you’ll learn about promotion actions and how they’re computed and used.

computeActions Method

The IPromotionModuleService has a computeActions method that returns an array of actions to perform on a cart when one or more promotions are applied.

Note

Refer to the method’s reference for full details on this method’s parameters and return type.

Actions inform you what adjustment must be made to a cart item or shipping method. Each action is an object having the action attribute indicating the type of action.


Action Types

addItemAdjustment Action

The addItemAdjustment action indicates that an adjustment must be made to an item. For example, removing $5 off its amount.

This action has the following format:

export interface AddItemAdjustmentAction {
action: "addItemAdjustment"
item_id: string
amount: number
code: string
description?: string
}

When the Medusa application receives this action type, it creates a new record of the LineItemAdjustment data model in the Cart Module.

Note

Refer to this reference for details on the object’s properties.

removeItemAdjustment Action

The removeItemAdjustment action indicates that an adjustment must be removed from a line item. For example, remove the $5 discount.

When the Medusa application uses the computeActions method, it passes any previous item adjustments in the items property of the second parameter.

This action has the following format:

export interface RemoveItemAdjustmentAction {
action: "removeItemAdjustment"
adjustment_id: string
description?: string
code: string
}

When the Medusa application receives this action type, it removes the LineItemAdjustment with the specified ID in the adjustment_id property.

Note

Refer to this reference for details on the object’s properties.

addShippingMethodAdjustment Action

The addShippingMethodAdjustment action indicates that an adjustment must be made on a shipping method. For example, make the shipping method free.

This action has the following format:

export interface AddShippingMethodAdjustment {
action: "addShippingMethodAdjustment"
shipping_method_id: string
amount: number
code: string
description?: string
}

When the Medusa application receives this action type, it creates a new record of the ShippingMethodAdjustment data model in the Cart Module.

Note

Refer to this reference for details on the object’s properties.

removeShippingMethodAdjustment Action

The removeShippingMethodAdjustment action indicates that an adjustment must be removed from a shipping method. For example, remove the free shipping discount.

When the Medusa application uses the computeActions method, it passes any previous shipping method adjustments in the shipping_methods property of the second parameter.

This action has the following format:

export interface RemoveShippingMethodAdjustment {
action: "removeShippingMethodAdjustment"
adjustment_id: string
code: string
}

When the Medusa application receives this action type, it removes the ShippingMethodAdjustment with the specified ID in the adjustment_id property.

Note

Refer to this reference for details on the object’s properties.

campaignBudgetExceeded Action

When the campaignBudgetExceeded action is returned, the promotions within a campaign can no longer be used as the campaign budget has been exceeded.

This action has the following format:

export interface CampaignBudgetExceededAction {
action: "campaignBudgetExceeded"
code: string
}

The Medusa Application considers this an error, so it doesn’t apply the promotions on the cart.

Note

Refer to this reference for details on the object’s properties.

Was this section helpful?