Add and edit addresses, for billing only.

This commit is contained in:
Colin Kuskie 2010-04-26 11:33:27 -07:00
parent 0b437f85c3
commit 85c7beca70
2 changed files with 45 additions and 12 deletions

View file

@ -624,6 +624,7 @@ Updates the cart totals from form data.
sub updateFromForm { sub updateFromForm {
my $self = shift; my $self = shift;
$self->session->log->warn('updateFromForm');
my $form = $self->session->form; my $form = $self->session->form;
foreach my $item (@{$self->getItems}) { foreach my $item (@{$self->getItems}) {
if ($form->get("quantity-".$item->getId) ne "") { if ($form->get("quantity-".$item->getId) ne "") {
@ -645,12 +646,25 @@ sub updateFromForm {
my %billingData = $book->processAddressForm('billing_'); my %billingData = $book->processAddressForm('billing_');
my $billingAddressId = $form->process('billingAddressId'); my $billingAddressId = $form->process('billingAddressId');
$self->session->log->warn('billing addressId: '. $billingAddressId);
if ($billingAddressId eq 'new_address' && ! exists $billingData{'error'}) { if ($billingAddressId eq 'new_address' && ! exists $billingData{'error'}) {
my $billingAddress = $book->addAddress(\%billingData); ##Add a new address
$self->update({billingAddressId => $billingAddress->get('addressId'), }); $self->session->log->warn('add a new address');
my $newAddress = $book->addAddress(\%billingData);
$self->update({billingAddressId => $newAddress->get('addressId'), });
} }
elsif ($billingAddressId ne 'new_address') { elsif ($billingAddressId eq 'update_address' && $self->get('billingAddressId')) {
$self->update({billinbAddressId => $billingAddressId}); $self->session->log->warn('update an existing address');
##User changed the address selector
my $address = $self->getBillingAddress();
$address->update(\%billingData);
}
elsif ($billingAddressId ne 'new_address' && $billingAddressId) {
$self->session->log->warn('change an address');
$self->update({billingAddressId => $billingAddressId});
}
else {
$self->session->log->warn('address: something else: '. $billingData{error});
} }
#$book->processAddressForm() #$book->processAddressForm()
@ -781,6 +795,7 @@ Updates the cart totals and then displays the cart again.
sub www_update { sub www_update {
my $self = shift; my $self = shift;
$self->session->log->warn('www_update');
$self->updateFromForm; $self->updateFromForm;
return $self->www_view; return $self->www_view;
} }
@ -958,18 +973,30 @@ sub www_view {
my $addresses = $addressBook->getAddresses; my $addresses = $addressBook->getAddresses;
tie my %addressOptions, 'Tie::IxHash'; tie my %addressOptions, 'Tie::IxHash';
$addressOptions{'new_address'} = $i18n->get('Add new address'); $addressOptions{'new_address'} = $i18n->get('Add new address');
my $billingAddressId = $self->get('billingAddressId');
if ($billingAddressId) {
$addressOptions{'update_address'} = $i18n->get('Update this address');
}
foreach my $address (@{ $addresses }) { foreach my $address (@{ $addresses }) {
$addressOptions{$address->get('addressId')} = $address->get('label'); $addressOptions{$address->get('addressId')} = $address->get('label');
} }
$var{'shippingAddressChooser'} = WebGUI::Form::selectBox($session, {
name => 'shipping_addressId',
options => \%addressOptions,
value => $self->get('shippingAddressId') ? $self->get('shippingAddressId') : 'new_address',
});
$var{'billingAddressChooser'} = WebGUI::Form::selectBox($session, { $var{'billingAddressChooser'} = WebGUI::Form::selectBox($session, {
name => 'billing_addressId', name => 'billingAddressId',
options => \%addressOptions, options => \%addressOptions,
value => $self->get('billingAddressId') ? $self->get('billingAddressId') : 'new_address', value => $billingAddressId ? $billingAddressId : 'new_address',
});
my $shippingAddressId = $self->get('shippingAddressId');
if (!$shippingAddressId) {
delete $addressOptions{'update_address'};
}
$var{'shippingAddressChooser'} = WebGUI::Form::selectBox($session, {
name => 'shippingAddressId',
options => \%addressOptions,
value => $shippingAddressId ? $shippingAddressId : 'new_address',
}); });
my $shippingAddressData = $self->get('shippingAddressId') ? $self->getShippingAddress->get() : {}; my $shippingAddressData = $self->get('shippingAddressId') ? $self->getShippingAddress->get() : {};
my $billingAddressData = $self->get('billingAddressId') ? $self->getBillingAddress->get() : {}; my $billingAddressData = $self->get('billingAddressId') ? $self->getBillingAddress->get() : {};

View file

@ -1750,7 +1750,13 @@ our $I18N = {
}, },
'Add new address' => { 'Add new address' => {
message => q|Add new address.|, message => q|Add new address|,
lastUpdated => 0,
context => q|form label for the cart. Allows user to build a new address.|
},
'Update this address' => {
message => q|Update this address|,
lastUpdated => 0, 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 build a new address.|
}, },