revbank/plugins/market
Juerd Waalboer 551c22c8ba Product ID in cart items internal metadata + alias support.
The alias support is implemented in products, but not in market.

The product ID in the cart items is useful for plugins that hook the checkout.
2013-02-28 01:42:33 +01:00

37 lines
947 B
Perl
Executable file

#!perl
HELP "market" => "Edit market list";
my $filename = 'revbank.market';
sub command :Tab(market) {
my ($self, $cart, $command) = @_;
if ($command eq 'market') {
system $ENV{EDITOR} || 'vi', $filename;
return ACCEPT;
}
my @products;
open my $fh, '<', $filename or die $!;
/\S/ && !/^\s*#/ and push @products, [split " ", $_, 5] while readline $fh;
chomp @$_ for @products;
for my $fields (@products) {
my ($username, $id, $seller, $space, $description) = @$fields;
next if $command ne $id;
$username = parse_user($username) or next;
$seller = parse_amount($seller) or next;
$space = parse_amount($space) or next;
$cart->add(undef, -($seller + $space), $description, {product_id=>$id});
$cart->add($username, 0+$seller, "\$you bought $description")
if 0+$seller;
return ACCEPT;
}
return NEXT;
}