- Product
Basic product
- CartItem
cart item extend product
- Promo
Rule processor
- Cart
Cart
- CartDiscount
Rule discount on cart sub total
- ExclusiveDiscount
discount per item
Basic product
create a new product
Param | Type |
---|---|
id | Number |
name | String |
price | Number |
cart item extend product
create a new cart item
Param | Type |
---|---|
product | Product |
quantity | Number |
Rule processor
Kind: global class
- Promo
- new Promo(...rules)
- .exclusiveDiscount(item) ⇒
Number
- .cartDiscount(subTotal) ⇒
Number
create new promo session
Param | Type |
---|---|
...rules | CartDiscount | ExclusiveDiscount |
apply exclusive rules for a item
Kind: instance method of Promo
Param | Type |
---|---|
item | CartItem |
apply cart rules for a sub total
Kind: instance method of Promo
Param | Type |
---|---|
subTotal | Number |
Cart
Kind: global class
- Cart
- new Cart(promo)
- .scan(product) ⇒
this
- .subTotal() ⇒
number
- .payable() ⇒
Number
create a cart
Param | Type |
---|---|
promo | Promo |
scan item
Kind: instance method of Cart
Param | Type |
---|---|
product | Product |
cart sub total before cart discount
Kind: instance method of Cart
apply cart discount
Kind: instance method of Cart
Returns: Number
- - final payable amount
Rule discount on cart sub total
Kind: global class
flat discount will be called at the end of all other discounts in case of multiple flat discount higher severity flat discount will be applicable
Param | Type | Description |
---|---|---|
min | Number |
min amount |
max | Number |
max amount |
discount | Number |
amount or fraction ration |
flat | Boolean |
enable discount as amount |
Example
| Min | Max | discount | code | comment |
|------|-------|----------|---------------------------------|----------|
| 10$ | 30$ | 10% | new CartDiscount(10, 30, 0.1); | |
| 30$ | 50$ | 20% | new CartDiscount(30, 50, 0.2); | |
| 50$ | any | 8$ | new CartDiscount(10, 20, 8, 1);| |
calculate discount on cart sub total
Kind: instance method of CartDiscount
Returns: Number
- - discount
Param | Type |
---|---|
subTotal | Cart.total |
discount per item
Kind: global class
discount applicable when ordering certain item quantity
Param | Type |
---|---|
pid | Number |
quantity | Number |
price | Number |
calculate discount per items
Kind: instance method of ExclusiveDiscount
Returns: Number
- - discount
Param | Type |
---|---|
item | CartItem |