
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.
37 lines
864 B
Perl
Executable file
37 lines
864 B
Perl
Executable file
#!perl
|
|
|
|
HELP "<productID>" => "Look up products from database";
|
|
HELP "edit" => "Edit product list";
|
|
|
|
my $filename = 'revbank.products';
|
|
|
|
sub command :Tab(edit) {
|
|
my ($self, $cart, $command) = @_;
|
|
|
|
if ($command eq 'edit') {
|
|
system $ENV{EDITOR} || 'vi', $filename;
|
|
return ACCEPT;
|
|
}
|
|
|
|
my @products;
|
|
|
|
open my $fh, '<', $filename or die $!;
|
|
/\S/ && !/^\s*#/ and push @products, [split " ", $_, 3] while readline $fh;
|
|
chomp @$_ for @products;
|
|
|
|
for my $fields (@products) {
|
|
my ($ids, $price, $description) = @$fields;
|
|
|
|
my @ids = split /,/, $ids;
|
|
for my $id (@ids) {
|
|
next if $id ne $command;
|
|
|
|
$price = parse_amount($price) or next;
|
|
|
|
$cart->add(undef, -$price, $description, { product_id => $ids[0] });
|
|
return ACCEPT;
|
|
}
|
|
}
|
|
|
|
return NEXT;
|
|
}
|