#!perl HELP "+" => "Add N more items of the previous thing"; my $limit = 200; my $err_limit = "Repetition is limited at $limit items."; my $err_pfand = "Plugins 'pfand' and 'repeat' cannot be combined."; sub command($self, $cart, $command, @) { return ABORT, $err_pfand if $cart->entries('is_pfand'); my ($post) = $command =~ /^\+(\d+)?$/ or return NEXT; return ABORT, "Can't modify an empty transaction." if not $cart->size; my $last = ($cart->entries)[-1]; return REJECT, "Addition only works on products." if not $last->has_attribute('product_id'); if ($post) { return REJECT, $err_limit if $last->quantity + $post > $limit; $last->quantity($last->quantity + $post); return ACCEPT; } return "Add to previous product", \&add; } sub add($self, $cart, $arg, @) { $arg =~ /^\d+$/ and $arg > 0 or return REJECT, "Invalid value."; my $last = ($cart->entries)[-1]; return REJECT, $err_limit if $last->quantity + $arg > $limit; $last->quantity($last->quantity + $arg); return ACCEPT; }