From ae41f9dbd77ed27f161fb2e54cc815e7098f9ce5 Mon Sep 17 00:00:00 2001 From: Ella Nan <38847123+ellanan@users.noreply.github.com> Date: Tue, 23 Sep 2025 10:08:13 -0400 Subject: [PATCH] fix: pass currency in header in AddPromotion --- src/endpoints/cart.js | 20 ++++++++++++++++---- src/types/cart.d.ts | 13 +++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/endpoints/cart.js b/src/endpoints/cart.js index 2a058f2..01559d3 100644 --- a/src/endpoints/cart.js +++ b/src/endpoints/cart.js @@ -202,14 +202,26 @@ class CartEndpoint extends BaseExtend { }) } - AddPromotion(code, token = null) { - const body = buildCartItemData(code, null, 'promotion_item') + AddPromotion(code, token=null, currency = null) { + + const additionalHeaders = currency + ? { 'X-MOLTIN-CURRENCY': currency } + : {} return this.request.send( `${this.endpoint}/${this.cartId}/items`, 'POST', - body, - token + { + data: { + type: 'promotion_item', + code + } + }, + token, + null, + null, + null, + additionalHeaders ) } diff --git a/src/types/cart.d.ts b/src/types/cart.d.ts index 78a71fd..b07de4a 100644 --- a/src/types/cart.d.ts +++ b/src/types/cart.d.ts @@ -350,15 +350,6 @@ export interface CartEndpoint ShippingGroup: CartShippingGroupBase ): Promise - /** - * Add Promotion to Cart - * Description: You can use the Promotions API to apply discounts to your cart as a special cart item type. - * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/add-promotion-to-cart.html - * @param code the promotion code. - * @param token a customer token to apply customer specific promotions. - */ - AddPromotion(code: string, token?: string): Promise - /** * Get a Cart by reference * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-checkout/carts/get-a-cart.html @@ -438,8 +429,10 @@ export interface CartEndpoint * Description: You can use the Promotions API to apply discounts to your cart as a special cart item type. * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/add-promotion-to-cart.html * @param code the promotion code. + * @param token a customer token to apply customer specific promotions. + * @param currency the currency to apply the promotion in. */ - AddPromotion(code: string): Promise + AddPromotion(code: string, token?: string, currency?: string): Promise /** * Remove promotion from Cart