Handel::Cart::Item - Module representing an individual shopping cart item
use Handel::Cart::Item; my $item = Handel::Cart::Item->create({ cart => '11111111-1111-1111-1111-111111111111', sku => '1234', price => 1.23, quantity => 1 });
Handel::Cart::Item is used in two main ways. First, you can create or edit cart items individually:
As a general rule, you probably want to add/edit items using the cart objects items and add methods below instead.
items
add
Second, the items method of any valid Handel::Cart object returns a collection of Handel::Cart::Item objects:
my @items = $cart->items; foreach (@items) { print $_->sku; };
You can create a new Handel::Cart::Item object by calling the new method:
new
my $item = Handel::Cart::Item->create({ cart => '11111111-1111-1111-1111-111111111111', sku => '1234', price => 1.23, quantity => 1 }); $item->quantity(2); print $item->total;
The following options are available:
A storage object to use to create a new item object. Currently, this storage object must have the same columns as the default storage object for the current item class.
The following methods are mapped to columns in the default cart schema. These methods may or may not be available in any subclasses, or in situations where a custom schema is being used that has different column names.
Returns the id of the current cart item.
print $item->id;
See "id" in Handel::Schema::Cart::Item for more information about this column.
Gets/sets the id of the cart this item belongs to.
$item->cart('11111111-1111-1111-1111-111111111111'); print $item->cart;
See "cart" in Handel::Schema::Cart::Item for more information about this column.
Gets/sets the sku (stock keeping unit/part number) for the cart item.
$item->sku('ABC123'); print $item->sku;
See "sku" in Handel::Schema::Cart::Item for more information about this column.
Gets/sets the quantity, or the number of this item being purchased.
$item->quantity(3); print $item->quantity;
By default, the value supplied will be checked against "constraint_quantity" in Handel::Constraints to verify it is within the valid range of values.
See "quantity" in Handel::Schema::Cart::Item for more information about this column.
Gets/sets the price for the cart item. The price is returned as a stringified Handel::Currency object.
$item->price(12.95); print $item->price; print $item->price->format;
See "price" in Handel::Schema::Cart::Item for more information about this column.
Returns the total price for the cart item as a stringified Handel::Currency object. This is really just quantity*total and is provided for convenience.
print $item->total; print $item->total->format;
Gets/sets the description for the current cart item.
$item->description('Best Item Ever'); print $item->description;
See "description" in Handel::Schema::Cart::Item for more information about this column.
Handel::Cart, Handel::Schema::Cart::Item, Handel::Currency
Christopher H. Laco CPAN ID: CLACO claco@chrislaco.com http://today.icantfocus.com/blog/
To install Handel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Handel
CPAN shell
perl -MCPAN -e shell install Handel
For more information on module installation, please visit the detailed CPAN module installation guide.