diff --git a/plugins/statiegeld b/plugins/statiegeld index bb4c7e2..03ba88a 100644 --- a/plugins/statiegeld +++ b/plugins/statiegeld @@ -23,8 +23,9 @@ my $nope = "Sorry, no deposit on that product.\n"; our $S = ($ENV{REVBANK_STATIEGELD} // 0) == 1; -sub statiegeld_product($product_id) { - my $products = RevBank::Plugin::products::_read_products(); +sub statiegeld_product($product_id, $products = undef) { + $products ||= RevBank::Plugin::products::_read_products(); + my $product = $products->{$product_id} or return; my @addons = @{ $product->{addons} }; diff --git a/plugins/statiegeld_tokens b/plugins/statiegeld_tokens index 90be2ec..4232d91 100644 --- a/plugins/statiegeld_tokens +++ b/plugins/statiegeld_tokens @@ -104,15 +104,12 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) { my $tokens_changed = 0; # Products bought: add tokens - for my $entry ($cart->entries('addons')) { - for my $addon_id (@{ $entry->attribute('addons') }) { - my $addon = $products->{"+$addon_id"} // $products->{$addon_id}; - - next - if $addon->{percent} - or (List::Util::none { $addon->{contra} eq $_ } _addon_accounts) - or $addon->{price} <= 0; + for my $entry ($cart->entries('product_id')) { + my $id = $entry->attribute('product_id'); + my $sg = RevBank::Plugin::statiegeld::statiegeld_product($id, $products) + or next; + for my $addon (@{ $sg->{statiegeld_addons} }) { for (1 .. $entry->quantity) { my $token = join(":", join(".", time(), time() + $ttl, $transaction_id),