Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add [cart-clear] tag.
  • Loading branch information
racke committed Sep 15, 2010
1 parent 3e73af5 commit f199e5a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/WellWell/Cart.pm
Expand Up @@ -31,6 +31,9 @@ Vend::Config::parse_tag('UserTag', 'cart_add Order sku quantity');
Vend::Config::parse_tag('UserTag', 'cart_add AddAttr');
Vend::Config::parse_tag('UserTag', 'cart_add MapRoutine WellWell::Cart::cart_add');

Vend::Config::parse_tag('UserTag', 'cart_clear AddAttr');
Vend::Config::parse_tag('UserTag', 'cart_clear MapRoutine WellWell::Cart::cart_clear');

Vend::Config::parse_tag('UserTag', 'cart_item Order sku quantity');
Vend::Config::parse_tag('UserTag', 'cart_item AddAttr');
Vend::Config::parse_tag('UserTag', 'cart_item MapRoutine WellWell::Cart::cart_item');
Expand Down Expand Up @@ -127,6 +130,37 @@ sub cart_add {
return $itemref;
}

# [cart-clear] - clear cart

sub cart_clear {
my ($opt) = @_;
my (@new_cart, $sku);

for my $itemref (@$Vend::Items) {
$sku = $itemref->{code};
WellWell::Core::hooks('run', 'cart', 'delete', 'main', $itemref);

if ($itemref->{error}) {
# one of the hooks denied the item
if ($itemref->{log_error}) {
::logError('Removing item %s was denied: %s', $sku, $itemref->{error});
}
Vend::Tags->error({name => $sku, set => $itemref->{error}, overwrite => 1});

# prevent error from leaking into subsequent cart actions
delete $itemref->{error};

push (@new_cart, $itemref);
}
}

if (@$Vend::Items = @new_cart) {
return 0;
}

return 1;
}

sub cart_refresh {
my ($cart, $new_cart, $quantity, $itemref, $sku, $modifiers);

Expand Down

0 comments on commit f199e5a

Please sign in to comment.