Add a billing address to the cart. Add form processing for an address form to the AddressBook. Support for choosing shipping methods without an address.
This commit is contained in:
parent
8504a34c65
commit
9838d20458
6 changed files with 134 additions and 59 deletions
Binary file not shown.
|
|
@ -36,6 +36,7 @@ my $session = start(); # this line required
|
||||||
addWikiSubKeywords($session);
|
addWikiSubKeywords($session);
|
||||||
addSynopsistoEachWikiPage($session);
|
addSynopsistoEachWikiPage($session);
|
||||||
dropVisitorAddressBooks($session);
|
dropVisitorAddressBooks($session);
|
||||||
|
alterCartTable($session);
|
||||||
alterAddressBookTable($session);
|
alterAddressBookTable($session);
|
||||||
addWizardHandler( $session );
|
addWizardHandler( $session );
|
||||||
|
|
||||||
|
|
@ -125,6 +126,15 @@ sub alterAddressBookTable {
|
||||||
print "DONE!\n" unless $quiet;
|
print "DONE!\n" unless $quiet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub alterCartTable {
|
||||||
|
my $session = shift;
|
||||||
|
print "\tAdd billing address column to the Cart table... " unless $quiet;
|
||||||
|
# and here's our code
|
||||||
|
$session->db->write("ALTER TABLE cart ADD COLUMN billingAddressId CHAR(22)");
|
||||||
|
print "DONE!\n" unless $quiet;
|
||||||
|
}
|
||||||
|
|
||||||
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -367,6 +367,51 @@ sub newByUserId {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 processAddressForm ( $prefix )
|
||||||
|
|
||||||
|
Process the current set of form variables for any belonging to the address book. Returns
|
||||||
|
a hash ref of address information.
|
||||||
|
|
||||||
|
=head3 $prefix
|
||||||
|
|
||||||
|
An optional prefix to be added to each form variable.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub processAddressForm {
|
||||||
|
my ($self, $prefix) = @_;
|
||||||
|
$prefix ||= '';
|
||||||
|
my $form = $self->session->form;
|
||||||
|
my %addressData = (
|
||||||
|
label => $form->get($prefix . "label"),
|
||||||
|
firstName => $form->get($prefix . "firstName"),
|
||||||
|
lastName => $form->get($prefix . "lastName"),
|
||||||
|
address1 => $form->get($prefix . "address1"),
|
||||||
|
address2 => $form->get($prefix . "address2"),
|
||||||
|
address3 => $form->get($prefix . "address3"),
|
||||||
|
city => $form->get($prefix . "city"),
|
||||||
|
state => $form->get($prefix . "state"),
|
||||||
|
code => $form->get($prefix . "code", "zipcode"),
|
||||||
|
country => $form->get($prefix . "country", "country"),
|
||||||
|
phoneNumber => $form->get($prefix . "phoneNumber", "phone"),
|
||||||
|
email => $form->get($prefix . "email", "email"),
|
||||||
|
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/) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return %addressData;
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 update ( properties )
|
=head2 update ( properties )
|
||||||
|
|
@ -540,46 +585,10 @@ Saves the address. If there is a problem generates www_editAddress() with an err
|
||||||
sub www_editAddressSave {
|
sub www_editAddressSave {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $form = $self->session->form;
|
my $form = $self->session->form;
|
||||||
my $i18n = WebGUI::International->new($self->session,"Shop");
|
my %addressData = $self->processAddressForm();
|
||||||
if ($form->get("label") eq "") {
|
if (exists $addressData{error}) {
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('label')));
|
return $self->www_editAddress($addressData{error});
|
||||||
}
|
}
|
||||||
if ($form->get("firstName") eq "") {
|
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('firstName')));
|
|
||||||
}
|
|
||||||
if ($form->get("lastName") eq "") {
|
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('lastName')));
|
|
||||||
}
|
|
||||||
if ($form->get("address1") eq "") {
|
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('address')));
|
|
||||||
}
|
|
||||||
if ($form->get("city") eq "") {
|
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('city')));
|
|
||||||
}
|
|
||||||
if ($form->get("code") eq "") {
|
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('code')));
|
|
||||||
}
|
|
||||||
if ($form->get("country") eq "") {
|
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('country')));
|
|
||||||
}
|
|
||||||
if ($form->get("phoneNumber") eq "") {
|
|
||||||
return $self->www_editAddress(sprintf($i18n->get('is a required field'), $i18n->get('phone number')));
|
|
||||||
}
|
|
||||||
my %addressData = (
|
|
||||||
label => $form->get("label"),
|
|
||||||
firstName => $form->get("firstName"),
|
|
||||||
lastName => $form->get("lastName"),
|
|
||||||
address1 => $form->get("address1"),
|
|
||||||
address2 => $form->get("address2"),
|
|
||||||
address3 => $form->get("address3"),
|
|
||||||
city => $form->get("city"),
|
|
||||||
state => $form->get("state"),
|
|
||||||
code => $form->get("code","zipcode"),
|
|
||||||
country => $form->get("country","country"),
|
|
||||||
phoneNumber => $form->get("phoneNumber","phone"),
|
|
||||||
email => $form->get("email","email"),
|
|
||||||
organization => $form->get("organization"),
|
|
||||||
);
|
|
||||||
if ($form->get('addressId') eq '') {
|
if ($form->get('addressId') eq '') {
|
||||||
$self->addAddress(\%addressData);
|
$self->addAddress(\%addressData);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -565,6 +565,10 @@ A hash reference that contains one of the following:
|
||||||
|
|
||||||
The unique id for a shipping address attached to this cart.
|
The unique id for a shipping address attached to this cart.
|
||||||
|
|
||||||
|
=head4 billingAddressId
|
||||||
|
|
||||||
|
The unique id for a billing address attached to this cart.
|
||||||
|
|
||||||
=head4 shipperId
|
=head4 shipperId
|
||||||
|
|
||||||
The unique id of the configured shipping driver that will be used to ship these goods.
|
The unique id of the configured shipping driver that will be used to ship these goods.
|
||||||
|
|
@ -585,7 +589,7 @@ sub update {
|
||||||
WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref.");
|
WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref.");
|
||||||
}
|
}
|
||||||
my $id = id $self;
|
my $id = id $self;
|
||||||
foreach my $field (qw(shippingAddressId posUserId shipperId creationDate)) {
|
foreach my $field (qw(billingAddressId shippingAddressId posUserId shipperId creationDate)) {
|
||||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||||
}
|
}
|
||||||
$self->session->db->setRow("cart","cartId",$properties{$id});
|
$self->session->db->setRow("cart","cartId",$properties{$id});
|
||||||
|
|
@ -595,7 +599,7 @@ sub update {
|
||||||
|
|
||||||
=head2 updateFromForm ( )
|
=head2 updateFromForm ( )
|
||||||
|
|
||||||
Updates the cart totals.
|
Updates the cart totals from form data.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|
@ -618,8 +622,10 @@ sub updateFromForm {
|
||||||
my $i18n = WebGUI::International->new($self->session, "Shop");
|
my $i18n = WebGUI::International->new($self->session, "Shop");
|
||||||
$error{id $self} = $i18n->get('mixed items warning');
|
$error{id $self} = $i18n->get('mixed items warning');
|
||||||
}
|
}
|
||||||
|
my $book = $self->getAddressBook;
|
||||||
|
#$book->processAddressForm()
|
||||||
my $cartProperties = {};
|
my $cartProperties = {};
|
||||||
$cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' );
|
$cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' );
|
||||||
$self->update( $cartProperties );
|
$self->update( $cartProperties );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -698,6 +704,22 @@ sub www_removeItem {
|
||||||
return $self->www_view;
|
return $self->www_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_setBillingAddress ()
|
||||||
|
|
||||||
|
Sets the billing address for the cart.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_setBillingAddress {
|
||||||
|
my $self = shift;
|
||||||
|
my $form = $self->session->form;
|
||||||
|
$self->update({billingAddressId=>$form->get('billingAddressId')});
|
||||||
|
return $self->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 www_setShippingAddress ()
|
=head2 www_setShippingAddress ()
|
||||||
|
|
@ -710,10 +732,10 @@ sub www_setShippingAddress {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $form = $self->session->form;
|
my $form = $self->session->form;
|
||||||
if ($form->get("itemId") ne "") {
|
if ($form->get("itemId") ne "") {
|
||||||
$self->getItem($form->get("itemId"))->update({shippingAddressId=>$form->get('addressId')});
|
$self->getItem($form->get("itemId"))->update({shippingAddressId=>$form->get('shippingAddressId')});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$self->update({shippingAddressId=>$form->get('addressId')});
|
$self->update({shippingAddressId=>$form->get('shippingAddressId')});
|
||||||
}
|
}
|
||||||
return $self->www_view;
|
return $self->www_view;
|
||||||
}
|
}
|
||||||
|
|
@ -742,11 +764,12 @@ Displays the shopping cart.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub www_view {
|
sub www_view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $url = $session->url;
|
my $url = $session->url;
|
||||||
my $i18n = WebGUI::International->new($session, "Shop");
|
my $form = $session->form;
|
||||||
my @items = ();
|
my $i18n = WebGUI::International->new($session, "Shop");
|
||||||
|
my @items = ();
|
||||||
my $taxDriver = WebGUI::Shop::Tax->getDriver( $session );
|
my $taxDriver = WebGUI::Shop::Tax->getDriver( $session );
|
||||||
|
|
||||||
if($url->forceSecureConnection()){
|
if($url->forceSecureConnection()){
|
||||||
|
|
@ -888,8 +911,6 @@ sub www_view {
|
||||||
#Address form variables
|
#Address form variables
|
||||||
$var{userIsVisitor} = $session->user->isVisitor;
|
$var{userIsVisitor} = $session->user->isVisitor;
|
||||||
if ($var{userIsVisitor}) {
|
if ($var{userIsVisitor}) {
|
||||||
##Make login form
|
|
||||||
#Form variable returnUrl
|
|
||||||
$var{loginFormHeader} = WebGUI::Form::formHeader($session, {action => $session->url->page})
|
$var{loginFormHeader} = WebGUI::Form::formHeader($session, {action => $session->url->page})
|
||||||
. WebGUI::Form::hidden($session,{ name => 'op', value => 'auth'})
|
. WebGUI::Form::hidden($session,{ name => 'op', value => 'auth'})
|
||||||
. WebGUI::Form::hidden($session,{ name => 'method', value => 'login'})
|
. WebGUI::Form::hidden($session,{ name => 'method', value => 'login'})
|
||||||
|
|
@ -906,6 +927,7 @@ sub www_view {
|
||||||
my $addressBook = $self->getAddressBook;
|
my $addressBook = $self->getAddressBook;
|
||||||
$addressBook->appendAddressFormVars(\%var, 'shipping_', {});
|
$addressBook->appendAddressFormVars(\%var, 'shipping_', {});
|
||||||
$addressBook->appendAddressFormVars(\%var, 'billing_', {});
|
$addressBook->appendAddressFormVars(\%var, 'billing_', {});
|
||||||
|
$var{sameShippingAsBilling} = WebGUI::Form::yesNo($session, {name => 'sameShippingAsBilling', value => $form->get('sameShippingAsBilling','yesNo')});
|
||||||
}
|
}
|
||||||
|
|
||||||
# POS variables
|
# POS variables
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,14 @@ sub getDrivers {
|
||||||
=head2 getOptions ( $cart )
|
=head2 getOptions ( $cart )
|
||||||
|
|
||||||
Returns a list of options for the user to ship, along with the cost of using each one. It is a hash of hashrefs,
|
Returns a list of options for the user to ship, along with the cost of using each one. It is a hash of hashrefs,
|
||||||
with the key of the primary hash being the shipperId of the driver, and sub keys of label and price.
|
with the key of the primary hash being the shipperId of the driver, and sub keys of label, price, and whether the
|
||||||
|
price actually exists, to tell the difference between 0 and unknown.
|
||||||
|
|
||||||
|
{
|
||||||
|
label => 'ShipDriver label',
|
||||||
|
price => \d+,
|
||||||
|
hasPrice => 1 || 0,
|
||||||
|
}
|
||||||
|
|
||||||
=head3 $cart
|
=head3 $cart
|
||||||
|
|
||||||
|
|
@ -99,15 +106,24 @@ sub getOptions {
|
||||||
my %options = ();
|
my %options = ();
|
||||||
SHIPPER: foreach my $shipper (@{$self->getShippers()}) {
|
SHIPPER: foreach my $shipper (@{$self->getShippers()}) {
|
||||||
next SHIPPER unless $shipper->get('enabled');
|
next SHIPPER unless $shipper->get('enabled');
|
||||||
my $price = eval { $shipper->calculate($cart) };
|
|
||||||
if (my $e = WebGUI::Error->caught()) {
|
|
||||||
$self->session->log->warn($e->error);
|
|
||||||
next SHIPPER;
|
|
||||||
}
|
|
||||||
next SHIPPER unless $shipper->canUse;
|
next SHIPPER unless $shipper->canUse;
|
||||||
|
my ($price, $hasPrice);
|
||||||
|
if ($cart->get('shippingAddressId')) {
|
||||||
|
my $price = eval { $shipper->calculate($cart) };
|
||||||
|
if (my $e = WebGUI::Error->caught()) {
|
||||||
|
$self->session->log->warn($e->error);
|
||||||
|
next SHIPPER;
|
||||||
|
}
|
||||||
|
$hasPrice = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$price = 0;
|
||||||
|
$hasPrice = 0;
|
||||||
|
}
|
||||||
$options{$shipper->getId} = {
|
$options{$shipper->getId} = {
|
||||||
label => $shipper->get("label"),
|
label => $shipper->get("label"),
|
||||||
price => $price,
|
price => $price,
|
||||||
|
hasPrice => 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return \%options;
|
return \%options;
|
||||||
|
|
|
||||||
|
|
@ -1731,6 +1731,24 @@ our $I18N = {
|
||||||
context => q|commerce setting help|
|
context => q|commerce setting help|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'Billing Address' => {
|
||||||
|
message => q|Billing Address|,
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q|template label for the cart|
|
||||||
|
},
|
||||||
|
|
||||||
|
'Shipping Address' => {
|
||||||
|
message => q|Shipping Address|,
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q|template label for the cart|
|
||||||
|
},
|
||||||
|
|
||||||
|
'use same shipping as billing' => {
|
||||||
|
message => q|Use the same shipping address as billing address.|,
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q|template label for the cart|
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue