From a1f20e67ce10108e5155544bfa7b38c93d271d6d Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Thu, 28 Feb 2013 13:02:28 +0100 Subject: [PATCH] New hook: "add" --- RevBank/Cart.pm | 4 +++- RevBank/Plugins.pm | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/RevBank/Cart.pm b/RevBank/Cart.pm index cd6f52f..74a98f0 100644 --- a/RevBank/Cart.pm +++ b/RevBank/Cart.pm @@ -17,11 +17,13 @@ sub add { my ($self, $user, $amount, $description, $data) = @_; $user ||= '$you'; $data ||= {}; - push @{ $self->{ $user } }, { + my $item = { %$data, # Internal stuff, not logged or printed. amount => $amount, description => $description, }; + RevBank::Plugins::call_hooks("add", $self, $user, $item); + push @{ $self->{ $user } }, $item; } sub empty { diff --git a/RevBank/Plugins.pm b/RevBank/Plugins.pm index 2b4bcb9..1c27395 100644 --- a/RevBank/Plugins.pm +++ b/RevBank/Plugins.pm @@ -228,6 +228,17 @@ Called when user input was given. C<$split_input> is a boolean that is true if the input will be split on whitespace, rather than treated as a whole. The input MAY be altered by the plugin. +=item hook_add $class, $cart, $user, $item + +Called when something is added to the cart. Of course, like in C<< $cart->add +>>, C<$user> will be undef if the product is added for the current user. + +C<$item> is a reference to a hash with the keys C, C and +the metadata given in the C call. Changing the values changes the actual +item going into the cart! + +Be careful to avoid infinite loops if you add new stuff. + =item hook_checkout $class, $cart, $user, $transaction_id Called when the transaction is finalized.