Promotion Actions

In this document, you’ll learn about promotion actions and how they’re computed using the computeActions method.

computeActions Method#

The Promotion Module's main service has a computeActions method that returns an array of actions to perform on a cart when one or more promotions are applied.

Actions inform you what adjustment must be made to a cart item or shipping method. Each action is an object having the action property 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:

Code
1export interface AddItemAdjustmentAction {2  action: "addItemAdjustment"3  item_id: string4  amount: number5  code: string6  description?: string7}

This action means that a new record should be created of the LineItemAdjustment data model in the Cart Module, or OrderLineItemAdjustment data model in the Order Module.

NoteRefer 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.

The computeActions method accepts any previous item adjustments in the items property of the second parameter.

This action has the following format:

Code
1export interface RemoveItemAdjustmentAction {2  action: "removeItemAdjustment"3  adjustment_id: string4  description?: string5  code: string6}

This action means that a new record should be removed of the LineItemAdjustment (or OrderLineItemAdjustment) with the specified ID in the adjustment_id property.

NoteRefer 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:

Code
1export interface AddShippingMethodAdjustment {2  action: "addShippingMethodAdjustment"3  shipping_method_id: string4  amount: number5  code: string6  description?: string7}

This action means that a new record should be created of the ShippingMethodAdjustment data model in the Cart Module, or OrderShippingMethodAdjustment data model in the Order Module.

NoteRefer 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.

The computeActions method accepts any previous shipping method adjustments in the shipping_methods property of the second parameter.

This action has the following format:

Code
1export interface RemoveShippingMethodAdjustment {2  action: "removeShippingMethodAdjustment"3  adjustment_id: string4  code: string5}

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

NoteRefer 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:

Code
1export interface CampaignBudgetExceededAction {2  action: "campaignBudgetExceeded"3  code: string4}
NoteRefer to this reference for details on the object’s properties.
Was this page helpful?
Edit this page