From 13142235e60d739e79b1cdf3eac29c3dd7699080 Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Fri, 17 Apr 2020 17:05:31 +0200 Subject: [PATCH 1/2] discount getters --- packages/core/rfcs/discount-getters.md | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 packages/core/rfcs/discount-getters.md diff --git a/packages/core/rfcs/discount-getters.md b/packages/core/rfcs/discount-getters.md new file mode 100644 index 000000000..969ba08fd --- /dev/null +++ b/packages/core/rfcs/discount-getters.md @@ -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 { + // ... + // new ones: + + getDiscount: () => DISCOUNT; // don't think if it's needed + getDiscountId: () => string; + getDiscountedTotals: () => AgnosticTotals; + getDiscountName: () => string; + getDiscountValue: () => number; + getDiscountType: () => string; // fixed or percentage + + [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 { + getId: () => string; + getName: () => string; + getValue: () => number; + getType: () => string; // fixed or percentage +} + +export interface CartGetters { + // ... + // 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; + // ... +} +``` + +## Migration process + +Prety straightforward, just implement a new getters. From a280600db0a72c84d3f89c3f3892c9b6db49a97b Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Fri, 17 Apr 2020 17:06:42 +0200 Subject: [PATCH 2/2] discount getters --- packages/core/rfcs/discount-getters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/rfcs/discount-getters.md b/packages/core/rfcs/discount-getters.md index 969ba08fd..c5b49c122 100644 --- a/packages/core/rfcs/discount-getters.md +++ b/packages/core/rfcs/discount-getters.md @@ -46,7 +46,7 @@ And also we don't need a coupon property anomore: ```ts export interface UseCart { // ... - coupon: ComputedProperty; + coupon: ComputedProperty; // to be removed // ... } ```