From 22d6806dfeae80f1365108cd332160e5e7384ed1 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 10 May 2010 17:19:01 -0700 Subject: [PATCH] Better UI for changing addresses. Prevent bad things from happening if the user delete required fields. --- lib/WebGUI/Shop/Cart.pm | 13 +++++++------ lib/WebGUI/i18n/English/Shop.pm | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index ddfe644d9..e6c910884 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -702,8 +702,9 @@ Updates the cart totals, the address fields and the shipping and billing options =cut sub updateFromForm { - my $self = shift; - my $form = $self->session->form; + my $self = shift; + my $session = $self->session; + my $form = $session->form; foreach my $item (@{$self->getItems}) { if ($form->get("quantity-".$item->getId) ne "") { eval { $item->setQuantity($form->get("quantity-".$item->getId)) }; @@ -740,7 +741,7 @@ sub updateFromForm { my $address = $self->getBillingAddress(); $address->update(\%billingData); } - elsif ($billingAddressId ne 'new_address' && $billingAddressId) { + elsif ($billingAddressId ne 'new_address' && $billingAddressId ne 'update_address' && $billingAddressId) { ##User changed the address selector to another address field $cartProperties->{billingAddressId} = $billingAddressId; } @@ -775,7 +776,7 @@ sub updateFromForm { my $address = $self->getBillingAddress(); $address->update(\%shippingData); } - elsif ($shippingAddressId ne 'new_address' && $shippingAddressId) { + elsif ($shippingAddressId ne 'new_address' && $shippingAddressId ne 'update_address' && $shippingAddressId) { $cartProperties->{shippingAddressId} = $shippingAddressId; } else { @@ -1117,7 +1118,7 @@ sub www_view { my $billingAddressId = $self->get('billingAddressId'); if ($billingAddressId) { - $billingAddressOptions{'update_address'} = $i18n->get('Update this address'); + $billingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $self->getBillingAddress->get('label'); } %billingAddressOptions = (%billingAddressOptions, %addressOptions); @@ -1133,7 +1134,7 @@ sub www_view { my $shippingAddressId = $self->get('shippingAddressId'); if ($shippingAddressId) { - $shippingAddressOptions{'update_address'} = $i18n->get('Update this address'); + $shippingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $self->getShippingAddress->get('label'); } %shippingAddressOptions = (%shippingAddressOptions, %addressOptions); diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index 25965a646..d741c9fe4 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -1761,10 +1761,10 @@ our $I18N = { context => q|form label for the cart. Allows user to build a new address.| }, - 'Update this address' => { - message => q|Update this address|, + 'Update %s' => { + message => q|Update address: %s|, lastUpdated => 0, - context => q|form label for the cart. Allows user to build a new address.| + context => q|form label for the cart. Allows user to edit an existing address. %s will be replaced by the label for the currently selected address, if there is one.| }, 'Choose a payment method' => {