NAME
Dancer::Plugin::Interchange6::Cart
DESCRIPTION
Extends Interchange6::Cart to tie cart to Interchange6::Schema::Result::Cart.
ATTRIBUTES
See "ATTRIBUTES" in Interchange6::Cart for a full list of attributes inherited by this module.
database
The database name as defined in the Dancer::Plugin::DBIC configuration.
Attribute is required.
sessions_id
Extends inherited sessions_id attribute.
Attribute is required.
METHODS
See "METHODS" in Interchange6::Cart for a full list of methods inherited by this module.
get_sessions_id
BUILDARGS
Sets default values for name, database and sessions_id if not given and loads other attribute values from DB cart. If DB cart does not exist then create new one.
BUILD
Load existing cart from the database along with any products it contains and add cart hooks.
METHODS
add
Add one or more products to the cart.
Possible arguments:
single product sku (scalar value)
hashref with keys 'sku' and 'quantity' (quantity is optional and defaults to 1)
an array reference of either of the above
In list context returns an array of Interchange6::Cart::Products and in scalar context returns an array reference of the same.
clear
Removes all products from the cart.
load_saved_products
Pulls old cart items into current cart - used after user login.
remove
Remove single product from the cart. Takes SKU of product to identify the product.
rename
Rename this cart. This is the writer method for "name" in Interchange6::Cart.
Arguments: new name
Returns: cart object
set_sessions_id
Writer method for "sessions_id" in Interchange6::Cart.
set_users_id
Writer method for "users_id" in Interchange6::Cart.
update
Update quantity of products in the cart.
Parameters are pairs of SKUs and quantities, e.g.
$cart->update(9780977920174 => 5,
9780596004927 => 3);
Triggers before_cart_update and after_cart_update hooks.
A quantity of zero is equivalent to removing this product, so in this case the remove hooks will be invoked instead of the update hooks.
Returns updated products that are still in the cart. Products removed via quantity 0 or products for which quantity has not changed will not be returned.
HOOKS
The following hooks are available:
- before_cart_add_validate
-
Executed in "add" before arguments are validated as being valid. Hook receives the following arguments:
Receives: $cart, \%args
The args are those that were passed to add.
Example:
hook before_cart_add_validate => sub { my ( $cart, $args ) = @_; foreach my $arg ( @$args ) { my $sku = ref($arg) eq 'HASH' ? $arg->{sku} : $arg; die "bad product" if $sku eq "bad sku"; } }
- before_cart_add
-
Called in "add" immediately before the products are added to the cart.
Receives: $cart, \@products
The products arrary ref contains simple hash references that will be passed to "new" in Interchange6::Cart::Product.
- after_cart_add
-
Called in "add" after products have been added to the cart.
Receives: $cart, \@product
The products arrary ref contains <Interchange6::Cart::Product>s.
- before_cart_remove_validate
-
Called at start of "remove" before arg has been validated.
Receives: $cart, $sku
- before_cart_remove
-
Called in "remove" before validated product is removed from cart.
Receives: $cart, $sku
- after_cart_remove
-
Called in "remove" after product has been removed from cart.
Receives: $cart, $sku
- before_cart_update
-
Executed for each pair of sku/quantity passed to update before the update is performed.
Receives: $cart, $sku, $quantity
- after_cart_update
-
Executed for each pair of sku/quantity passed to update after the update is performed.
Receives: $cart, $sku, $quantity
- before_cart_clear
-
Executed in "clear" before the clear is performed.
Receives: $cart
- after_cart_clear
-
Executed in "clear" after the clear is performed.
Receives: $cart
- before_cart_set_users_id
-
Executed in set_users_id before users_id is updated.
Receives: $cart, $userid
- after_cart_set_users_id
-
Executed in set_users_id after users_id is updated.
Receives: $cart, $userid
- before_cart_set_sessions_id
-
Executed in set_sessions_id before sessions_id is updated.
Receives: $cart, $sessionid
- after_cart_set_sessions_id
-
Executed in set_sessions_id after sessions_id is updated.
Receives: $cart, $sessionid
- before_cart_rename
-
Executed in "rename" before cart "name" in Interchange6::Cart is updated.
Receives: $cart, $old_name, $new_name
- after_cart_rename
-
Executed in "rename" after cart "name" in Interchange6::Cart is updated.
Receives: $cart, $old_name, $new_name
AUTHORS
Stefan Hornburg (Racke), <racke@linuxia.de>
Peter Mottram (SysPete), <peter@sysnix.com>
LICENSE AND COPYRIGHT
Copyright 2011-2014 Stefan Hornburg (Racke) <racke@linuxia.de>.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.