From 12d2ce6c161aae81fe70917d0be86d53ae83b6ab Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 28 Feb 2008 01:04:14 +0000 Subject: [PATCH] some fixes --- lib/WebGUI/Shop/Cart.pm | 14 +++++++++++++- lib/WebGUI/Shop/CartItem.pm | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 1704d849d..6babe1ec3 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -33,6 +33,7 @@ These subroutines are available from this package: readonly session => my %session; private properties => my %properties; +private error => my %error; #------------------------------------------------------------------- @@ -261,6 +262,16 @@ Updates the cart totals and then displays the cart again. sub www_update { my $self = shift; + my $form = $self->session->form; + foreach my $item (@{$self->getItems}) { + if ($form->get("quantity-".$item->getId) ne "") { + eval { $item->setQuantity($form->get("quantity-".$item->getId)) }; + if (WebGUI::Error->caught("WebGUI::Error::Shop::MaxOfItemInCartReached")) { + my $i18n = WebGUI::International->new($self->session, "Shop"); + $error{id $self} = sprint($i18n->get("too many of this item"), $item->get("configuredTitle")); + } + } + } return $self->www_view; } @@ -285,7 +296,7 @@ sub www_view { url => $sku->getUrl("shop=cart;method=viewItem;itemId=".$item->getId), quantityField => WebGUI::Form::integer($session, {name=>"quantity-".$item->getId, value=>$item->get("quantity")}), isUnique => ($sku->getMaxAllowedInCart == 1), - isShippable => $sku->isShippable, + isShippable => $sku->isShippingRequired, extendedPrice => sprintf("%.2f", ($properties{price} * $properties{quantity})), price => sprintf("%.2f", $properties{price}), removeButton => WebGUI::Form::submit($session, {value=>$i18n->get("remove button"), @@ -299,6 +310,7 @@ sub www_view { my %var = ( %{$self->get}, items => \@items, + error => $error{id $self}, formHeader => WebGUI::Form::formHeader($session) . WebGUI::Form::hidden($session, {name=>"shop", value=>"cart"}) . WebGUI::Form::hidden($session, {name=>"method", value=>"update"}) diff --git a/lib/WebGUI/Shop/CartItem.pm b/lib/WebGUI/Shop/CartItem.pm index d8a0af7c0..3ca128abb 100644 --- a/lib/WebGUI/Shop/CartItem.pm +++ b/lib/WebGUI/Shop/CartItem.pm @@ -210,6 +210,23 @@ sub remove { } +#------------------------------------------------------------------- + +=head2 setQuantity ( quantity ) + +Sets quantity of this item in the cart. + +=head3 quantity + +The number to set the quantity to. Zero or less will remove the item from cart. + +=cut + +sub setQuantity { + my ($self, $quantity) = @_; + return $self->incrementQuantity($quantity - $self->get("quantity")); +} + #------------------------------------------------------------------- =head2 update ( properties )