Skip to content

Latest commit

 

History

History
1417 lines (890 loc) · 39.4 KB

api.md

File metadata and controls

1417 lines (890 loc) · 39.4 KB

Modules

Cestino/BasicCartService

Fetch masterdata from an external resource and put it to the cart model.

Cestino

A basic shopping cart implementation in javascript.

Cestino/PriceFormatter

Formatting integers to decimal currency representation.

Cestino/Util

Utilities used to check and modify basic data types.

Classes

BasicCartService
Cart
CartPosition
Product
ProductQuantity
ProductFeature
ShippingGroup
PriceFormatter

Cestino/BasicCartService

Fetch masterdata from an external resource and put it to the cart model.

Requires: module:bluebird, module:atomic


Cestino/BasicCartService.create(options) ⇒ BasicCartService

Creates an object to load masterdata from a server.

Kind: static method of Cestino/BasicCartService

Param Type
options Object

Cestino

A basic shopping cart implementation in javascript.

Requires: Cestino/BasicCartService, Cestino/PriceFormatter, Cestino/Util


Cestino.Util

Kind: static property of Cestino
See: Cestino/Util


Cestino.PriceFormatter

Kind: static property of Cestino
See: Cestino/PriceFormatter


Cestino.BasicCartService

Kind: static property of Cestino
See: Cestino/BasicCartService


Cestino.Product

Kind: static property of Cestino


Product.create ⇒ Product

Creates an object of type Cart.Product

Kind: static property of Product

Param Type
id String
title String
price Integer

Product.extendWith ⇒ Product

Extends class Product by passed constructor

Kind: static property of Product

Param Type
subclassConstructor *

Cestino.ProductFeature

Kind: static property of Cestino


ProductFeature.create ⇒ ProductFeature

Creates an object of type Cart.ProductFeature

Kind: static property of ProductFeature

Param Type
id String | Integer
label String
price Integer

ProductFeature.extendWith ⇒ ProductFeature

Extends class ProductFeature by passed constructor

Kind: static property of ProductFeature

Param Type
subclassConstructor *

Cestino.ProductQuantity

Kind: static property of Cestino


ProductQuantity.create ⇒ ProductQuantity

Creates an object of type Cart.ProductQuantity

Kind: static property of ProductQuantity

Param Type
amount Integer
dimX Integer
dimY Integer
dimZ Integer

ProductQuantity.extendWith ⇒ ProductQuantity

Extends class ProductQuantity by passed constructor

Kind: static property of ProductQuantity

Param Type
subclassConstructor *

Cestino.ShippingGroup

Kind: static property of Cestino


ShippingGroup.create ⇒ ShippingGroup

Creates an object of type Cart.ShippingGroup

Kind: static property of ShippingGroup

Param Type
name String

ShippingGroup.extendWith ⇒ ShippingGroup

Extends class ShippingGroup by passed constructor

Kind: static property of ShippingGroup

Param Type
subclassConstructor *

Cestino.create(oService) ⇒ Cart

Creates an object of type Cart; The main object.

Kind: static method of Cestino

Param Type
oService Object

Cestino.overridePositionCalculation(fn)

Use this to override the method for calculating a cart-position

Kind: static method of Cestino

Param Type
fn function

"add" (position)

Event reporting that a product has been add to cart.

Kind: event emitted by Cestino

Param Type
position CartPosition

"remove" (position)

Event reporting that a product has been removed from cart.

Kind: event emitted by Cestino

Param Type
position CartPosition

"change" (position)

Event reporting that a product-position in cart has been changed.

Kind: event emitted by Cestino

Param Type
position CartPosition

"load" (cart)

Event reporting that the cart has been load from json.

Kind: event emitted by Cestino

Param Type
cart Cart

Cestino~loadCallback : function

Callback that will be fired, if registered and the cart has been load from json.

Kind: inner abstract typedef of Cestino

Param Type
cart Cart

Cestino~addProductCallback : function

Callback that will be fired, if registered and a product has been add to cart.

Kind: inner abstract typedef of Cestino

Param Type
position CartPosition

Cestino~removeProductCallback : function

Callback that will be fired, if registered and a product has been removed from cart.

Kind: inner abstract typedef of Cestino

Param Type
position CartPosition

Cestino~changePositionCallback : function

Callback that will be fired, if registered and a product-position in cart has been changed.

Kind: inner abstract typedef of Cestino

Param Type
position CartPosition

Cestino/PriceFormatter

Formatting integers to decimal currency representation.

Requires: Cestino/Util


Cestino/PriceFormatter.create(decimalSeparator, thousandsSeparator, decimalCount) ⇒ PriceFormatter

Creates an object to convert integer price to decimal price (e. g. cents to dollar/euro).

Kind: static method of Cestino/PriceFormatter

Param Type
decimalSeparator String
thousandsSeparator String
decimalCount Number

Cestino/Util

Utilities used to check and modify basic data types.


Cestino/Util.isNumber(n) ⇒ Boolean

Is passed data a number?

Kind: static method of Cestino/Util
Access: public

Param Type
n *

Cestino/Util.isInt(n) ⇒ Boolean

Is passed data of type Integer?

Kind: static method of Cestino/Util
Access: public

Param Type
n *

Cestino/Util.isFloat(n) ⇒ Boolean

Is passed data of type Float?

Kind: static method of Cestino/Util
Access: public

Param Type
n *

Cestino/Util.isEmpty(val) ⇒ Boolean

Is passed data empty?

Kind: static method of Cestino/Util
Access: public

Param Type
val *

Cestino/Util.lpad(str, width, padStr) ⇒ String

Pad a string on left side to a certain length with another string.

Kind: static method of Cestino/Util
Access: public

Param Type
str String
width Integer
padStr String

Cestino/Util.round(number) ⇒ Integer

Other than Math.round(), this function rounds to nearest away from zero

Kind: static method of Cestino/Util
Access: public

Param Type
number Number

BasicCartService ℗

Kind: global class
Access: private


new BasicCartService(options)

Service used to fetch and put master data of products into the model.

Param Type
options Object

basicCartService. options : Object

Kind: instance property of BasicCartService


basicCartService.setProductDataToCart(oCart) ⇒ Promise

Updates the cart with actual valid information about products.

Kind: instance method of BasicCartService
Access: public

Param Type
oCart Cart

Cart ℗

Kind: global class
Access: private


new Cart(oService)

Class to manage a shopping cart. The cart only supports product-positions separated by shipping-groups. All prices were handled without tax; Extend the model to consider tax calculation. You have to implement costs of payment on your own.

Param Type
oService Object

cart. positionId : Integer

Kind: instance property of Cart


cart. oCartService : Object

Kind: instance property of Cart


cart. positions : Array.<CartPosition>

Kind: instance property of Cart


cart. shippingGroups : Object

Kind: instance property of Cart
Access: private


cart. listener : Object

Kind: instance property of Cart


cart.walk(fnCallback) ⇒ Cart

Walks through all positions of the cart, calls passed function and puts position and group to it.

Kind: instance method of Cart
Access: public

Param Type
fnCallback function

cart.toJSON() ⇒ String

Returns a json-representation of the cart; Only necessary information will be transported to the json-string.

Kind: instance method of Cart
Access: public


cart.fromJSON(sJSON) ⇒ Cart

Build the cart from JSON

Kind: instance method of Cart
Emits: load
Access: public

Param Type
sJSON String

cart.add(oProduct, oQuantity, [oShippingGroup], [aProductFeatures]) ⇒ String

Creates a position in the cart

Kind: instance method of Cart
Returns: String - Id of generated Position
Emits: add
Access: public

Param Type Default
oProduct Product
oQuantity ProductQuantity | Integer
[oShippingGroup] ShippingGroup | String ""
[aProductFeatures] Array.<ProductFeature> []

cart.on(kind, fnListener) ⇒ Cart

Adds a function that will be invoke when a specific event occurs.

Kind: instance method of Cart
Returns: Cart - this-reference for method chaining ...
Access: public

Param Type Description
kind String "add" (product), "remove" (product), "change" (position) or "load" (cart)
fnListener loadCallback | addProductCallback | removeProductCallback | changePositionCallback

cart.off(kind, fnListener) ⇒ Cart

Removes a function that will be invoke on specific action.

Kind: instance method of Cart
Returns: Cart - this-reference for method chaining ...
Access: public

Param Type
kind string
fnListener loadCallback | addProductCallback | removeProductCallback | changePositionCallback

cart.getShippingGroups() ⇒ Array.<String>

Get all defined groups.

Kind: instance method of Cart
Access: public


cart.getShippingGroupByName(sShippingGroup) ⇒ false | ShippingGroup

Returns a shipping-group by name.

Kind: instance method of Cart

Param Type
sShippingGroup String | ShippingGroup

cart.getPositionsOfGroup(sShippingGroup) ⇒ Array.<CartPosition>

Returns all positions of the pssed group.

Kind: instance method of Cart
Access: public

Param Type
sShippingGroup String | ShippingGroup

cart.calculateGroup(sShippingGroup, includeShippingGroupCost) ⇒ Integer

Calculates the subtotal of a shipping-group.

Kind: instance method of Cart
Access: public

Param Type
sShippingGroup String | ShippingGroup
includeShippingGroupCost Boolean

cart.calculate(includeShippingGroupCost) ⇒ Integer

Calculates the total of the whole shopping-cart.

Kind: instance method of Cart
Access: public

Param Type
includeShippingGroupCost Boolean

cart.deletePosition(sIdCartPosition) ⇒ CartPosition

Delete a cart-position by id.

Kind: instance method of Cart
Returns: CartPosition - The position that was removed
Emits: remove
Access: public

Param Type
sIdCartPosition String

cart.getPositionById(sIdCartPosition) ⇒ CartPosition

Tries to get a position from given id.

Kind: instance method of Cart
Access: public

Param Type
sIdCartPosition String

CartPosition ℗

Kind: global class
Access: private


new CartPosition(sId, oProduct, aFeatures, oQuantity)

The cart reference will be injected on instancing separately.

Param Type
sId String
oProduct Product
aFeatures Array.<ProductFeature>
oQuantity ProductQuantity

cartPosition.getId() ⇒ String

Kind: instance method of CartPosition


cartPosition.getProduct() ⇒ Product

Kind: instance method of CartPosition


cartPosition.getFeatures() ⇒ Array.<ProductFeature>

Kind: instance method of CartPosition


cartPosition.getQuantity() ⇒ ProductQuantity

Kind: instance method of CartPosition


cartPosition.getCart() ⇒ Cart

Kind: instance method of CartPosition


cartPosition.replaceQuantity(oQuantity) ⇒ CartPosition

Replacing the product quantity in cart position.

Kind: instance method of CartPosition
Returns: CartPosition - this-reference for method chaining ...
Emits: change
Access: public

Param Type
oQuantity ProductQuantity

cartPosition.incrementAmount(amount) ⇒ CartPosition

Incrementing amount of cart position.

Kind: instance method of CartPosition
Emits: change
Access: public

Param Type
amount Integer

cartPosition.decrementAmount(amount) ⇒ CartPosition

Decrementing amount of cart position.

Kind: instance method of CartPosition
Emits: change
Access: public

Param Type
amount Integer

cartPosition.calculate() ⇒ Integer

Returns calculated price in cents.

Kind: instance method of CartPosition
Access: public


Product ℗

Kind: global class
Access: private


new Cart.Product(id, title, price)

Class to describe a product that was add to cart.

Param Type
id String
title String
price Integer

product.getId() ⇒ String

Kind: instance method of Product


product.getTitle() ⇒ String

Returns the title of the product.

Kind: instance method of Product


product.getPrice([oCartPosition]) ⇒ Integer

Returns the price of the product. Overwrite this method to modify the cart calculation to your needs (e. g. to add tax)

Kind: instance method of Product

Param Type
[oCartPosition] CartPosition

ProductQuantity ℗

Kind: global class
Access: private


new Cart.ProductQuantity(amount, [dimX], [dimY], [dimZ])

Class to represent the quantity structure of a product in a position. No limits or ranges will be checked, you have to implement it by yourself!

Param Type
amount Integer
[dimX] Integer
[dimY] Integer
[dimZ] Integer

productQuantity.getAmount() ⇒ Integer

Kind: instance method of ProductQuantity


productQuantity.getLength() ⇒ Integer

Kind: instance method of ProductQuantity


productQuantity.getWidth() ⇒ Integer

Kind: instance method of ProductQuantity


productQuantity.getHeight() ⇒ Integer

Kind: instance method of ProductQuantity


productQuantity.getDepth() ⇒ Integer

Kind: instance method of ProductQuantity


productQuantity.getFactor([oCartPosition]) ⇒ Integer

Calculates the quantity factor for the product. Overwrite this method to modify the cart calculation to your needs (e. g. to convert into another scale unit).

Kind: instance method of ProductQuantity

Param Type
[oCartPosition] CartPosition

ProductFeature ℗

Kind: global class
Access: private


new Cart.ProductFeature(id, label, [price])

Class to describe a selected feature of a product.

Param Type
id String | Integer
label String
[price] Integer

productFeature.getId() ⇒ String

Kind: instance method of ProductFeature


productFeature.getPrice([oCartPosition]) ⇒ Integer

Returns the price of a feature selected to a product. Overwrite this method to modify the cart calculation to your needs

Kind: instance method of ProductFeature

Param Type
[oCartPosition] CartPosition

productFeature.getLabel() ⇒ Integer

Returns the label of a feature selected to a product.

Kind: instance method of ProductFeature


ShippingGroup ℗

Kind: global class
Access: private


new Cart.ShippingGroup([sName])

Represents information about a shipping group

Param Type
[sName] String

shippingGroup. name : String

Kind: instance property of ShippingGroup
Access: private


shippingGroup. cart : Cart

Kind: instance property of ShippingGroup
Access: private


shippingGroup. price : Integer

Kind: instance property of ShippingGroup
Access: private


shippingGroup.calculate(includeShippingGroupCost) ⇒ Integer

Returns the cost for the whole Shipping group

Kind: instance method of ShippingGroup

Param Type
includeShippingGroupCost Boolean

shippingGroup.setPrice(price) ⇒ ShippingGroup

Sets the cost for shipping of a shipping group.

Kind: instance method of ShippingGroup

Param Type
price Integer

shippingGroup.getPrice() ⇒ Integer

Returns the shipping cost for the group. Overwrite this method to add cost for shipping of a shipping group. You can access the current cart through method-call "this.getCart()".

Kind: instance method of ShippingGroup


shippingGroup.getName() ⇒ String

Returns the name of this shipping group.

Kind: instance method of ShippingGroup


shippingGroup.getCart() ⇒ Cart

Returns the cart this shipping group belongs to.

Kind: instance method of ShippingGroup


PriceFormatter ℗

Kind: global class
Access: private


new PriceFormatter(decimalSeparator, thousandsSeparator, decimalCount)

Creates an object to convert integer price to decimal price (e. g. cents to dollar/euro).

Param Type
decimalSeparator String
thousandsSeparator String
decimalCount Integer

priceFormatter. decimalCount : Integer

Kind: instance property of PriceFormatter


priceFormatter. thousandsSeparator : String

Kind: instance property of PriceFormatter


priceFormatter. decimalSeparator : String

Kind: instance property of PriceFormatter


PriceFormatter.format(int) ⇒ String

Converts the passed integer value into configured format.

Kind: static method of PriceFormatter
Access: private

Param Type
int Integer