0462cc5acf
- Change existing data model guides and add new ones for DML - Change module's docs around service factory + remove guides that are now necessary - Hide/remove all mentions of module relationships, or label them as coming soon. - Change all data model creation snippets to use DML - use `property` instead of `field` when referring to a data model's properties. - Fix all snippets in commerce module guides to use new method suffix (no more main model methods) - Rework recipes, removing/hiding a lot of sections as a lot of recipes are incomplete with the current state of DML. ### Other changes - Highlight fixes in some guides - Remove feature flags guide - Fix code block styles when there are no line numbers. ### Upcoming changes in other PRs - Re-generate commerce module references (for the updates in the method names) - Ensure that the data model references are generated correctly for models using DML. - (probably at a very later point) revisit recipes
134 lines
3.9 KiB
Plaintext
134 lines
3.9 KiB
Plaintext
export const metadata = {
|
||
title: `Promotion Actions`,
|
||
}
|
||
|
||
# {metadata.title}
|
||
|
||
In this document, you’ll learn about promotion actions and how they’re computed and used.
|
||
|
||
## computeActions Method
|
||
|
||
The Promotion Module's main service has a [computeActions method](/references/promotion/computeActions) 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:
|
||
|
||
```ts
|
||
export interface AddItemAdjustmentAction {
|
||
action: "addItemAdjustment"
|
||
item_id: string
|
||
amount: number
|
||
code: string
|
||
description?: string
|
||
}
|
||
```
|
||
|
||
This action means that a new record should be created of the `LineItemAdjustment` data model in the Cart Module.
|
||
|
||
<Note>
|
||
|
||
Refer to [this reference](/references/promotion/interfaces/promotion.AddItemAdjustmentAction) for details on the object’s properties.
|
||
|
||
</Note>
|
||
|
||
### `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:
|
||
|
||
```ts
|
||
export interface RemoveItemAdjustmentAction {
|
||
action: "removeItemAdjustment"
|
||
adjustment_id: string
|
||
description?: string
|
||
code: string
|
||
}
|
||
```
|
||
|
||
This action means that a new record should be removed of the `LineItemAdjustment` with the specified ID in the `adjustment_id` property.
|
||
|
||
<Note>
|
||
|
||
Refer to [this reference](/references/promotion/interfaces/promotion.RemoveItemAdjustmentAction) for details on the object’s properties.
|
||
|
||
</Note>
|
||
|
||
### `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:
|
||
|
||
```ts
|
||
export interface AddShippingMethodAdjustment {
|
||
action: "addShippingMethodAdjustment"
|
||
shipping_method_id: string
|
||
amount: number
|
||
code: string
|
||
description?: string
|
||
}
|
||
```
|
||
|
||
This action means that a new record should be created of the `ShippingMethodAdjustment` data model in the Cart Module.
|
||
|
||
<Note>
|
||
|
||
Refer to [this reference](/references/promotion/interfaces/promotion.AddShippingMethodAdjustment) for details on the object’s properties.
|
||
|
||
</Note>
|
||
|
||
### `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:
|
||
|
||
```ts
|
||
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](/references/promotion/interfaces/promotion.RemoveShippingMethodAdjustment) for details on the object’s properties.
|
||
|
||
</Note>
|
||
|
||
### `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:
|
||
|
||
```ts
|
||
export interface CampaignBudgetExceededAction {
|
||
action: "campaignBudgetExceeded"
|
||
code: string
|
||
}
|
||
```
|
||
|
||
<Note>
|
||
|
||
Refer to [this reference](/references/promotion/interfaces/promotion.CampaignBudgetExceededAction) for details on the object’s properties.
|
||
|
||
</Note>
|