diff --git a/plugins/market b/plugins/market index 0078a98..3c4a0b8 100644 --- a/plugins/market +++ b/plugins/market @@ -37,10 +37,26 @@ sub command :Tab(market,&tab) { my $space = parse_amount($product->{ space }) or return NEXT; my $description = $product->{description}; - $cart - ->add(-($seller + $space), "$description (sold by $username)", {product_id=>$command}) - ->add_contra($username, 0+$seller, "\$you bought $description") - if 0+$seller; + my @existing = grep { + $_->attribute('plugin') eq $self->id and + $_->attribute('product_id') eq $command + } $cart->entries('plugin'); + + if (@existing) { + $existing[0]->quantity($existing[0]->quantity + 1); + return ACCEPT; + } + + $cart->add( + -($seller + $space), + "$description (sold by $username)", + { product_id => $command, plugin => $self->id } + )->add_contra( + $username, + $seller, + "\$you bought $description" + ); + return ACCEPT; } diff --git a/plugins/products b/plugins/products index ba8c10c..bee1599 100644 --- a/plugins/products +++ b/plugins/products @@ -34,10 +34,20 @@ sub command :Tab(edit,&tab) { my $price = parse_amount( $product->{price} ) or return NEXT; + my @existing = grep { + $_->attribute('plugin') eq $self->id and + $_->attribute('product_id') eq $product->{id} + } $cart->entries('plugin'); + + if (@existing) { + $existing[0]->quantity($existing[0]->quantity + 1); + return ACCEPT; + } + $cart->add( -$price, $product->{description}, - { product_id => $product->{id} } + { product_id => $product->{id}, plugin => $self->id } ); return ACCEPT; }