
Undoes 714b337
because github seems to no longer require chmod +x
for syntax highlighting extensionless files.
53 lines
1.2 KiB
Perl
53 lines
1.2 KiB
Perl
#!perl
|
|
|
|
HELP "pfand" => "Pfand zurueck";
|
|
|
|
# This is a demo plugin. It's called "pfand" because "deposit" would be
|
|
# confusing and only the Germans are crazy enough to have deposits on small
|
|
# bottles anyway ;)
|
|
|
|
# The file format for 'revbank.pfand' is simply two whitespace separated
|
|
# columns: product id and pfand amount.
|
|
|
|
sub _read_pfand {
|
|
open my $fh, 'revbank.pfand' or die $!;
|
|
return {
|
|
map { split " " } grep /\S/, grep !/^\s*#/, readline $fh
|
|
};
|
|
}
|
|
|
|
sub command :Tab(pfand) {
|
|
my ($self, $cart, $command) = @_;
|
|
|
|
return NEXT if $command ne 'pfand';
|
|
|
|
return "Pfand zurueck fuer", \&product;
|
|
}
|
|
|
|
sub product :Tab(&tab) {
|
|
my ($self, $cart, $product) = @_;
|
|
my $pfand = _read_pfand->{ $product };
|
|
|
|
if ($pfand) {
|
|
$cart->add(undef, +$pfand, "Pfand zurueck", { is_return => 1 });
|
|
} else {
|
|
say "$product: Kein Pfand";
|
|
}
|
|
return ACCEPT;
|
|
}
|
|
|
|
sub tab {
|
|
return keys %{ _read_pfand() };
|
|
}
|
|
|
|
sub hook_add {
|
|
my ($class, $cart, $user, $item) = @_;
|
|
return if defined $user;
|
|
return if exists $item->{is_return};
|
|
return if not exists $item->{product_id};
|
|
|
|
my $pfand = _read_pfand->{ $item->{product_id} } or return;
|
|
|
|
$cart->add(undef, -$pfand, "Pfand", { is_pfand => 1 });
|
|
}
|
|
|