diff --git a/docs/upgrades/packages-7.5.3/shopping-cart-collateral-items-1.wgpkg b/docs/upgrades/packages-7.5.3/shopping-cart-collateral-items-1.wgpkg index 8a545a161..7e718f3ad 100644 Binary files a/docs/upgrades/packages-7.5.3/shopping-cart-collateral-items-1.wgpkg and b/docs/upgrades/packages-7.5.3/shopping-cart-collateral-items-1.wgpkg differ diff --git a/docs/upgrades/upgrade_7.5.2-7.5.3.pl b/docs/upgrades/upgrade_7.5.2-7.5.3.pl index 1f287e12b..ecab3d86a 100644 --- a/docs/upgrades/upgrade_7.5.2-7.5.3.pl +++ b/docs/upgrades/upgrade_7.5.2-7.5.3.pl @@ -105,7 +105,7 @@ sub migrateToNewCart { index cartId_assetId (cartId,assetId) )"); $session->db->write("drop table shoppingCart"); - $session->db->write("insert into settings values ('shopCartTemplateId','HKwB9Y7jKKfpL4bkQEmX0w')"); + $session->db->write("insert into settings values ('shopCartTemplateId','aIpCmr9Hi__vgdZnDTz1jw')"); } #------------------------------------------------- diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index dac79deb4..5fc2a78db 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -67,7 +67,7 @@ sub addToCart { my ($self, $options) = @_; $self->applyOptions($options); my $cart = WebGUI::Shop::Cart->create($self->session); - my $cart->addItem($self); + $cart->addItem($self); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 6babe1ec3..6e50f317e 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -128,7 +128,7 @@ sub get { if (defined $name) { return $properties{id $self}{$name}; } - my %copyOfHashRef = $properties{id $self}; + my %copyOfHashRef = %{$properties{id $self}}; return \%copyOfHashRef; } @@ -249,6 +249,8 @@ Remove an item from the cart and then display the cart again. sub www_removeItem { my $self = shift; + my $item = WebGUI::Shop::CartItem->new($self, $self->session->form->get("itemId")); + $item->remove; return $self->www_view; } @@ -291,19 +293,20 @@ sub www_view { my @items = (); foreach my $item (@{$self->getItems}) { my $sku = $item->getSku; + $sku->applyOptions($item->get("options")); my %properties = ( %{$item->get}, 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->isShippingRequired, - extendedPrice => sprintf("%.2f", ($properties{price} * $properties{quantity})), - price => sprintf("%.2f", $properties{price}), + extendedPrice => sprintf("%.2f", ($sku->getPrice * $item->get("quantity"))), + price => sprintf("%.2f", $sku->getPrice), removeButton => WebGUI::Form::submit($session, {value=>$i18n->get("remove button"), - onclick=>"this.form.method.value='removeItem';this.form.itemId.value='".$item->getId."';this.form.submit;"}), + extras=>q|onclick="this.form.method.value='removeItem';this.form.itemId.value='|.$item->getId.q|';this.form.submit;"|}), shippingAddress => "todo", shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"), - onclick=>"this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.itemId.value='".$item->getId."';this.form.submit;"}), + extras=>q|onclick="this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.itemId.value='|.$item->getId.q|';this.form.submit;"|}), ); push(@items, \%properties); } @@ -318,15 +321,15 @@ sub www_view { formFooter => WebGUI::Form::formFooter($session), updateButton => WebGUI::Form::submit($session, {value=>$i18n->get("update cart button")}), checkoutButton => WebGUI::Form::submit($session, {value=>$i18n->get("checkout button"), - onclick=>"this.form.shop.value='pay';this.form.methodvalue='viewOptions';this.form.submit;"}), + extras=>q|onclick="this.form.shop.value='pay';this.form.methodvalue='viewOptions';this.form.submit;"|}), continueShoppingButton => WebGUI::Form::submit($session, {value=>$i18n->get("continue shopping button"), - onclick=>"this.form.method.value='continueShopping';this.form.submit;"}), + extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;"|}), chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"), - onclick=>"this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"}), + extras=>q|onclick="this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"|}), shipppingAddress => "todo", shippingOptions => "todo", shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"), - onclick=>"this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"}), + extras=>q|onclick="this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"|}), hasShippingAddress => "todo", couponField => WebGUI::Form::text($session, {name=>"couponCode", value=>"", size=>20}), couponDiscount => "todo", diff --git a/lib/WebGUI/Shop/CartItem.pm b/lib/WebGUI/Shop/CartItem.pm index 3ca128abb..c192d53e7 100644 --- a/lib/WebGUI/Shop/CartItem.pm +++ b/lib/WebGUI/Shop/CartItem.pm @@ -94,7 +94,7 @@ sub get { } return $properties{id $self}{$name}; } - my %copyOfHashRef = $properties{id $self}; + my %copyOfHashRef = %{$properties{id $self}}; return \%copyOfHashRef; } @@ -143,16 +143,8 @@ If specified may increment quantity by more than one. Specify a negative number sub incrementQuantity { my ($self, $quantity) = @_; $quantity ||= 1; - my $id = id $self; - if ($self->get("quantity") + $quantity > $self->getSku->getMaxAllowedInCart) { - WebGUI::Error::Shop::MaxOfItemInCartReached->throw(error=>"Cannot have that many of this item in cart."); - } - if ($self->get("quantity") + $quantity <= 0) { - return $self->remove; - } - $properties{$id}{quantity} += $quantity; - $self->cart->session->db->setRow("cartItems","itemId", $properties{$id}); - return $properties{$id}{quantity}; + $self->setQuantity($quantity + $self->get("quantity")); + return $self->get("quantity"); } @@ -224,7 +216,15 @@ The number to set the quantity to. Zero or less will remove the item from cart. sub setQuantity { my ($self, $quantity) = @_; - return $self->incrementQuantity($quantity - $self->get("quantity")); + my $id = id $self; + if ($quantity > $self->getSku->getMaxAllowedInCart) { + WebGUI::Error::Shop::MaxOfItemInCartReached->throw(error=>"Cannot have that many of this item in cart."); + } + if ($quantity <= 0) { + return $self->remove; + } + $properties{$id}{quantity} = $quantity; + $self->cart->session->db->setRow("cartItems","itemId", $properties{$id}); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index cdf0657d3..e70dcc0a8 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -3,6 +3,12 @@ package WebGUI::i18n::English::Shop; use strict; our $I18N = { + 'too many of this item' => { + message => q|Can't add that many %s to your cart.|, + lastUpdated => 0, + context => q|an error message| + }, + 'subtotal' => { message => q|Subtotal|, lastUpdated => 0,