Christopher H. Laco > Mango-0.01000_13 > Mango::Wishlist

Download:
Mango-0.01000_13.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Mango::Wishlist - Module representing a wishlist

SYNOPSIS ^

    my $wishlist = $provider->create({
        user => 23
    });
    
    $wishlist->add({
        sku      => 'SKU1234',
        quantity => 1,
        price    => 1.25
    });
    
    my $items = $wishlist->items;
    while (my $item = $items->next) {
        print $item->sku;
        print $item->price;
        print $item->total;
    };
    print $wishlist->subtotal;

DESCRIPTION ^

Mango::Wishlist represents a users wishlist and wishlist contents. A wishlist is simply cart that has been saved and given a name for later use.

METHODS ^

add

Arguments: \%data | $item

Adds a new item to the current wishlist and returns the new item. You can pass in the item data as a hash reference:

    my $item = $wishlist->add({
        sku      => 'SKU1234',
        quantity => 1,
        price    => 1.25
    });

or pass an existing wishlist/cart item:

    $wishlist->add(
        $cart->items({sku => 'ABC-123'})->first
    );

When passing an existing item to add, all columns in the source item will be copied into the destination item if the column exists in the destination and the column isn't the primary key or the foreign key of the item relationship.

The item object passed to add must be an instance or subclass of Handel::Cart.

clear

Deletes all items from the current wishlist.

    $wishlist->clear;

count

Returns the number of items in the wishlist.

    my $numitems = $wishlist->count;

created

Returns the date and time in UTC the wishlist was created as a DateTime object.

    print $wishlist->created;

delete

Arguments: \%filter

Deletes the item(s) matching the supplied filter from the current wishlist.

    $wishlist->delete({
        sku => 'ABC-123'
    });

description

Arguments: $description

Gets/sets the description of the current wishlist.

    print $wishlist->description;

destroy

Deletes the current wishlist and all of its items.

id

Returns the id of the current wishlist.

    print $wishlist->id;

items

Arguments: \%filter [, \%options]

Loads the current wishlist items matching the specified filter and returns a Mango::Iterator in scalar context, or a list of items in list context.

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

The following options are available:

order_by

Order the items by the column(s) and order specified. This option uses the SQL style syntax:

    my $items = $wishlist->items(undef, {order_by => 'sku ASC'});

name

Arguments: $name

Gets/sets the name of the current wishlist.

    print $wishlist->name;

restore

Arguments: \%filter [, $mode]
Arguments: $cart [, $mode]

Copies (restores) items from a cart/wishlist, or a set of carts/wishlist back into the current cart. You may either pass in a hash reference containing the search criteria of the cart(s) to restore:

    $cart->restore({
        id => 23
    });

or you can pass in an existing Mango::Cart or Mango::Wishlist object or subclass.

    my $cart = Mango::Cart->search({
        id   => 23
    })->first;
    
    $wishlist->restore($cart);

For either method, you may also specify the mode in which the wishlist should be restored. The following modes are available:

WISHLIST_MODE_REPLACE

All items in the current wishlist will be deleted before the cart is restored into it. This is the default if no mode is specified.

WISHLIST_MODE_MERGE

If an item with the same SKU exists in both the current wishlist and the saved cart, the quantity of each will be added together and applied to the same sku in the current wishlist. Any price differences are ignored and we assume that the price in the current wishlist has the more up to date price.

WISHLIST_MODE_APPEND

All items in the cart will be appended to the list of items in the current wishlist. No effort will be made to merge items with the same SKU and duplicates will be allowed.

subtotal

Returns the current total price of all the items in the wishlist as a Mango::Currency object. This is equivalent to:

    my $items = $wishlist->items;
    my $subtotal = 0;
    
    while (my $item = $items->next) {
        $subtotal += $item->quantity*$item->price;
    };

update

Saves any changes made to the wishlist back to the provider.

    $wishlist->user(23);
    $wishlist->update;

Whenever "update" is called, "updated" is automatically set to the current time in UTC.

updated

Returns the date and time in UTC the wishlist was last updated as a DateTime object.

    print $wishlist->updated;

SEE ALSO ^

Mango::Wishlist::Item, Mango::Schema::Wishlist

AUTHOR ^

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