Nitesi::Cart - Cart class for Nitesi Shop Machine
Generic cart class for Nitesi.
Each item in the cart has at least the following attributes:
Initializer which receives the constructor arguments, but does nothing. May be overridden in a subclass.
Returns items in the cart.
Returns subtotal of the cart.
Returns total of the cart.
Add item to the cart. Returns item in case of success.
The item is a hash (reference) which is subject to the following conditions:
Item identifier is required.
Item name is required.
Item quantity is optional and has to be a natural number greater than zero. Default for quantity is 1.
Item price is required and a positive number.
Remove item from the cart. Takes SKU of item to identify the item.
Update items in the cart.
Parameters are pairs of SKUs and quantities, e.g.
$cart->update(9780977920174 => 5, 9780596004927 => 3);
Triggers before_cart_update and after_cart_update hooks.
A quantity of zero is equivalent to removing this item, so in this case the remove hooks will be invoked instead of the update hooks.
Removes all items from the cart.
Returns the sum of the quantity of all items in the shopping cart, which is commonly used as number of items.
print 'Items in your cart: ', $cart->quantity, "\n";
Returns the number of different items in the shopping cart.
Apply cost to cart.
$cart->apply_cost(amount => 5, name => 'shipping', label => 'Shipping');
$cart->apply_cost(amount => 0.19, name => 'tax', label => 'Sales Tax', relative => 1);
$cart->apply_cost(amount => 0.19, name => 'tax', label => 'Sales Tax', relative => 1, inclusive => 1);
Returns particular cost by position or by name.
Get or set id of the cart. This can be used for subclasses, e.g. primary key value for carts in the database.
Get or set the name of the cart.
Returns last error.
Seeds items within the cart from $item_ref.
Stefan Hornburg (Racke), <firstname.lastname@example.org>
Copyright 2011-2012 Stefan Hornburg (Racke) <email@example.com>.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.