Christopher H. Laco > Handel-0.32 > Handel::Cart::Item

Download:
Handel-0.32.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Source   Latest Release: Handel-1.00011

NAME ^

Handel::Cart::Item - Module representing an individual shopping cart line item

SYNOPSIS ^

    use Handel::Cart::Item;

    my $item = Handel::Cart::Item->new({
        sku => '1234',
        price => 1.23,
        quantity => 1
    });

    $cart->add($item);

DESCRIPTION ^

Handel::Cart::Item is used in two main ways. First, you can create new line items and add them to an existing cart object:

    use Handel::Cart::Item;

    my $item = Handel::Cart::Item->new({
        sku => '1234',
        price => 1.23,
        quantity => 1
    });

    $cart->add($item);

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;
    };

CONSTRUCTOR ^

new

You can create a new Handel::Cart::Item object by calling the new method:

    my $item = Handel::Cart::Item->new({
        sku => '1234',
        price => 1.23,
        quantity => 1
    });

    $item->quantity(2);

    print $item->total;

This is a lazy operation. No actual item record is created until the item object is passed into the add method of a Handel::Cart object.

METHODS ^

sku

Returns or sets the sku (stock keeping unit/part number) for the cart item.

quantity

Returns or sets the quantity the cart item.

price

Returns or sets the price for the cart item.

Starting in version 0.12, price now returns a stringified Handel::Currency object. This can be used to format the price, and convert its value from on currency to another.

total

Returns the total price for the cart item. This is really just quantity*total and is provided for convenience.

Starting in version 0.12, subtotal now returns a stringified Handel::Currency object. This can be used to format the price, and convert its value from on currency to another.

description

Returns or sets the description for the cart item.

SEE ALSO ^

Handel::Cart, Handel::Currency

AUTHOR ^

    Christopher H. Laco
    CPAN ID: CLACO
    claco@chrislaco.com
    http://today.icantfocus.com/blog/