|
1
|
import { Table } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `Application Method`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
In this guide, you'll learn what an application method is in the Promotion Module. |
|
10
|
|
|
11
|
## What is an Application Method? |
|
12
|
|
|
13
|
The [ApplicationMethod data model](/references/promotion/models/ApplicationMethod) defines how a promotion is applied. It has the following properties that determine its behavior: |
|
14
|
|
|
15
|
<Table> |
|
16
|
<Table.Header> |
|
17
|
<Table.Row> |
|
18
|
<Table.HeaderCell> |
|
19
|
|
|
20
|
Property |
|
21
|
|
|
22
|
</Table.HeaderCell> |
|
23
|
<Table.HeaderCell> |
|
24
|
|
|
25
|
Purpose |
|
26
|
|
|
27
|
</Table.HeaderCell> |
|
28
|
<Table.HeaderCell> |
|
29
|
|
|
30
|
Possible Values |
|
31
|
|
|
32
|
</Table.HeaderCell> |
|
33
|
</Table.Row> |
|
34
|
</Table.Header> |
|
35
|
<Table.Body> |
|
36
|
<Table.Row> |
|
37
|
<Table.Cell> |
|
38
|
|
|
39
|
`type` |
|
40
|
|
|
41
|
</Table.Cell> |
|
42
|
<Table.Cell> |
|
43
|
|
|
44
|
Does the promotion discount a fixed amount or a percentage? |
|
45
|
|
|
46
|
</Table.Cell> |
|
47
|
<Table.Cell> |
|
48
|
|
|
49
|
`fixed`, `percentage` |
|
50
|
|
|
51
|
</Table.Cell> |
|
52
|
</Table.Row> |
|
53
|
<Table.Row> |
|
54
|
<Table.Cell> |
|
55
|
|
|
56
|
`target_type` |
|
57
|
|
|
58
|
</Table.Cell> |
|
59
|
<Table.Cell> |
|
60
|
|
|
61
|
Is the promotion applied to a cart item, shipping method, or the entire order? |
|
62
|
|
|
63
|
</Table.Cell> |
|
64
|
<Table.Cell> |
|
65
|
|
|
66
|
`items`, `shipping_methods`, `order` |
|
67
|
|
|
68
|
</Table.Cell> |
|
69
|
</Table.Row> |
|
70
|
<Table.Row> |
|
71
|
<Table.Cell> |
|
72
|
|
|
73
|
`allocation` |
|
74
|
|
|
75
|
</Table.Cell> |
|
76
|
<Table.Cell> |
|
77
|
|
|
78
|
Is the discounted amount applied to each item, split between the applicable items, or applied on specific number of items? |
|
79
|
|
|
80
|
</Table.Cell> |
|
81
|
<Table.Cell> |
|
82
|
|
|
83
|
`each`, `across`, `once` |
|
84
|
|
|
85
|
</Table.Cell> |
|
86
|
</Table.Row> |
|
87
|
<Table.Row> |
|
88
|
<Table.Cell> |
|
89
|
|
|
90
|
`value` |
|
91
|
|
|
92
|
</Table.Cell> |
|
93
|
<Table.Cell> |
|
94
|
|
|
95
|
How much is discounted? Its meaning depends on the `type`: a fixed amount when `type` is `fixed`, or a percentage between `0` and `100` when `type` is `percentage`. |
|
96
|
|
|
97
|
</Table.Cell> |
|
98
|
<Table.Cell> |
|
99
|
|
|
100
|
A number, such as `10`. |
|
101
|
|
|
102
|
</Table.Cell> |
|
103
|
</Table.Row> |
|
104
|
<Table.Row> |
|
105
|
<Table.Cell> |
|
106
|
|
|
107
|
`currency_code` |
|
108
|
|
|
109
|
</Table.Cell> |
|
110
|
<Table.Cell> |
|
111
|
|
|
112
|
Which currency does the promotion apply to? Only carts whose currency matches receive the discount. Required for `fixed` promotions, as explained in the [Discount Value and Currency section](#discount-value-and-currency). |
|
113
|
|
|
114
|
</Table.Cell> |
|
115
|
<Table.Cell> |
|
116
|
|
|
117
|
A currency code, such as `usd`. |
|
118
|
|
|
119
|
</Table.Cell> |
|
120
|
</Table.Row> |
|
121
|
</Table.Body> |
|
122
|
</Table> |
|
123
|
|
|
124
|
--- |
|
125
|
|
|
126
|
## Discount Value and Currency |
|
127
|
|
|
128
|
The `value` and `currency_code` properties work together based on the application method's `type`: |
|
129
|
|
|
130
|
<Table> |
|
131
|
<Table.Header> |
|
132
|
<Table.Row> |
|
133
|
<Table.HeaderCell> |
|
134
|
|
|
135
|
`type` |
|
136
|
|
|
137
|
</Table.HeaderCell> |
|
138
|
<Table.HeaderCell> |
|
139
|
|
|
140
|
Meaning of `value` |
|
141
|
|
|
142
|
</Table.HeaderCell> |
|
143
|
<Table.HeaderCell> |
|
144
|
|
|
145
|
Role of `currency_code` |
|
146
|
|
|
147
|
</Table.HeaderCell> |
|
148
|
</Table.Row> |
|
149
|
</Table.Header> |
|
150
|
<Table.Body> |
|
151
|
<Table.Row> |
|
152
|
<Table.Cell> |
|
153
|
|
|
154
|
`fixed` |
|
155
|
|
|
156
|
</Table.Cell> |
|
157
|
<Table.Cell> |
|
158
|
|
|
159
|
A fixed amount to discount, such as `10` to discount `$10`. |
|
160
|
|
|
161
|
</Table.Cell> |
|
162
|
<Table.Cell> |
|
163
|
|
|
164
|
Set the `currency_code` to specify the currency of the discounted amount. A fixed amount is only meaningful in a specific currency, so set the `currency_code` for `fixed` promotions. |
|
165
|
|
|
166
|
</Table.Cell> |
|
167
|
</Table.Row> |
|
168
|
<Table.Row> |
|
169
|
<Table.Cell> |
|
170
|
|
|
171
|
`percentage` |
|
172
|
|
|
173
|
</Table.Cell> |
|
174
|
<Table.Cell> |
|
175
|
|
|
176
|
A percentage between `0` and `100` to discount, such as `10` to discount `10%`. |
|
177
|
|
|
178
|
</Table.Cell> |
|
179
|
<Table.Cell> |
|
180
|
|
|
181
|
The `currency_code` isn't relevant to the discounted amount, since a percentage applies to any currency. You can still set it to restrict the promotion to a single currency. |
|
182
|
|
|
183
|
</Table.Cell> |
|
184
|
</Table.Row> |
|
185
|
</Table.Body> |
|
186
|
</Table> |
|
187
|
|
|
188
|
### How the Currency Match Works |
|
189
|
|
|
190
|
When a `currency_code` is set, Medusa only applies the promotion if the cart's currency matches the application method's `currency_code`. If you don't set a `currency_code`, the promotion applies to carts of any currency. |
|
191
|
|
|
192
|
For example, a `fixed` promotion with a `value` of `10` and a `currency_code` of `usd` discounts `$10` off carts using the US dollar. It isn't applied to a cart using the Euro. |
|
193
|
|
|
194
|
<Note> |
|
195
|
|
|
196
|
If the promotion belongs to a [campaign](../campaign/page.mdx) with a spend-based budget, the campaign budget's `currency_code` must match the application method's `currency_code`. |
|
197
|
|
|
198
|
</Note> |
|
199
|
|
|
200
|
## Target Promotion Rules |
|
201
|
|
|
202
|
When the promotion is applied to a cart item or a shipping method (in other words, when `target_type` is `items` or `shipping_methods`), you can restrict which items/shipping methods the promotion is applied to. |
|
203
|
|
|
204
|
The `ApplicationMethod` data model has a collection of [PromotionRule](/references/promotion/models/PromotionRule) records to restrict which items or shipping methods the promotion applies to. The `target_rules` property in the `ApplicationMethod` represents this relation. |
|
205
|
|
|
206
|
 |
|
207
|
|
|
208
|
In this example, the promotion is only applied to product variants in the cart that have the SKU `SHIRT`. |
|
209
|
|
|
210
|
<Note title="Warning" type="warning"> |
|
211
|
|
|
212
|
A target rule's `attribute` must be prefixed based on the `target_type`: use `items.` for item rules and `shipping_methods.` for shipping-method rules. For example, to target a product, set the `attribute` to `items.product.id`, not `product_id`. Refer to [Rule Attributes](../concepts/page.mdx#rule-attributes) for the full list of supported keys. |
|
213
|
|
|
214
|
</Note> |
|
215
|
|
|
216
|
--- |
|
217
|
|
|
218
|
## Buy Promotion Rules |
|
219
|
|
|
220
|
When the promotion’s type is `buyget`, you must specify the “buy X” condition. For example, a cart must have two shirts before the promotion can be applied. |
|
221
|
|
|
222
|
The application method has a collection of `PromotionRule` items to define the “buy X” rule. The `buy_rules` property in the `ApplicationMethod` represents this relation. |
|
223
|
|
|
224
|
 |
|
225
|
|
|
226
|
In this example, the cart must have two product variants with the SKU `SHIRT` for the promotion to be applied. |
|
227
|
|
|
228
|
<Note title="Warning" type="warning"> |
|
229
|
|
|
230
|
Like target rules, a buy rule's `attribute` must be prefixed based on the `target_type`: use `items.` for item rules and `shipping_methods.` for shipping-method rules. For example, to require a specific product, set the `attribute` to `items.product.id`, not `product_id`. Refer to [Rule Attributes](../concepts/page.mdx#rule-attributes) for the full list of supported keys. |
|
231
|
|
|
232
|
</Note> |
|
233
|
|
|
234
|
A `buyget` promotion only discounts a matching "Get Y" item that is already in the cart. It doesn't add the free product to the cart automatically. If the target item isn't in the cart, Medusa doesn't apply the promotion. This is true whether the promotion is automatic or the customer applies it with a code. |
|
235
|
|
|
236
|
--- |
|
237
|
|
|
238
|
## Maximum Quantity Restriction |
|
239
|
|
|
240
|
You can restrict how many items the promotion is applied to either at the item level or the cart level. |
|
241
|
|
|
242
|
### Item Level Restriction |
|
243
|
|
|
244
|
When the `allocation` property in the `ApplicationMethod` is set to `each`, you can set the `max_quantity` property of `ApplicationMethod` to limit how many quantities of each applicable item the promotion is applied to. |
|
245
|
|
|
246
|
For example, if the `max_quantity` property is set to `1` and the customer has a line item with quantity two in the cart, the promotion is only applied to one of them. |
|
247
|
|
|
248
|
```json title="Example Cart" |
|
249
|
{ |
|
250
|
"cart": { |
|
251
|
"items": [ |
|
252
|
{ |
|
253
|
"id": "item_1", |
|
254
|
"quantity": 2 // The promotion is applied to 1 of this item |
|
255
|
} |
|
256
|
] |
|
257
|
} |
|
258
|
} |
|
259
|
``` |
|
260
|
|
|
261
|
This condition is applied on the quantity of every applicable item in the cart. For example, if set to `1` and the customer has two applicable items in the cart, the promotion is applied to one of each of them. |
|
262
|
|
|
263
|
```json title="Example Cart" |
|
264
|
{ |
|
265
|
"cart": { |
|
266
|
"items": [ |
|
267
|
{ |
|
268
|
"id": "item_1", |
|
269
|
"quantity": 2 // The promotion is applied to 1 of this item |
|
270
|
}, |
|
271
|
{ |
|
272
|
"id": "item_2", |
|
273
|
"quantity": 3 // The promotion is applied to 1 of this item |
|
274
|
} |
|
275
|
] |
|
276
|
} |
|
277
|
} |
|
278
|
``` |
|
279
|
|
|
280
|
### Cart Level Restriction |
|
281
|
|
|
282
|
<Note> |
|
283
|
|
|
284
|
The `once` allocation type is available from [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0). |
|
285
|
|
|
286
|
</Note> |
|
287
|
|
|
288
|
When the `allocation` property in the `ApplicationMethod` is set to `once`, you must set the `max_quantity` property of `ApplicationMethod`. It limits how many items in total the promotion is applied to. |
|
289
|
|
|
290
|
In this scenario, the Promotion Module prioritizes which applicable items the promotion is applied to based on the following rules: |
|
291
|
|
|
292
|
1. Prioritize items with the lowest price. |
|
293
|
2. Distribute the promotion sequentially until the `max_quantity` is reached. |
|
294
|
|
|
295
|
#### Example 1 |
|
296
|
|
|
297
|
Consider: |
|
298
|
|
|
299
|
- A promotion whose application method has its `allocation` property set to `once` and `max_quantity` set to `2`. |
|
300
|
- A cart with three items having different prices, each with a quantity of `1`. |
|
301
|
|
|
302
|
The Promotion Module will apply the promotion to the two items with the lowest price. |
|
303
|
|
|
304
|
```json title="Example Cart" |
|
305
|
{ |
|
306
|
"cart": { |
|
307
|
"items": [ |
|
308
|
{ |
|
309
|
"id": "item_1", |
|
310
|
"price": 10, |
|
311
|
"quantity": 1 // The promotion is applied to this item |
|
312
|
}, |
|
313
|
{ |
|
314
|
"id": "item_2", |
|
315
|
"price": 20, |
|
316
|
"quantity": 1 // The promotion is applied to this item |
|
317
|
}, |
|
318
|
{ |
|
319
|
"id": "item_3", |
|
320
|
"price": 30, |
|
321
|
"quantity": 1 // The promotion is NOT applied to this item |
|
322
|
} |
|
323
|
] |
|
324
|
} |
|
325
|
} |
|
326
|
``` |
|
327
|
|
|
328
|
#### Example 2 |
|
329
|
|
|
330
|
Consider: |
|
331
|
|
|
332
|
- A promotion whose application method has its `allocation` property set to `once` and `max_quantity` set to `2`. |
|
333
|
- A cart with two items having different prices and quantities greater than `2`. |
|
334
|
|
|
335
|
The Promotion Module will try to apply the promotion to the item with the lowest price first: |
|
336
|
|
|
337
|
```json title="Example Cart" |
|
338
|
{ |
|
339
|
"cart": { |
|
340
|
"items": [ |
|
341
|
{ |
|
342
|
"id": "item_1", |
|
343
|
"price": 10, |
|
344
|
"quantity": 3 // The promotion is applied to 2 of this item |
|
345
|
}, |
|
346
|
{ |
|
347
|
"id": "item_2", |
|
348
|
"price": 20, |
|
349
|
"quantity": 4 // The promotion is NOT applied to this item |
|
350
|
} |
|
351
|
] |
|
352
|
} |
|
353
|
} |
|
354
|
``` |
|
355
|
|
|
356
|
Since that item has a quantity of `3`, the promotion is applied to `2` of that item, reaching the `max_quantity` limit. The promotion is not applied to the other item. |
|
357
|
|
|
358
|
#### Example 3 |
|
359
|
|
|
360
|
Consider: |
|
361
|
|
|
362
|
- A promotion whose application method has its `allocation` property set to `once` and `max_quantity` set to `5`. |
|
363
|
- A cart with two items having different prices and quantities less than `5`. |
|
364
|
|
|
365
|
The Promotion Module will try to apply the promotion to the item with the lowest price first: |
|
366
|
|
|
367
|
```json title="Example Cart" |
|
368
|
{ |
|
369
|
"cart": { |
|
370
|
"items": [ |
|
371
|
{ |
|
372
|
"id": "item_1", |
|
373
|
"price": 10, |
|
374
|
"quantity": 3 // The promotion is applied to all 3 of this item |
|
375
|
}, |
|
376
|
{ |
|
377
|
"id": "item_2", |
|
378
|
"price": 20, |
|
379
|
"quantity": 4 // The promotion is applied to 2 of this item |
|
380
|
} |
|
381
|
] |
|
382
|
} |
|
383
|
} |
|
384
|
``` |
|
385
|
|
|
386
|
The promotion is applied to all `3` quantities of the item with the lowest price. Since the `max_quantity` is `5`, the promotion is applied to `2` quantities of the other item, reaching the `max_quantity` limit. |