Make all address form variables sticky. Build address choosers for shipping and billing. Begin form processing for address forms.
This commit is contained in:
parent
0050f44bec
commit
0b437f85c3
4 changed files with 65 additions and 9 deletions
Binary file not shown.
|
|
@ -77,6 +77,7 @@ An optional prefix to add to each variable name, and form name.
|
|||
sub appendAddressFormVars {
|
||||
my ($self, $var, $prefix, $properties ) = @_;
|
||||
my $session = $self->session;
|
||||
my $form = $session->form;
|
||||
$properties ||= {};
|
||||
$prefix ||= '';
|
||||
$var ||= {};
|
||||
|
|
@ -84,28 +85,28 @@ sub appendAddressFormVars {
|
|||
$var->{ $prefix . $_ . 'Field' } = WebGUI::Form::text( $session, {
|
||||
name => $prefix . $_,
|
||||
maxlength => 35,
|
||||
defaultValue => $properties->{ $_ }
|
||||
defaultValue => $properties->{ $_ } || $form->get($prefix . $_),
|
||||
} );
|
||||
}
|
||||
$var->{ $prefix . 'countryField' } =
|
||||
WebGUI::Form::country( $session,{
|
||||
name => $prefix . 'country',
|
||||
defaultValue => $properties->{ country }
|
||||
defaultValue => $properties->{ country } || $form->get($prefix . 'country' ),
|
||||
} );
|
||||
$var->{ $prefix . 'codeField' } =
|
||||
WebGUI::Form::zipcode( $session, {
|
||||
name => $prefix . 'code',
|
||||
defaultValue => $properties->{ code }
|
||||
defaultValue => $properties->{ code } || $form->get($prefix . 'code' ),
|
||||
} );
|
||||
$var->{ $prefix . 'phoneNumberField' } =
|
||||
WebGUI::Form::phone( $session, {
|
||||
name => $prefix . 'phoneNumber',
|
||||
defaultValue => $properties->{ phoneNumber }
|
||||
defaultValue => $properties->{ phoneNumber } || $form->get($prefix . 'phoneNumber' ),
|
||||
} );
|
||||
$var->{ $prefix . 'emailField' } =
|
||||
WebGUI::Form::email( $session, {
|
||||
name => $prefix . 'email',
|
||||
defaultValue => $properties->{ email }
|
||||
defaultValue => $properties->{ email } || $form->get($prefix . 'email' ),
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
@ -400,13 +401,14 @@ sub processAddressForm {
|
|||
organization => $form->get($prefix . "organization"),
|
||||
);
|
||||
my $i18n = WebGUI::International->new($self->session, "Shop");
|
||||
foreach my $field (qw/label firstName lastName address1 city code country phoneNumber/) {
|
||||
FIELD: foreach my $field (qw/label firstName lastName address1 city code country phoneNumber/) {
|
||||
my $label = $field eq 'address1' ? 'address'
|
||||
: $field eq 'phoneNumber' ? 'phone number'
|
||||
: $field
|
||||
;
|
||||
if ($addressData{$field} eq "") {
|
||||
$addressData{error} = sprintf($i18n->get('is a required field'), $i18n->get($label));
|
||||
last FIELD;
|
||||
}
|
||||
}
|
||||
return %addressData;
|
||||
|
|
|
|||
|
|
@ -270,6 +270,25 @@ sub getAddressBook {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getBillingAddress ()
|
||||
|
||||
Returns the WebGUI::Shop::Address object that is attached to this cart for billing.
|
||||
|
||||
=cut
|
||||
|
||||
sub getBillingAddress {
|
||||
my $self = shift;
|
||||
my $book = $self->getAddressBook;
|
||||
if (my $addressId = $self->get("billingAddressId")) {
|
||||
return $book->getAddress($addressId);
|
||||
}
|
||||
my $address = $book->getDefaultAddress;
|
||||
$self->update({billingAddressId=>$address->getId});
|
||||
return $address;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ()
|
||||
|
||||
Returns the unique id for this cart.
|
||||
|
|
@ -622,7 +641,18 @@ sub updateFromForm {
|
|||
my $i18n = WebGUI::International->new($self->session, "Shop");
|
||||
$error{id $self} = $i18n->get('mixed items warning');
|
||||
}
|
||||
my $book = $self->getAddressBook;
|
||||
my $book = $self->getAddressBook;
|
||||
|
||||
my %billingData = $book->processAddressForm('billing_');
|
||||
my $billingAddressId = $form->process('billingAddressId');
|
||||
if ($billingAddressId eq 'new_address' && ! exists $billingData{'error'}) {
|
||||
my $billingAddress = $book->addAddress(\%billingData);
|
||||
$self->update({billingAddressId => $billingAddress->get('addressId'), });
|
||||
}
|
||||
elsif ($billingAddressId ne 'new_address') {
|
||||
$self->update({billinbAddressId => $billingAddressId});
|
||||
}
|
||||
|
||||
#$book->processAddressForm()
|
||||
my $cartProperties = {};
|
||||
$cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' );
|
||||
|
|
@ -925,8 +955,26 @@ sub www_view {
|
|||
else {
|
||||
##Address form variables
|
||||
my $addressBook = $self->getAddressBook;
|
||||
$addressBook->appendAddressFormVars(\%var, 'shipping_', {});
|
||||
$addressBook->appendAddressFormVars(\%var, 'billing_', {});
|
||||
my $addresses = $addressBook->getAddresses;
|
||||
tie my %addressOptions, 'Tie::IxHash';
|
||||
$addressOptions{'new_address'} = $i18n->get('Add new address');
|
||||
foreach my $address (@{ $addresses }) {
|
||||
$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, {
|
||||
name => 'billing_addressId',
|
||||
options => \%addressOptions,
|
||||
value => $self->get('billingAddressId') ? $self->get('billingAddressId') : 'new_address',
|
||||
});
|
||||
my $shippingAddressData = $self->get('shippingAddressId') ? $self->getShippingAddress->get() : {};
|
||||
my $billingAddressData = $self->get('billingAddressId') ? $self->getBillingAddress->get() : {};
|
||||
$addressBook->appendAddressFormVars(\%var, 'shipping_', $shippingAddressData);
|
||||
$addressBook->appendAddressFormVars(\%var, 'billing_', $billingAddressData);
|
||||
$var{sameShippingAsBilling} = WebGUI::Form::yesNo($session, {name => 'sameShippingAsBilling', value => $form->get('sameShippingAsBilling','yesNo')});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1749,6 +1749,12 @@ our $I18N = {
|
|||
context => q|template label for the cart|
|
||||
},
|
||||
|
||||
'Add new address' => {
|
||||
message => q|Add new address.|,
|
||||
lastUpdated => 0,
|
||||
context => q|form label for the cart. Allows user to build a new address.|
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue