Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/endpoints/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
13 changes: 3 additions & 10 deletions src/types/cart.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,6 @@ export interface CartEndpoint
ShippingGroup: CartShippingGroupBase
): Promise<ShippingGroupResponse>

/**
* 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<CartItemsResponse>

/**
* Get a Cart by reference
* DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-checkout/carts/get-a-cart.html
Expand Down Expand Up @@ -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<CartItemsResponse>
AddPromotion(code: string, token?: string, currency?: string): Promise<CartItemsResponse>

/**
* Remove promotion from Cart
Expand Down