Require that the user be logged in before entering in address info. Refactor out address form into a method that can called multiple times.
This commit is contained in:
parent
747fa8c922
commit
fbefeaf621
5 changed files with 131 additions and 85 deletions
Binary file not shown.
|
|
@ -143,11 +143,6 @@ our $HELP = {
|
||||||
description => "formFooter help",
|
description => "formFooter help",
|
||||||
required => 1,
|
required => 1,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name => "checkoutButton",
|
|
||||||
description => "checkoutButton help",
|
|
||||||
required => 1,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name => "updateButton",
|
name => "updateButton",
|
||||||
description => "updateButton help",
|
description => "updateButton help",
|
||||||
|
|
@ -157,15 +152,6 @@ our $HELP = {
|
||||||
name => "continueShoppingButton",
|
name => "continueShoppingButton",
|
||||||
description => "continueShoppingButton help",
|
description => "continueShoppingButton help",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name => "chooseShippingButton",
|
|
||||||
description => "chooseShippingButton help",
|
|
||||||
required => 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name => "shipToButton",
|
|
||||||
description => "shipToButton help",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name => "subtotalPrice",
|
name => "subtotalPrice",
|
||||||
description => "subtotalPrice help",
|
description => "subtotalPrice help",
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,58 @@ sub getAddresses {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getAddressFormVars ( $properties, $prefix )
|
||||||
|
|
||||||
|
Return a hashref of template variables for building a form to edit an address.
|
||||||
|
|
||||||
|
=head3 $properties
|
||||||
|
|
||||||
|
A hash ref of properties to assign to as default to the form variables.
|
||||||
|
|
||||||
|
=head3 $prefix
|
||||||
|
|
||||||
|
An optional prefix to add to each variable name, and form name.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getAddressFormVars {
|
||||||
|
my ($self, $prefix, $properties ) = @_;
|
||||||
|
my $session = $self->session;
|
||||||
|
$properties ||= {};
|
||||||
|
$prefix ||= '';
|
||||||
|
my $var = {};
|
||||||
|
for ( qw{ address1 address2 address3 label firstName lastName city state organization } ) {
|
||||||
|
$var->{ $prefix . $_ . 'Field' } = WebGUI::Form::text( $session, {
|
||||||
|
name => $prefix . $_,
|
||||||
|
maxlength => 35,
|
||||||
|
defaultValue => $properties->{ $_ }
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
$var->{ $prefix . 'countryField' } =
|
||||||
|
WebGUI::Form::country( $session,{
|
||||||
|
name => $prefix . 'country',
|
||||||
|
defaultValue => $properties->{ country }
|
||||||
|
} );
|
||||||
|
$var->{ $prefix . 'codeField' } =
|
||||||
|
WebGUI::Form::zipcode( $session, {
|
||||||
|
name => $prefix . 'code',
|
||||||
|
defaultValue => $properties->{ code }
|
||||||
|
} );
|
||||||
|
$var->{ $prefix . 'phoneNumberField' } =
|
||||||
|
WebGUI::Form::phone( $session, {
|
||||||
|
name => $prefix . 'phoneNumber',
|
||||||
|
defaultValue => $properties->{ phoneNumber }
|
||||||
|
} );
|
||||||
|
$var->{ $prefix . 'emailField' } =
|
||||||
|
WebGUI::Form::email( $session, {
|
||||||
|
name => $prefix . 'email',
|
||||||
|
defaultValue => $properties->{ email }
|
||||||
|
} );
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 getDefaultAddress ()
|
=head2 getDefaultAddress ()
|
||||||
|
|
||||||
Returns the default address for this address book if there is one. Otherwise throws a WebGUI::Error::ObjectNotFound exception.
|
Returns the default address for this address book if there is one. Otherwise throws a WebGUI::Error::ObjectNotFound exception.
|
||||||
|
|
|
||||||
|
|
@ -798,9 +798,8 @@ sub www_view {
|
||||||
price => $self->formatCurrency($sku->getPrice),
|
price => $self->formatCurrency($sku->getPrice),
|
||||||
removeButton => WebGUI::Form::submit($session, {value=>$i18n->get("remove button"),
|
removeButton => WebGUI::Form::submit($session, {value=>$i18n->get("remove button"),
|
||||||
extras=>q|onclick="this.form.method.value='removeItem';this.form.itemId.value='|.$item->getId.q|';this.form.submit;"|}),
|
extras=>q|onclick="this.form.method.value='removeItem';this.form.itemId.value='|.$item->getId.q|';this.form.submit;"|}),
|
||||||
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
|
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("Special shipping"), }),
|
||||||
extras=>q|onclick="setCallbackForAddressChooser(this.form,'|.$item->getId.q|');"|}),
|
);
|
||||||
);
|
|
||||||
my $itemAddress = eval {$item->getShippingAddress};
|
my $itemAddress = eval {$item->getShippingAddress};
|
||||||
if ((!WebGUI::Error->caught) && $itemAddress && $address && $itemAddress->getId ne $address->getId) {
|
if ((!WebGUI::Error->caught) && $itemAddress && $address && $itemAddress->getId ne $address->getId) {
|
||||||
$properties{shippingAddress} = $itemAddress->getHtmlFormatted;
|
$properties{shippingAddress} = $itemAddress->getHtmlFormatted;
|
||||||
|
|
@ -823,14 +822,12 @@ sub www_view {
|
||||||
. WebGUI::Form::hidden($session, {name=>"callback", value=>""}),
|
. WebGUI::Form::hidden($session, {name=>"callback", value=>""}),
|
||||||
formFooter => WebGUI::Form::formFooter($session),
|
formFooter => WebGUI::Form::formFooter($session),
|
||||||
updateButton => WebGUI::Form::submit($session, {value=>$i18n->get("update cart button"), extras=>q|id="updateCartButton"|}),
|
updateButton => WebGUI::Form::submit($session, {value=>$i18n->get("update cart button"), extras=>q|id="updateCartButton"|}),
|
||||||
checkoutButton => WebGUI::Form::submit($session, {value=>$i18n->get("checkout button"),
|
|
||||||
extras=>q|onclick="this.form.method.value='checkout';this.form.submit;" id="checkoutButton"|}),
|
|
||||||
continueShoppingButton => WebGUI::Form::submit($session, {value=>$i18n->get("continue shopping button"),
|
continueShoppingButton => WebGUI::Form::submit($session, {value=>$i18n->get("continue shopping button"),
|
||||||
extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;" id="continueShoppingButton"|}),
|
extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;" id="continueShoppingButton"|}),
|
||||||
chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"),
|
# chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"),
|
||||||
extras=>q|onclick="setCallbackForAddressChooser(this.form);" id="chooseAddressButton"|}),
|
# extras=>q|onclick="setCallbackForAddressChooser(this.form);" id="chooseAddressButton"|}),
|
||||||
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
|
# shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
|
||||||
extras=>q|onclick="setCallbackForAddressChooser(this.form);"|}),
|
# extras=>q|onclick="setCallbackForAddressChooser(this.form);"|}),
|
||||||
subtotalPrice => $self->formatCurrency($self->calculateSubtotal()),
|
subtotalPrice => $self->formatCurrency($self->calculateSubtotal()),
|
||||||
minimumCartAmount => $session->setting->get( 'shopCartCheckoutMinimum' ) > 0
|
minimumCartAmount => $session->setting->get( 'shopCartCheckoutMinimum' ) > 0
|
||||||
? sprintf( '%.2f', $session->setting->get( 'shopCartCheckoutMinimum' ) )
|
? sprintf( '%.2f', $session->setting->get( 'shopCartCheckoutMinimum' ) )
|
||||||
|
|
@ -839,51 +836,74 @@ sub www_view {
|
||||||
);
|
);
|
||||||
|
|
||||||
# if there is no shipping address we can't check out
|
# if there is no shipping address we can't check out
|
||||||
if (WebGUI::Error->caught) {
|
# if (WebGUI::Error->caught) {
|
||||||
$var{shippingPrice} = $var{tax} = $self->formatCurrency(0);
|
# $var{shippingPrice} = $var{tax} = $self->formatCurrency(0);
|
||||||
}
|
# }
|
||||||
|
#
|
||||||
|
# # if there is a shipping address calculate tax and shipping options
|
||||||
|
# if ($address) {
|
||||||
|
# $var{hasShippingAddress} = 1;
|
||||||
|
# $var{shippingAddress} = $address->getHtmlFormatted;
|
||||||
|
# my $ship = WebGUI::Shop::Ship->new($self->session);
|
||||||
|
# my $options = $ship->getOptions($self);
|
||||||
|
# my $numberOfOptions = scalar keys %{ $options };
|
||||||
|
# if ($numberOfOptions < 1) {
|
||||||
|
# $var{shippingOptions} = '';
|
||||||
|
# $var{shippingPrice} = 0;
|
||||||
|
# $error{id $self} = $i18n->get("No shipping plugins configured");
|
||||||
|
# }
|
||||||
|
# elsif ($numberOfOptions == 1) {
|
||||||
|
# my ($option) = keys %{ $options };
|
||||||
|
# $self->update({ shipperId => $option });
|
||||||
|
# $var{shippingPrice} = $options->{$self->get("shipperId")}->{price};
|
||||||
|
# $var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
||||||
|
# }
|
||||||
|
# else {
|
||||||
|
# tie my %formOptions, 'Tie::IxHash';
|
||||||
|
# $formOptions{''} = $i18n->get('Choose a shipping method');
|
||||||
|
# foreach my $option (keys %{$options}) {
|
||||||
|
# $formOptions{$option} = $options->{$option}{label}." (".$self->formatCurrency($options->{$option}{price}).")";
|
||||||
|
# }
|
||||||
|
# $var{shippingOptions} = WebGUI::Form::selectBox($session, {name=>"shipperId", options=>\%formOptions, value=>$self->get("shipperId")});
|
||||||
|
# if (!exists $options->{$self->get('shipperId')}) {
|
||||||
|
# $self->update({shipperId => ''});
|
||||||
|
# }
|
||||||
|
# if (my $shipperId = $self->get('shipperId')) {
|
||||||
|
# $var{shippingPrice} = $options->{$shipperId}->{price};
|
||||||
|
# }
|
||||||
|
# else {
|
||||||
|
# $var{shippingPrice} = 0;
|
||||||
|
# $error{id $self} = ($i18n->get('Choose a shipping method and update the cart to checkout'));
|
||||||
|
# }
|
||||||
|
# $var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# # Tax variables
|
||||||
|
# $var{tax} = $self->calculateTaxes;
|
||||||
|
|
||||||
# if there is a shipping address calculate tax and shipping options
|
#Address form variables
|
||||||
if ($address) {
|
$var{userIsVisitor} = $session->user->isVisitor;
|
||||||
$var{hasShippingAddress} = 1;
|
if ($var{userIsVisitor}) {
|
||||||
$var{shippingAddress} = $address->getHtmlFormatted;
|
##Make login form
|
||||||
my $ship = WebGUI::Shop::Ship->new($self->session);
|
#Form variable returnUrl
|
||||||
my $options = $ship->getOptions($self);
|
$var{loginFormHeader} = WebGUI::Form::formHeader($session, {action => $session->url->page})
|
||||||
my $numberOfOptions = scalar keys %{ $options };
|
. WebGUI::Form::hidden($session,{ name => 'op', value => 'auth'})
|
||||||
if ($numberOfOptions < 1) {
|
. WebGUI::Form::hidden($session,{ name => 'method', value => 'login'})
|
||||||
$var{shippingOptions} = '';
|
;
|
||||||
$var{shippingPrice} = 0;
|
$var{loginFormUsername} = WebGUI::Form::text($session, { name => 'username', size => 12, });
|
||||||
$error{id $self} = $i18n->get("No shipping plugins configured");
|
$var{loginFormPassword} = WebGUI::Form::password($session, { name => 'identifier', size => 12, });
|
||||||
}
|
$var{loginFormButton} = WebGUI::Form::submit($session, { value => $i18n->get(52,'WebGUI'), });
|
||||||
elsif ($numberOfOptions == 1) {
|
$var{registerLink} = $session->url->page('op=auth;method=createAccount');
|
||||||
my ($option) = keys %{ $options };
|
$session->scratch->set('redirectAfterLogin', $session->url->page('shop=cart'));
|
||||||
$self->update({ shipperId => $option });
|
$var{loginFormFooter} = WebGUI::Form::formFooter($session)
|
||||||
$var{shippingPrice} = $options->{$self->get("shipperId")}->{price};
|
}
|
||||||
$var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
else {
|
||||||
}
|
##Address form variables
|
||||||
else {
|
my $addressBook = $self->getAddressBook;
|
||||||
tie my %formOptions, 'Tie::IxHash';
|
%var = (%var, $addressBook->getAddressFormVars('shipping', {}));
|
||||||
$formOptions{''} = $i18n->get('Choose a shipping method');
|
%var = (%var, $addressBook->getAddressFormVars('billing', {}));
|
||||||
foreach my $option (keys %{$options}) {
|
|
||||||
$formOptions{$option} = $options->{$option}{label}." (".$self->formatCurrency($options->{$option}{price}).")";
|
|
||||||
}
|
|
||||||
$var{shippingOptions} = WebGUI::Form::selectBox($session, {name=>"shipperId", options=>\%formOptions, value=>$self->get("shipperId")});
|
|
||||||
if (!exists $options->{$self->get('shipperId')}) {
|
|
||||||
$self->update({shipperId => ''});
|
|
||||||
}
|
|
||||||
if (my $shipperId = $self->get('shipperId')) {
|
|
||||||
$var{shippingPrice} = $options->{$shipperId}->{price};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$var{shippingPrice} = 0;
|
|
||||||
$error{id $self} = ($i18n->get('Choose a shipping method and update the cart to checkout'));
|
|
||||||
}
|
|
||||||
$var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Tax variables
|
|
||||||
$var{tax} = $self->calculateTaxes;
|
|
||||||
|
|
||||||
# POS variables
|
# POS variables
|
||||||
$var{isCashier} = WebGUI::Shop::Admin->new($session)->isCashier;
|
$var{isCashier} = WebGUI::Shop::Admin->new($session)->isCashier;
|
||||||
|
|
@ -895,7 +915,7 @@ sub www_view {
|
||||||
$var{posUserId} = $posUser->userId;
|
$var{posUserId} = $posUser->userId;
|
||||||
|
|
||||||
# calculate price adjusted for in-store credit
|
# calculate price adjusted for in-store credit
|
||||||
$var{totalPrice} = $var{subtotalPrice} + $var{shippingPrice} + $var{tax};
|
$var{totalPrice} = $var{subtotalPrice}; # + $var{shippingPrice} + $var{tax};
|
||||||
my $credit = WebGUI::Shop::Credit->new($session, $posUser->userId);
|
my $credit = WebGUI::Shop::Credit->new($session, $posUser->userId);
|
||||||
$var{ inShopCreditAvailable } = $credit->getSum;
|
$var{ inShopCreditAvailable } = $credit->getSum;
|
||||||
$var{ inShopCreditDeduction } = $credit->calculateDeduction($var{totalPrice});
|
$var{ inShopCreditDeduction } = $credit->calculateDeduction($var{totalPrice});
|
||||||
|
|
|
||||||
|
|
@ -201,12 +201,6 @@ our $I18N = {
|
||||||
context => q|a help description|,
|
context => q|a help description|,
|
||||||
},
|
},
|
||||||
|
|
||||||
'checkoutButton help' => {
|
|
||||||
message => q|The button the user pushes to choose a payment method.|,
|
|
||||||
lastUpdated => 0,
|
|
||||||
context => q|a help description|,
|
|
||||||
},
|
|
||||||
|
|
||||||
'continueShoppingButton help' => {
|
'continueShoppingButton help' => {
|
||||||
message => q|Clicking this button will take the user back to the site.|,
|
message => q|Clicking this button will take the user back to the site.|,
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
|
|
@ -219,18 +213,6 @@ our $I18N = {
|
||||||
context => q|a help description|,
|
context => q|a help description|,
|
||||||
},
|
},
|
||||||
|
|
||||||
'chooseShippingButton help' => {
|
|
||||||
message => q|Clicking this button will let the user pick a shipping address from the address book.|,
|
|
||||||
lastUpdated => 0,
|
|
||||||
context => q|a help description|,
|
|
||||||
},
|
|
||||||
|
|
||||||
'shipToButton help' => {
|
|
||||||
message => q|Does the same as the chooseShippingButton.|,
|
|
||||||
lastUpdated => 0,
|
|
||||||
context => q|a help description|,
|
|
||||||
},
|
|
||||||
|
|
||||||
'subtotalPrice help' => {
|
'subtotalPrice help' => {
|
||||||
message => q|The price of all the items in the cart.|,
|
message => q|The price of all the items in the cart.|,
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
|
|
@ -976,6 +958,12 @@ our $I18N = {
|
||||||
context => q|a button the user clicks on to set shipping information|
|
context => q|a button the user clicks on to set shipping information|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'Special shipping' => {
|
||||||
|
message => q|Special shipping|,
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q|a button the user clicks on to set shipping information on an item|
|
||||||
|
},
|
||||||
|
|
||||||
'shipping address' => {
|
'shipping address' => {
|
||||||
message => q|Shipping Address|,
|
message => q|Shipping Address|,
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue