Classes

Product

Basic product

CartItem

cart item extend product

Promo

Rule processor

Cart

Cart

CartDiscount

Rule discount on cart sub total

ExclusiveDiscount

discount per item

Product

Basic product

Kind: global class

new Product(id, name, price)

create a new product

Param Type
id Number
name String
price Number

CartItem

cart item extend product

Kind: global class

new CartItem(product, quantity)

create a new cart item

Param Type
product Product
quantity Number

Promo

Rule processor

Kind: global class

new Promo(...rules)

create new promo session

Param Type
...rules CartDiscount | ExclusiveDiscount

promo.exclusiveDiscount(item) ⇒ Number

apply exclusive rules for a item

Kind: instance method of Promo

Param Type
item CartItem

promo.cartDiscount(subTotal) ⇒ Number

apply cart rules for a sub total

Kind: instance method of Promo

Param Type
subTotal Number

Cart

Cart

Kind: global class

new Cart(promo)

create a cart

Param Type
promo Promo

cart.scan(product) ⇒ this

scan item

Kind: instance method of Cart

Param Type
product Product

cart.subTotal() ⇒ number

cart sub total before cart discount

Kind: instance method of Cart

cart.payable() ⇒ Number

apply cart discount

Kind: instance method of Cart
Returns: Number - - final payable amount

CartDiscount

Rule discount on cart sub total

Kind: global class

new CartDiscount(min, max, discount, flat)

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);|          | 

cartDiscount.discount(subTotal) ⇒ Number

calculate discount on cart sub total

Kind: instance method of CartDiscount
Returns: Number - - discount

Param Type
subTotal Cart.total

ExclusiveDiscount

discount per item

Kind: global class

new ExclusiveDiscount(pid, quantity, price)

discount applicable when ordering certain item quantity

Param Type
pid Number
quantity Number
price Number

exclusiveDiscount.discount(item) ⇒ Number

calculate discount per items

Kind: instance method of ExclusiveDiscount
Returns: Number - - discount

Param Type
item CartItem