NAME

Handel::Order - Module for maintaining order contents

SYNOPSIS

my $order = Handel::Order->new({
    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 is a component for maintaining simple order records.

While Handel::Order subclasses Class::DBI, it is strongly recommended that you not use its methods unless it's absolutely necessary. Stick to the documented methods here and you'll be safe should I decide to implement some other data access mechanism. :-)

CONSTRUCTOR

There are three ways to create a new order object. You can either pass a hashref into new containing all the required values needed to create a new order record or pass a hashref into load containing the search criteria to use to load an existing order or set of orders.

NOTE: The only required hash key is cart. new will copy the specified carts items inthe the order items. cart can be an already existing Handel::Cart object, of a hash reference of search critera, or a cart id (uuid).

When creating a new order from a cart, new will automatically create a new Handel::Checkout process and process CHECKOUT_PHASE_INITIALIZE on the new order. This can be disabled by passing any true value in the second option noprocess.

Handel::Order->new(\%data [, $noprocess])
my $order = Handel::Order->new({
    shopper => '10020400-E260-11CF-AE68-00AA004A34D5',
    id => '111111111-2222-3333-4444-555566667777',
    cart => $cartobject
});

my $order = Handel::Order->new({
    shopper => '10020400-E260-11CF-AE68-00AA004A34D5',
    id => '111111111-2222-3333-4444-555566667777',
    cart => '11112222-3333-4444-5555-666677778888'
});

my $order = Handel::Order->new({
    shopper => '10020400-E260-11CF-AE68-00AA004A34D5',
    id => '111111111-2222-3333-4444-555566667777',
    cart => {
        id => '11112222-3333-4444-5555-666677778888',
        type => CART_TYPE_TEMP
    }
});
Handel::Order->load([\%filter, $wantiterator])
my $order = Handel::Order->load({
    id => 'D597DEED-5B9F-11D1-8DD2-00AA004ABD5E'
});

You can also omit \%filter to load all available orders.

my @orders = Handel::Order->load();

In scalar context load returns a Handel::Order object if there is a single result, or a Handel::Iterator object if there are multiple results. You can force load to always return an iterator even if only one cart exists by setting the $wantiterator parameter to RETURNAS_ITERATOR.

my $iterator = Handel::Order->load(undef, RETURNAS_ITERATOR);
while (my $item = $iterator->next) {
    print $item->sku;
};

See Handel::Contstants for the available RETURNAS options.

A Handel::Exception::Argument exception is thrown if the first parameter is not a hashref.

METHODS

clear

This method removes all items from the current cart object.

$cart->clear;

delete(\%filter)

This method deletes the cart item(s) matching the supplied filter values and returns the number of items deleted.

if ( $cart->delete({id => '8D4B0BE1-C02E-11D2-A33D-00A0C94B8D0E'}) ) {
    print 'Item deleted';
};

items([\%filter, [$wantiterator])

You can retrieve all or some of the items contained in the order via the items method. In a scalar context, items returns an iterator object which can be used to cycle through items one at a time. In list context, it will return an array containing all items.

my $iterator = $order->items;
while (my $item = $iterator->next) {
    print $item->sku;
};

my @items = $order->items;
...
dosomething(\@items);

When filtering the items in the order in scalar context, a Handel::Order::Item object will be returned if there is only one result. If there are multiple results, a Handel::Iterator object will be returned instead. You can force items to always return a Handel::Iterator object even if only one item exists by setting the $wantiterator parameter to RETURNAS_ITERATOR.

my $item = $order->items({sku => 'SKU1234'}, RETURNAS_ITERATOR);
if ($item->isa('Handel::Order::Item)) {
    print $item->sku;
} else {
    while ($item->next) {
        print $_->sku;
    };
};

See the RETURNAS constants in Handel::Constants for other options.

In list context, filtered items return an array of items just as when items is called without a filter specified.

my @items - $order->items((sku -> 'SKU1%'});

A Handel::Exception::Argument exception is thrown if parameter one isn't a hashref or undef.

billtofirstname

Gets/sets the bill to first name

billtolastname

Gets/sets the bill to last name

billtoaddress1

Gets/sets the bill to address line 1

billtoaddress2

Gets/sets the bill to address line 2

billtoaddress3

Gets/sets the bill to address line 3

billtocity

Gets/sets the bill to city

billtostate

Gets/sets the bill to state/province

billtozip

Gets/sets the bill to zip/postal code

billtocountry

Gets/sets the bill to country

billtodayphone

Gets/sets the bill to day phone number

billtonightphone

Gets/sets the bill to night phone number

billtofax

Gets/sets the bill to fax number

billtoemail

Gets/sets the bill to email address

comments

Gets/sets the comments for this order

count

Gets the number of items in the order

created

Gets/sets the created date of the order

handling

Gets/sets the handling charge

id

Gets/sets the record id

number

Gets/sets the order number

shipmethod

Gets/sets the shipping method

shipping

Gets/sets the shipping cost

shiptosameasbillto

Gets/sets the ship to same as bill to flag. When set, the ship to information will be copied from the bill to

shiptofirstname

Gets/sets the ship to first name

shiptolastname

Gets/sets the ship to last name

shiptoaddress1

Gets/sets the ship to address line 1

shiptoaddress2

Gets/sets the ship to address line 2

shiptoaddress3

Gets/sets the ship to address line 3

shiptocity

Gets/sets the ship to city

shiptostate

Gets/sets the ship to state

shiptozip

Gets/sets the ship to zip/postal code

shiptocountry

Gets/sets the ship to country

shiptodayphone

Gets/sets the ship to day phone number

shiptonightphone

Gets/sets the ship to night phone number

shiptofax

Gets/sets the ship to fax number

shiptoemail

Gets/sets the ship to email address

shopper

Gets/sets the shopper id

subtotal

Gets/sets the orders subtotal

tax

Gets/sets the orders tax

total

Gets/sets the orders total

type

Gets/sets the order type

updated

Gets/sets the last updated date of the order

AUTHOR

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