Stock plugin for hack42.
This commit is contained in:
parent
4df8d427ed
commit
6a6ce32791
2 changed files with 29 additions and 0 deletions
28
plugins/stock
Normal file
28
plugins/stock
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#!perl
|
||||||
|
|
||||||
|
sub command { NEXT }
|
||||||
|
|
||||||
|
sub hook_checkout {
|
||||||
|
my ($class, $cart, $user, $transaction_id) = @_;
|
||||||
|
|
||||||
|
# Hack42 for some reason used the dutch word in their revbank1 hack.
|
||||||
|
my $filename = -e("revbank.voorraad")
|
||||||
|
? "revbank.voorraad"
|
||||||
|
: "revbank.stock";
|
||||||
|
|
||||||
|
my @items = $cart->select_items('product_id') or return;
|
||||||
|
|
||||||
|
my %stock = do {
|
||||||
|
my $in;
|
||||||
|
open($in, '<', $filename)
|
||||||
|
? map { split " ", $_, 2 } readline $in
|
||||||
|
: ()
|
||||||
|
};
|
||||||
|
|
||||||
|
$stock{ $_->{product_id} }-- for @items;
|
||||||
|
|
||||||
|
open my $out, '>', "$filename.$$" or warn "$filename.$$: $!";
|
||||||
|
printf {$out} "%-16s %+9d\n", $_, $stock{$_} for sort keys %stock;
|
||||||
|
close $out or die "$filename.$$: $!";
|
||||||
|
rename "$filename.$$", $filename or die $!;
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ undo
|
||||||
give
|
give
|
||||||
take
|
take
|
||||||
#nyan # fun, but not compatible with dumb terminals
|
#nyan # fun, but not compatible with dumb terminals
|
||||||
|
#stock
|
||||||
|
|
||||||
# Then, plugins that apply heuristics
|
# Then, plugins that apply heuristics
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue