Methods Summary |
---|
public void | addItem(java.lang.String itemId)
addItem( itemId, 1 );
|
public void | addItem(java.lang.String itemId, int qty)
Integer curQty = ( Integer ) _details.get( itemId );
if ( curQty == null )
{
_details.put( itemId, new Integer( qty ) );
}
else
{
_details.put( itemId, new Integer( qty + curQty.intValue( ) ) );
}
|
public void | empty()
_details.clear( );
|
public java.util.Collection | getCartItems()
try
{
ArrayList items = new ArrayList( );
Iterator it = _details.keySet( ).iterator( );
while ( it.hasNext( ) )
{
String key = ( String ) it.next( );
Integer value = ( Integer ) _details.get( key );
try
{
Item item = manager.find( Item.class, key );
Product prod = item.getProduct( );
CartItem ci = new CartItem( item.getItemId( ), prod.getProductId( ), prod.getName( ), item.getDescription( ), value.intValue( ), item.getListPrice( ) );
items.add( ci );
}
catch ( Exception cce )
{
cce.printStackTrace( );
}
}
// Sort the items
Collections.sort( items, new CartItem.ItemIdComparator( ) );
return items;
}
catch ( Exception e )
{
return Collections.EMPTY_LIST;
}
|
public int | getCount()
return _details.size( );
|
public java.util.Map | getDetails()
return _details;
|
public double | getTotal()
double ret = 0.0d;
Iterator it = getCartItems( ).iterator( );
for ( ; it.hasNext( ); )
{
CartItem i = ( CartItem ) it.next( );
ret += ( i.getUnitCost( ) * i.getQuantity( ) );
}
return ret;
|
public void | remove()
|
public void | removeItem(java.lang.String itemId)
_details.remove( itemId );
|
public void | updateItems(java.lang.String[] itemId, int[] newQty)
for ( int i = 0; i < itemId.length; i++ )
{
String id = itemId[ i ];
int qty = newQty[ i ];
if ( _details.containsKey( id ) )
{
if ( qty > 0 )
{
_details.put( id, new Integer( qty ) );
}
}
else
{
Debug.print( " can't update item[" + id + "]. This item not in the cart" );
}
}
|