From b31b95ca37642b44887b4bdf47d8996a16bb1bc1 Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Sat, 9 Jun 2018 23:47:21 +0200 Subject: [PATCH] Bugfix: 'stock' counted 1 after using 'repeat' The 'stock' plugin uses the 'product_id' field in the cart item, but this was not copied by the 'repeat' plugin. The confusion is caused by a mismatch between the API for RevBank::Cart->add and the internal representation. --- lib/RevBank/Cart.pm | 4 ++++ plugins/repeat | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/RevBank/Cart.pm b/lib/RevBank/Cart.pm index e1f5ab5..49be311 100644 --- a/lib/RevBank/Cart.pm +++ b/lib/RevBank/Cart.pm @@ -15,6 +15,10 @@ sub new { sub add { my ($self, $user, $amount, $description, $data) = @_; + + # Note: 'repeat' plugin is currently dependent on this specific + # implementation! + $data ||= {}; my $item = { %$data, # Internal stuff, not logged or printed. diff --git a/plugins/repeat b/plugins/repeat index 3359f07..eb4fa66 100755 --- a/plugins/repeat +++ b/plugins/repeat @@ -12,10 +12,11 @@ my $err_limit = "Repetition is limited at $limit items."; sub _do_repeat { my ($cart, $item, $num) = @_; - my $data = $item->{data}; - $data->{_repeated} = 1; + $item->{_repeated} = 1; - $cart->add( @{ $item }{qw/user amount description/}, $data ) for 2..$num; + # Strongly dependent on the implementation of RevBank::Cart and the 'add' + # method. Bad idea, but meh. + $cart->add( @{ $item }{qw/user amount description/}, $item ) for 2..$num; } sub command {