From fbefeaf621843ebc06dd52572758ee7a8c44fb01 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 22 Apr 2010 20:02:19 -0700 Subject: [PATCH] Require that the user be logged in before entering in address info. Refactor out address form into a method that can called multiple times. --- .../default-shopping-cart-template.wgpkg | Bin 0 -> 3299 bytes lib/WebGUI/Help/Shop.pm | 14 -- lib/WebGUI/Shop/AddressBook.pm | 52 ++++++++ lib/WebGUI/Shop/Cart.pm | 126 ++++++++++-------- lib/WebGUI/i18n/English/Shop.pm | 24 +--- 5 files changed, 131 insertions(+), 85 deletions(-) create mode 100644 docs/upgrades/packages-7.9.4/default-shopping-cart-template.wgpkg diff --git a/docs/upgrades/packages-7.9.4/default-shopping-cart-template.wgpkg b/docs/upgrades/packages-7.9.4/default-shopping-cart-template.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..da35d5d7b3b61ee9a81bbb4e738578f932d6f310 GIT binary patch literal 3299 zcmV<93>@OZ|+Z*OmBZLQby_jY>t zv*&MbudR9J(_8cXt=;X--tKnKU-Nvw=fe+JvieVviy#A*MoGlutM>hhoMn0YFbV}9 z5{`b(nfkvpL|ps!`_?P^eRtz?p2SOH6e#ZQg1wvVzqRS_?N#i*y|vj}^FW)c|E$XX z8>?r189Utn1VOki*es0#!7c+Kg3)xwVv(!Mmg@Fi=)&fgM(oCk%p1&!CNaB~z zMpHJrN(v$WzK7(NWc`~d7i=&DZA`MHh{KM2Jjob~8zc%Mfh^SKKRfB+SL=$6kVQUh9e9Fo6hGVkQJeL0?F~`iMXr#4Mb#|r$GkE zWuP=d(b$iZn6*VVVF@-C1e zm)Q86PF@UNc<{G}p6SI&Cu1pOt+_0aHJ8By8Q5il9xTFz4TY!j;Y5h$L_S(rBXasu zl%kj^=|yp~sA_UZI3rOBUrabo`b1k-EevT}?xe%1ltEMkLFlL`YFLiWsY1~PxwG)u zcsw3_JLr<5AKJo|+{7&V2rcEQtV>RzER`-QS{I_VY+b|`0>8@T=w3g*5cNt{8M8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@ our $HELP = { description => "formFooter help", required => 1, }, - { - name => "checkoutButton", - description => "checkoutButton help", - required => 1, - }, { name => "updateButton", description => "updateButton help", @@ -157,15 +152,6 @@ our $HELP = { name => "continueShoppingButton", description => "continueShoppingButton help", }, - { - name => "chooseShippingButton", - description => "chooseShippingButton help", - required => 1, - }, - { - name => "shipToButton", - description => "shipToButton help", - }, { name => "subtotalPrice", description => "subtotalPrice help", diff --git a/lib/WebGUI/Shop/AddressBook.pm b/lib/WebGUI/Shop/AddressBook.pm index c03830f1f..063617703 100644 --- a/lib/WebGUI/Shop/AddressBook.pm +++ b/lib/WebGUI/Shop/AddressBook.pm @@ -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 () Returns the default address for this address book if there is one. Otherwise throws a WebGUI::Error::ObjectNotFound exception. diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 3654a5417..1c6eb5587 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -798,9 +798,8 @@ sub www_view { price => $self->formatCurrency($sku->getPrice), 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;"|}), - shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"), - extras=>q|onclick="setCallbackForAddressChooser(this.form,'|.$item->getId.q|');"|}), - ); + shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("Special shipping"), }), + ); my $itemAddress = eval {$item->getShippingAddress}; if ((!WebGUI::Error->caught) && $itemAddress && $address && $itemAddress->getId ne $address->getId) { $properties{shippingAddress} = $itemAddress->getHtmlFormatted; @@ -823,14 +822,12 @@ sub www_view { . WebGUI::Form::hidden($session, {name=>"callback", value=>""}), formFooter => WebGUI::Form::formFooter($session), 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"), extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;" id="continueShoppingButton"|}), - chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"), - extras=>q|onclick="setCallbackForAddressChooser(this.form);" id="chooseAddressButton"|}), - shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"), - extras=>q|onclick="setCallbackForAddressChooser(this.form);"|}), +# chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"), +# extras=>q|onclick="setCallbackForAddressChooser(this.form);" id="chooseAddressButton"|}), +# shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"), +# extras=>q|onclick="setCallbackForAddressChooser(this.form);"|}), subtotalPrice => $self->formatCurrency($self->calculateSubtotal()), minimumCartAmount => $session->setting->get( 'shopCartCheckoutMinimum' ) > 0 ? 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 (WebGUI::Error->caught) { - $var{shippingPrice} = $var{tax} = $self->formatCurrency(0); - } +# if (WebGUI::Error->caught) { +# $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 - 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}); - } + #Address form variables + $var{userIsVisitor} = $session->user->isVisitor; + if ($var{userIsVisitor}) { + ##Make login form + #Form variable returnUrl + $var{loginFormHeader} = WebGUI::Form::formHeader($session, {action => $session->url->page}) + . WebGUI::Form::hidden($session,{ name => 'op', value => 'auth'}) + . WebGUI::Form::hidden($session,{ name => 'method', value => 'login'}) + ; + $var{loginFormUsername} = WebGUI::Form::text($session, { name => 'username', size => 12, }); + $var{loginFormPassword} = WebGUI::Form::password($session, { name => 'identifier', size => 12, }); + $var{loginFormButton} = WebGUI::Form::submit($session, { value => $i18n->get(52,'WebGUI'), }); + $var{registerLink} = $session->url->page('op=auth;method=createAccount'); + $session->scratch->set('redirectAfterLogin', $session->url->page('shop=cart')); + $var{loginFormFooter} = WebGUI::Form::formFooter($session) + } + else { + ##Address form variables + my $addressBook = $self->getAddressBook; + %var = (%var, $addressBook->getAddressFormVars('shipping', {})); + %var = (%var, $addressBook->getAddressFormVars('billing', {})); } - - # Tax variables - $var{tax} = $self->calculateTaxes; # POS variables $var{isCashier} = WebGUI::Shop::Admin->new($session)->isCashier; @@ -895,7 +915,7 @@ sub www_view { $var{posUserId} = $posUser->userId; # 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); $var{ inShopCreditAvailable } = $credit->getSum; $var{ inShopCreditDeduction } = $credit->calculateDeduction($var{totalPrice}); diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index 5362fcb69..e1b8e075d 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -201,12 +201,6 @@ our $I18N = { 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' => { message => q|Clicking this button will take the user back to the site.|, lastUpdated => 0, @@ -219,18 +213,6 @@ our $I18N = { 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' => { message => q|The price of all the items in the cart.|, lastUpdated => 0, @@ -976,6 +958,12 @@ our $I18N = { 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' => { message => q|Shipping Address|, lastUpdated => 0,