File tree Expand file tree Collapse file tree 5 files changed +78
-14
lines changed
integration-tests/http/__tests__/cart/store
modules/link-modules/src/definitions Expand file tree Collapse file tree 5 files changed +78
-14
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @medusajs/link-modules " : patch
3
+ " @medusajs/core-flows " : patch
4
+ ---
5
+
6
+ fix(link-modules,core-flows): Carry over cart promotions to order promotions
Original file line number Diff line number Diff line change @@ -1252,6 +1252,60 @@ medusaIntegrationTestRunner({
1252
1252
)
1253
1253
} )
1254
1254
1255
+ it ( "should successfully complete cart with promotions" , async ( ) => {
1256
+ const oldCart = (
1257
+ await api . get ( `/store/carts/${ cart . id } ` , storeHeaders )
1258
+ ) . data . cart
1259
+
1260
+ createCartCreditLinesWorkflow . run ( {
1261
+ input : [
1262
+ {
1263
+ cart_id : oldCart . id ,
1264
+ amount : oldCart . total ,
1265
+ currency_code : "usd" ,
1266
+ reference : "test" ,
1267
+ reference_id : "test" ,
1268
+ } ,
1269
+ ] ,
1270
+ container : appContainer ,
1271
+ } )
1272
+
1273
+ const cartResponse = await api . post (
1274
+ `/store/carts/${ cart . id } /complete` ,
1275
+ { } ,
1276
+ storeHeaders
1277
+ )
1278
+
1279
+ const orderResponse = await api . get (
1280
+ `/store/orders/${ cartResponse . data . order . id } ?fields=+promotions.*` ,
1281
+ storeHeaders
1282
+ )
1283
+
1284
+ expect ( cartResponse . status ) . toEqual ( 200 )
1285
+ expect ( orderResponse . data . order ) . toEqual (
1286
+ expect . objectContaining ( {
1287
+ promotions : [
1288
+ expect . objectContaining ( {
1289
+ code : promotion . code ,
1290
+ } ) ,
1291
+ ] ,
1292
+ items : expect . arrayContaining ( [
1293
+ expect . objectContaining ( {
1294
+ unit_price : 1500 ,
1295
+ compare_at_unit_price : null ,
1296
+ quantity : 1 ,
1297
+ adjustments : expect . arrayContaining ( [
1298
+ expect . objectContaining ( {
1299
+ amount : 100 ,
1300
+ code : promotion . code ,
1301
+ } ) ,
1302
+ ] ) ,
1303
+ } ) ,
1304
+ ] ) ,
1305
+ } )
1306
+ )
1307
+ } )
1308
+
1255
1309
it ( "should successfully complete cart without shipping for digital products" , async ( ) => {
1256
1310
/**
1257
1311
* Product has a shipping profile so cart item should not require shipping
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export const cartFieldsForRefreshSteps = [
36
36
"shipping_methods.tax_lines.*" ,
37
37
"customer.*" ,
38
38
"customer.groups.*" ,
39
+ "promotions.id" ,
39
40
"promotions.code" ,
40
41
"payment_collection.id" ,
41
42
"payment_collection.raw_amount" ,
@@ -105,6 +106,7 @@ export const completeCartFields = [
105
106
"credit_lines.*" ,
106
107
"payment_collection.*" ,
107
108
"payment_collection.payment_sessions.*" ,
109
+ "promotions.id" ,
108
110
"items.variant.id" ,
109
111
"items.variant.product.id" ,
110
112
"items.variant.product.is_giftcard" ,
Original file line number Diff line number Diff line change 1
1
import {
2
2
CartCreditLineDTO ,
3
3
CartWorkflowDTO ,
4
+ LinkDefinition ,
5
+ PromotionDTO ,
4
6
UsageComputedActions ,
5
7
} from "@medusajs/framework/types"
6
8
import {
@@ -326,13 +328,22 @@ export const completeCartWorkflow = createWorkflow(
326
328
const linksToCreate = transform (
327
329
{ cart, createdOrder } ,
328
330
( { cart, createdOrder } ) => {
329
- const links : Record < string , any > [ ] = [
331
+ const links : LinkDefinition [ ] = [
330
332
{
331
333
[ Modules . ORDER ] : { order_id : createdOrder . id } ,
332
334
[ Modules . CART ] : { cart_id : cart . id } ,
333
335
} ,
334
336
]
335
337
338
+ if ( cart . promotions ?. length ) {
339
+ cart . promotions . forEach ( ( promotion : PromotionDTO ) => {
340
+ links . push ( {
341
+ [ Modules . ORDER ] : { order_id : createdOrder . id } ,
342
+ [ Modules . PROMOTION ] : { promotion_id : promotion . id } ,
343
+ } )
344
+ } )
345
+ }
346
+
336
347
if ( isDefined ( cart . payment_collection ?. id ) ) {
337
348
links . push ( {
338
349
[ Modules . ORDER ] : { order_id : createdOrder . id } ,
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ export const OrderPromotion: ModuleJoinerConfig = {
32
32
entity : "Promotion" ,
33
33
primaryKey : "id" ,
34
34
foreignKey : "promotion_id" ,
35
- alias : "promotion " ,
35
+ alias : "promotions " ,
36
36
args : {
37
37
methodSuffix : "Promotions" ,
38
38
} ,
@@ -44,8 +44,8 @@ export const OrderPromotion: ModuleJoinerConfig = {
44
44
serviceName : Modules . ORDER ,
45
45
entity : "Order" ,
46
46
fieldAlias : {
47
- promotion : {
48
- path : "promotion_link.promotion " ,
47
+ promotions : {
48
+ path : "promotion_link.promotions " ,
49
49
isList : true ,
50
50
} ,
51
51
} ,
@@ -54,16 +54,7 @@ export const OrderPromotion: ModuleJoinerConfig = {
54
54
primaryKey : "order_id" ,
55
55
foreignKey : "id" ,
56
56
alias : "promotion_link" ,
57
- } ,
58
- } ,
59
- {
60
- serviceName : Modules . PROMOTION ,
61
- entity : "Promotion" ,
62
- relationship : {
63
- serviceName : LINKS . OrderPromotion ,
64
- primaryKey : "promotion_id" ,
65
- foreignKey : "id" ,
66
- alias : "order_link" ,
57
+ isList : true ,
67
58
} ,
68
59
} ,
69
60
] ,
You can’t perform that action at this time.
0 commit comments