Skip to content
This repository was archived by the owner on May 21, 2020. It is now read-only.
Open
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
56 changes: 56 additions & 0 deletions packages/core/rfcs/discount-getters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Discount / coupons getters

## Motivation

There is no possibility to read discounts from the cart. We are not able to display discounted total price or even an information about applied discount code. Suggestion bellow:

```ts
export interface CartGetters<CART, CART_ITEM, DISCOUNT> {
// ...
// new ones:

getDiscount: () => DISCOUNT; // don't think if it's needed
getDiscountId: () => string;
getDiscountedTotals: () => AgnosticTotals;
getDiscountName: () => string;
getDiscountValue: () => number;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return string eg "-15%" "-20 złotych"

getDiscountType: () => string; // fixed or percentage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not necessary


[getterName: string]: (element: any, options?: any) => unknown;
}
```

Also I'm thinking about separated getters, which has even more sense as you can have multiple discounts applied to the cart.

```ts
export interface DiscountGetters {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be different between platforms

getId: () => string;
getName: () => string;
getValue: () => number;
getType: () => string; // fixed or percentage
}

export interface CartGetters<CART, CART_ITEM, DISCOUNT> {
// ...
// new ones:

getDiscounts: () => DISCOUNT[]; // now you can use discountGetters on each
getDiscountedTotals: () => AgnosticTotals; // still useful

[getterName: string]: (element: any, options?: any) => unknown;
}
```

And also we don't need a coupon property anomore:

```ts
export interface UseCart {
// ...
coupon: ComputedProperty<COUPON | null>; // to be removed
// ...
}
```

## Migration process

Prety straightforward, just implement a new getters.