#!perl { # If you want to keep track of stock, you need a way for people to # register cash payments. The 'cash' plugin takes care of that, but # that also assumes deposit_methods. So here's a minimal fallback # implementation for the 'cash' command. # If you use the 'cash' plugin, make sure it is loaded *before* # the 'stock' plugin in 'revbank.plugins'. HELP1 "cash" => "Checkout without a user account"; sub command :Tab(cash) ($self, $cart, $command, @) { return NEXT if $command ne 'cash'; return NEXT if not $cart->size; $cart->checkout('-cash'); return ACCEPT; } } sub hook_checkout($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 @entries = $cart->entries('product_id') or return; my %stock = do { my $in; open($in, '<', $filename) ? map { split " ", $_, 2 } readline $in : () }; $stock{ $_->attribute('product_id') } -= $_->quantity for @entries; 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 $!; }