Add new hook_checkout_prepare, rollback earlier change of hook_checkout
In hindsight, it was a bad idea to allow manipulating the cart (entries) in hook_checkout, because that hook is used by the `log` plugin. You now get unused entries in the log. Although that plugin should maybe have used hook_checkout_done, existing log file readers (including scripts) and custom plugins may depend on the CHECKOUT items in the log being before the BALANCE items.
This commit is contained in:
parent
50d93b3f6e
commit
6180bf6ea5
2 changed files with 8 additions and 5 deletions
|
@ -79,15 +79,18 @@ sub checkout($self, $user) {
|
|||
|
||||
RevBank::FileIO::with_lock {
|
||||
my $transaction_id = time() - 1300000000;
|
||||
|
||||
RevBank::Plugins::call_hooks("checkout_prepare", $self, $user, $transaction_id);
|
||||
for my $entry (@$entries) {
|
||||
$entry->sanity_check;
|
||||
$entry->user($user) if not $entry->user;
|
||||
}
|
||||
|
||||
RevBank::Plugins::call_hooks("checkout", $self, $user, $transaction_id);
|
||||
|
||||
my %deltas = ($user => RevBank::Amount->new(0));
|
||||
|
||||
for my $entry (@$entries) {
|
||||
# In case entries were added by the hook
|
||||
$entry->sanity_check;
|
||||
$entry->user($user) if not $entry->user;
|
||||
|
||||
$deltas{$_->{user}} += $_->{amount} * $entry->quantity
|
||||
for $entry, $entry->contras;
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ sub _handle_undo($cart) {
|
|||
}
|
||||
}
|
||||
|
||||
sub hook_checkout($class, $cart, $username, $transaction_id, @) {
|
||||
sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
|
||||
if ($username eq '-undo') {
|
||||
_handle_undo($cart);
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue