Class Index | File Index

Classes


Class Qww.Basket.Mgr

Class to provide simple basket manager functionality allowing a basket of itemss with different quantities to be easily managed.

Defined in: <JavaScript\QWW\QwwJs_BasketMgr.js>.

Class Summary
Constructor Attributes Constructor Name and Description
 
Constructs a new Qww.Service instance.
Field Summary
Field Attributes Field Name and Description
 
Cfg
Reference to the configuration object which was used to create construct the object.
 
Collection of items currently stored in the basket.
Method Summary
Method Attributes Method Name and Description
 
Add(id, Object, count)
Adds an item to the basket.
 
Clears the basket (i.e.
 
Returns the quantity of the specified product id.
 
Returns the total number of items in the basket, for example if product1 had a quantity of 2 and product2 had a quantity of 3 this would return 5.
 
Persists the current client side basket contents to the server.
 
SetCount(id, count)
Updates the quantity against a particular product code.
Class Detail
Qww.Basket.Mgr(cfg)
Constructs a new Qww.Service instance.
function DVDItem(id, title, price)
{
    this.ID = id;
    this.Title = title;
    this.Price = price * 1;
};

DVDItem.ConvertBasketItemToJson = function(item) {
    
    return "{\"ID\":\"" + item.ID + "\", \"Title\": \"" + item.Title + 
                "\", \"Price\": \"" + item.Price + "\"}";
};


var basket = new Qww.Basket.Mgr(
{
    OnConvertItemToJson: DVDItem.ConvertBasketItemToJson,
    OnBasketChanged: function(){refreshBasket();}
});

basket.Add("PID6665", new DVDItem("PID6665", "Film Title", 12.99);
Parameters:
{Object} cfg
JSON object to configure Mgr.
{Function} cfg.OnConvertItemToJson
Function to call which convertsan object representing a basket item into a JSON string. Function should accept a single parameter which is the besket item to be converted to JSON.
{Function} cfg.OnBasketChanged Optional
Function to call whenever the basket contents channges. Function can accept a single parameter which is a reference to this Qww.Basket.Mgr itself.
{String} cfg.Key Optional, Default: "QwwJs_BasketMgr_BASKET"
Key against which entire basket contents is stored by the Qww.Services.SimpleDataStorage.
Field Detail
{Object} Cfg
Reference to the configuration object which was used to create construct the object. This allows certain properties to be updated after initial instantiation.

{Qww.Basket.Item[]} Items
Collection of items currently stored in the basket.
Method Detail
Add(id, Object, count)
Adds an item to the basket.
Parameters:
{String} id
ID of the item. (e.g. unique product code).
{Object} Object
representing the basket item.
{Int} count Optional, Default: 1
Initial number of items of this product code to add to the basket.

Clear()
Clears the basket (i.e. removes all items).

GetCount(id)
Returns the quantity of the specified product id. Returns 0 if the product cannot be found in the basket.
Parameters:
{Int} id
ID / product code to return quantity for.

GetTotalCount()
Returns the total number of items in the basket, for example if product1 had a quantity of 2 and product2 had a quantity of 3 this would return 5.

SaveBasket()
Persists the current client side basket contents to the server.

SetCount(id, count)
Updates the quantity against a particular product code.
Parameters:
{Int} id
ID / product code of item in basket to update quantity for.
{Int} count
New quantity for this item. NOTE that if this is set to 0 the item is moved from the basket altogether.