market/products: reuse existing entry
This commit is contained in:
parent
c3b0b86c97
commit
29b3eea131
2 changed files with 31 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue