From a555c1ddf1d6e77c6f046d120d8dca8c185044f2 Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Mon, 30 Jan 2023 05:00:43 +0100 Subject: [PATCH] statiegeld: increase quantity instead of adding more of the same --- plugins/statiegeld | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/statiegeld b/plugins/statiegeld index 319a3aa..045ec6e 100644 --- a/plugins/statiegeld +++ b/plugins/statiegeld @@ -66,6 +66,18 @@ sub command ($invocant, $cart, $command, @) { ? "$addon->{description}" : "$addon->{description} ($product->{description})"; + my @existing = grep { + $_->attribute('plugin') eq $invocant->id and + $_->attribute('addon_id') eq $addon->{id} and + $_->{description} eq $d + } $cart->entries('plugin'); + + if (@existing) { + $existing[0]->quantity($existing[0]->quantity + 1); + $cart->select($existing[0]); + next; + } + $cart ->add(+$addon->{price}, $d, { plugin => $invocant->id, addon_id => $addon->{id} }) ->add_contra($addon->{contra}, -$addon->{price}, "$d for \$you");