Mango::Cart - Module representing a shopping cart


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


Mango::Cart represents a users shopping cart and cart contents.



Arguments: \%data | $item

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

    my $item = $cart->add({
        sku      => 'SKU1234',
        quantity => 1,
        price    => 1.25

or pass an existing cart item:

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

When passing an existing cart 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.


Deletes all items from the current cart.



Returns the number of items in the cart.

    my $numitems = $cart->count;


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

    print $cart->created;


Arguments: \%filter

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

        sku => 'ABC-123'


Deletes the current cart and all of its items.


Returns the id of the current cart.

    print $cart->id;


Arguments: \%filter [, \%options]

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

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

The following options are available:


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

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


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:

        id => 23

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

    my $wishlist = Mango::Wishlist->search({
        id   => 23

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


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


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


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


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

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


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


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


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

    print $cart->updated;


Arguments: $user

Assigns the current cart to the specified user. This can be a Mango::User object or the user id.


Mango::Cart::Item, Mango::Schema::Cart


    Christopher H. Laco