Dancer::Plugin::Interchange6::Cart
Extends Interchange6::Cart to tie cart to Interchange6::Schema::Result::Cart.
See "ATTRIBUTES" in Interchange6::Cart for a full list of attributes inherited by this module.
The database name as defined in the Dancer::Plugin::DBIC configuration.
Attribute is required.
Extends inherited sessions_id attribute.
See "METHODS" in Interchange6::Cart for a full list of methods inherited by this module.
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.
Load existing cart from the database along with any products it contains and add cart hooks.
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.
Removes all products from the cart.
Pulls old cart items into current cart - used after user login.
Remove single product from the cart. Takes SKU of product to identify the product.
Rename this cart. This is the writer method for "name" in Interchange6::Cart.
Arguments: new name
Returns: cart object
Writer method for "sessions_id" in Interchange6::Cart.
Writer method for "users_id" in Interchange6::Cart.
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.
The following hooks are available:
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"; } }
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.
Called in "add" after products have been added to the cart.
Receives: $cart, \@product
The products arrary ref contains <Interchange6::Cart::Product>s.
Called at start of "remove" before arg has been validated.
Receives: $cart, $sku
Called in "remove" before validated product is removed from cart.
Called in "remove" after product has been removed from cart.
Executed for each pair of sku/quantity passed to update before the update is performed.
Receives: $cart, $sku, $quantity
Executed for each pair of sku/quantity passed to update after the update is performed.
Executed in "clear" before the clear is performed.
Receives: $cart
Executed in "clear" after the clear is performed.
Executed in set_users_id before users_id is updated.
Receives: $cart, $userid
Executed in set_users_id after users_id is updated.
Executed in set_sessions_id before sessions_id is updated.
Receives: $cart, $sessionid
Executed in set_sessions_id after sessions_id is updated.
Executed in "rename" before cart "name" in Interchange6::Cart is updated.
Receives: $cart, $old_name, $new_name
Executed in "rename" after cart "name" in Interchange6::Cart is updated.
Stefan Hornburg (Racke), <racke@linuxia.de> Peter Mottram (SysPete), <peter@sysnix.com>
Copyright 2011-2015 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.
To install Dancer::Plugin::Interchange6, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Interchange6
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Interchange6
For more information on module installation, please visit the detailed CPAN module installation guide.