Skip to content

Commit

Permalink
Merge pull request #97 from spree/remove-promo-code-without-name
Browse files Browse the repository at this point in the history
 Add possibility to remove all promo codes without specific code name
  • Loading branch information
tniezg authored May 15, 2019
2 parents 32482ef + 3d4f751 commit a92f2c7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ Removes a coupon code from the Cart.

__Required token:__ [Bearer token](#bearer-token) or [Order token](#order-token)

__Parameters schema:__
__Optional parameters schema:__
```ts
coupon_code: string
coupon_code?: string
```

__Success response schema:__ [Success schema](#success-schema)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spree/storefront-api-v2-sdk",
"version": "2.1.4",
"version": "2.2.0",
"description": "Node module to easily integrate your JavaScript or TypeScript application with Spree API V2. You can create an entirely custom Storefront in JS/TS with this package including one page checkout, Single Page Apps, PWAs and so on",
"engines": {
"node": ">=8",
Expand Down
12 changes: 10 additions & 2 deletions src/endpoints/Cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ export default class Cart extends Http {
return await this.spreeResponse(PATCH, Routes.cartApplyCodePath(), token, params) as IOrderResult
}

public async removeCouponCode(token: IToken, code: string, params: IQuery = {}): Promise<IOrderResult> {
return await this.spreeResponse(PATCH, Routes.cartRemoveCodePath(code), token, params) as IOrderResult
public async removeCouponCode(token: IToken, code: string = null, params: IQuery = {}): Promise<IOrderResult> {
let route = ''

if (code !== null) {
route = Routes.cartRemoveCodePath(code)
} else {
route = Routes.cartRemoveCodePath('')
}

return await this.spreeResponse(DELETE, route, token, params) as IOrderResult
}

public async estimateShippingMethods(
Expand Down
2 changes: 1 addition & 1 deletion src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Routes = {
cartEmptyPath: () => `${storefrontPath}/cart/empty`,
cartSetItemQuantity: () => `${storefrontPath}/cart/set_quantity`,
cartApplyCodePath: () => `${storefrontPath}/cart/apply_coupon_code`,
cartRemoveCodePath: (code: string) => `${storefrontPath}/cart/remove_coupon_code/${code}`,
cartRemoveCodePath: (code?: string) => `${storefrontPath}/cart/remove_coupon_code/${code}`,
cartEstimateShippingMethodsPath: () => `${storefrontPath}/cart/estimate_shipping_rates`,
checkoutPath: () => `${storefrontPath}/checkout`,
checkoutNextPath: () => `${storefrontPath}/checkout/next`,
Expand Down
2 changes: 1 addition & 1 deletion types/endpoints/Cart.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export default class Cart extends Http {
emptyCart(token: IToken, params?: IQuery): Promise<IOrderResult>;
setQuantity(token: IToken, params: SetQuantity): Promise<IOrderResult>;
applyCouponCode(token: IToken, params: CouponCode): Promise<IOrderResult>;
removeCouponCode(token: IToken, code: string, params?: IQuery): Promise<IOrderResult>;
removeCouponCode(token: IToken, code?: string, params?: IQuery): Promise<IOrderResult>;
estimateShippingMethods(token: IToken, params: EstimateShippingMethods): Promise<IEstimatedShippingMethodsResult>;
}
2 changes: 1 addition & 1 deletion types/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export declare const Routes: {
cartEmptyPath: () => string;
cartSetItemQuantity: () => string;
cartApplyCodePath: () => string;
cartRemoveCodePath: (code: string) => string;
cartRemoveCodePath: (code?: string) => string;
cartEstimateShippingMethodsPath: () => string;
checkoutPath: () => string;
checkoutNextPath: () => string;
Expand Down

0 comments on commit a92f2c7

Please sign in to comment.