- 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.
- BasicCartService ℗
- Cart ℗
- CartPosition ℗
- Product ℗
- ProductQuantity ℗
- ProductFeature ℗
- ShippingGroup ℗
- PriceFormatter ℗
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 |
A basic shopping cart implementation in javascript.
Requires: Cestino/BasicCartService
, Cestino/PriceFormatter
, Cestino/Util
- Cestino
- static
- inner
- "add" (position)
- "remove" (position)
- "change" (position)
- "load" (cart)
- ~loadCallback :
function
- ~addProductCallback :
function
- ~removeProductCallback :
function
- ~changePositionCallback :
function
Kind: static property of Cestino
See: Cestino/Util
Kind: static property of Cestino
See: Cestino/PriceFormatter
Kind: static property of Cestino
See: Cestino/BasicCartService
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 | * |
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 | * |
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 | * |
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 |
Use this to override the method for calculating a cart-position
Kind: static method of Cestino
Param | Type |
---|---|
fn | function |
Event reporting that a product has been add to cart.
Kind: event emitted by Cestino
Param | Type |
---|---|
position | CartPosition |
Event reporting that a product has been removed from cart.
Kind: event emitted by Cestino
Param | Type |
---|---|
position | CartPosition |
Event reporting that a product-position in cart has been changed.
Kind: event emitted by Cestino
Param | Type |
---|---|
position | CartPosition |
Event reporting that the cart has been load from json.
Kind: event emitted by Cestino
Param | Type |
---|---|
cart | Cart |
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 |
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 |
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 |
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 |
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 |
Utilities used to check and modify basic data types.
- Cestino/Util
- .isNumber(n) ⇒
Boolean
- .isInt(n) ⇒
Boolean
- .isFloat(n) ⇒
Boolean
- .isEmpty(val) ⇒
Boolean
- .lpad(str, width, padStr) ⇒
String
- .round(number) ⇒
Integer
- .isNumber(n) ⇒
Is passed data a number?
Kind: static method of Cestino/Util
Access: public
Param | Type |
---|---|
n | * |
Is passed data of type Integer?
Kind: static method of Cestino/Util
Access: public
Param | Type |
---|---|
n | * |
Is passed data of type Float?
Kind: static method of Cestino/Util
Access: public
Param | Type |
---|---|
n | * |
Is passed data empty?
Kind: static method of Cestino/Util
Access: public
Param | Type |
---|---|
val | * |
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 |
Other than Math.round()
, this function rounds to nearest away from zero
Kind: static method of Cestino/Util
Access: public
Param | Type |
---|---|
number | Number |
Kind: global class
Access: private
- BasicCartService ℗
- new BasicCartService(options)
- [. options](#BasicCartService+ options) :
Object
- .setProductDataToCart(oCart) ⇒
Promise
Service used to fetch and put master data of products into the model.
Param | Type |
---|---|
options | Object |
Kind: instance property of BasicCartService
Updates the cart with actual valid information about products.
Kind: instance method of BasicCartService
Access: public
Param | Type |
---|---|
oCart | Cart |
Kind: global class
Access: private
- Cart ℗
- new Cart(oService)
- [. positionId](#Cart+ positionId) :
Integer
- [. oCartService](#Cart+ oCartService) :
Object
- [. positions](#Cart+ positions) :
Array.<CartPosition>
- [. shippingGroups](#Cart+ shippingGroups) :
Object
℗ - [. listener](#Cart+ listener) :
Object
- .walk(fnCallback) ⇒
Cart
- .toJSON() ⇒
String
- .fromJSON(sJSON) ⇒
Cart
- .add(oProduct, oQuantity, [oShippingGroup], [aProductFeatures]) ⇒
String
- .on(kind, fnListener) ⇒
Cart
- .off(kind, fnListener) ⇒
Cart
- .getShippingGroups() ⇒
Array.<String>
- .getShippingGroupByName(sShippingGroup) ⇒
false
|ShippingGroup
- .getPositionsOfGroup(sShippingGroup) ⇒
Array.<CartPosition>
- .calculateGroup(sShippingGroup, includeShippingGroupCost) ⇒
Integer
- .calculate(includeShippingGroupCost) ⇒
Integer
- .deletePosition(sIdCartPosition) ⇒
CartPosition
- .getPositionById(sIdCartPosition) ⇒
CartPosition
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 |
Kind: instance property of Cart
Kind: instance property of Cart
cart. positions : Array.<CartPosition>
Kind: instance property of Cart
Kind: instance property of Cart
Access: private
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 |
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 |
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 |
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 |
Calculates the subtotal of a shipping-group.
Kind: instance method of Cart
Access: public
Param | Type |
---|---|
sShippingGroup | String | ShippingGroup |
includeShippingGroupCost | Boolean |
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 |
Kind: global class
Access: private
- CartPosition ℗
- new CartPosition(sId, oProduct, aFeatures, oQuantity)
- .getId() ⇒
String
- .getProduct() ⇒
Product
- .getFeatures() ⇒
Array.<ProductFeature>
- .getQuantity() ⇒
ProductQuantity
- .getCart() ⇒
Cart
- .replaceQuantity(oQuantity) ⇒
CartPosition
- .incrementAmount(amount) ⇒
CartPosition
- .decrementAmount(amount) ⇒
CartPosition
- .calculate() ⇒
Integer
The cart reference will be injected on instancing separately.
Param | Type |
---|---|
sId | String |
oProduct | Product |
aFeatures | Array.<ProductFeature> |
oQuantity | ProductQuantity |
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 |
Returns calculated price in cents.
Kind: instance method of CartPosition
Access: public
Kind: global class
Access: private
- Product ℗
- new Cart.Product(id, title, price)
- .getId() ⇒
String
- .getTitle() ⇒
String
- .getPrice([oCartPosition]) ⇒
Integer
Class to describe a product that was add to cart.
Param | Type |
---|---|
id | String |
title | String |
price | Integer |
Kind: instance method of Product
Returns the title of the product.
Kind: instance method of Product
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 |
Kind: global class
Access: private
- ProductQuantity ℗
- new Cart.ProductQuantity(amount, [dimX], [dimY], [dimZ])
- .getAmount() ⇒
Integer
- .getLength() ⇒
Integer
- .getWidth() ⇒
Integer
- .getHeight() ⇒
Integer
- .getDepth() ⇒
Integer
- .getFactor([oCartPosition]) ⇒
Integer
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 |
Kind: instance method of ProductQuantity
Kind: instance method of ProductQuantity
Kind: instance method of ProductQuantity
Kind: instance method of ProductQuantity
Kind: instance method of ProductQuantity
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 |
Kind: global class
Access: private
- ProductFeature ℗
- new Cart.ProductFeature(id, label, [price])
- .getId() ⇒
String
- .getPrice([oCartPosition]) ⇒
Integer
- .getLabel() ⇒
Integer
Class to describe a selected feature of a product.
Param | Type |
---|---|
id | String | Integer |
label | String |
[price] | Integer |
Kind: instance method of ProductFeature
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 |
Returns the label of a feature selected to a product.
Kind: instance method of ProductFeature
Kind: global class
Access: private
- ShippingGroup ℗
- new Cart.ShippingGroup([sName])
- [. name](#ShippingGroup+ name) :
String
℗ - [. cart](#ShippingGroup+ cart) :
Cart
℗ - [. price](#ShippingGroup+ price) :
Integer
℗ - .calculate(includeShippingGroupCost) ⇒
Integer
- .setPrice(price) ⇒
ShippingGroup
- .getPrice() ⇒
Integer
- .getName() ⇒
String
- .getCart() ⇒
Cart
Represents information about a shipping group
Param | Type |
---|---|
[sName] | String |
Kind: instance property of ShippingGroup
Access: private
shippingGroup. cart : Cart
℗
Kind: instance property of ShippingGroup
Access: private
Kind: instance property of ShippingGroup
Access: private
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 |
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
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
Kind: global class
Access: private
- PriceFormatter ℗
- new PriceFormatter(decimalSeparator, thousandsSeparator, decimalCount)
- instance
- [. decimalCount](#PriceFormatter+ decimalCount) :
Integer
- [. thousandsSeparator](#PriceFormatter+ thousandsSeparator) :
String
- [. decimalSeparator](#PriceFormatter+ decimalSeparator) :
String
- [. decimalCount](#PriceFormatter+ decimalCount) :
- static
- .format(int) ⇒
String
℗
- .format(int) ⇒
Creates an object to convert integer price to decimal price (e. g. cents to dollar/euro).
Param | Type |
---|---|
decimalSeparator | String |
thousandsSeparator | String |
decimalCount | Integer |
Kind: instance property of PriceFormatter
Kind: instance property of PriceFormatter
Kind: instance property of PriceFormatter
Converts the passed integer value into configured format.
Kind: static method of PriceFormatter
Access: private
Param | Type |
---|---|
int | Integer |