The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Handel::Order::Item - Module representing an individual order line item

SYNOPSIS

    use Handel::Order;
    
    my $order = Handel::Order->create({
        id => '12345678-9098-7654-322-345678909876'
    });
    
    my $iterator = $order->items;
    while (my $item = $iterator->next) {
        print $item->sku;
        print $item->price;
        print $item->total;
    };

DESCRIPTION

Handel::Order::Item is used in two main ways. First, you can create or edit order items individually:

    use Handel::Order::Item;
    
    my $item = Handel::Order::Item->create({
        cart => '11111111-1111-1111-1111-111111111111',
        sku => '1234',
        price => 1.23,
        quantity => 1
    });

As a general rule, you probably want to add/edit items using the order objects items and add methods below instead.

Second, the items method of any valid Handel::Order object returns a collection of Handel::Order::Item objects:

    my @items = $order->items;
    foreach (@items) {
        print $_->sku;
    };

CONSTRUCTOR

create

Arguments: \%data [, \%options]

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

    my $item = Handel::Order::Item->create({
        sku => '1234',
        price => 1.23,
        quantity => 1,
        total => 1.23
    });
    
    $item->quantity(2);
    
    print $item->total;

The following options are available:

storage

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.

COLUMNS

The following methods are mapped to columns in the default order 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.

id

Returns the id of the current order item.

    print $item->id;

See "id" in Handel::Schema::Order::Item for more information about this column.

orderid

Gets/sets the id of the order this item belongs to.

    $item->order('11111111-1111-1111-1111-111111111111');
    print $item->order;

See "cart" in Handel::Schema::Order::Item for more information about this column.

sku

Arguments: $sku

Gets/sets the sku (stock keeping unit/part number) for the order item.

    $item->sku('ABC123');
    print $item->sku;

See "sku" in Handel::Schema::Order::Item for more information about this column.

quantity

Arguments: $quantity

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::Order::Item for more information about this column.

price

Arguments: $price

Gets/sets the price for the order 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::Order::Item for more information about this column.

total

Gets/sets the total price for the order item as a stringified Handel::Currency object.

    $item->total(12.95);
    print $item->total;
    print $item->total->format;

See "total" in Handel::Schema::Order::Item for more information about this column.

description

Arguments: $description

Gets/sets the description for the current order item.

    $item->description('Best Item Ever');
    print $item->description;

See "description" in Handel::Schema::Order::Item for more information about this column.

SEE ALSO

Handel::Order, Handel::Schema::Order::Item, Handel::Currency

AUTHOR

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