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 index a76453951..4c412e09d 100644 Binary files a/docs/upgrades/packages-7.9.4/default-shopping-cart-template.wgpkg and b/docs/upgrades/packages-7.9.4/default-shopping-cart-template.wgpkg differ diff --git a/docs/upgrades/upgrade_7.9.3-7.9.4.pl b/docs/upgrades/upgrade_7.9.3-7.9.4.pl index 4692e1ecd..d247e6ddb 100644 --- a/docs/upgrades/upgrade_7.9.3-7.9.4.pl +++ b/docs/upgrades/upgrade_7.9.3-7.9.4.pl @@ -146,6 +146,7 @@ sub alterCartTable { 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)"); + $session->db->write("ALTER TABLE cart ADD COLUMN gatewayId CHAR(22)"); print "DONE!\n" unless $quiet; } diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 95b7a0836..571b56fb8 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -12,6 +12,7 @@ use WebGUI::Shop::AddressBook; use WebGUI::Shop::CartItem; use WebGUI::Shop::Credit; use WebGUI::Shop::Ship; +use WebGUI::Shop::Pay; use WebGUI::Shop::Tax; use WebGUI::User; use Tie::IxHash; @@ -645,12 +646,13 @@ sub updateFromForm { my $book = $self->getAddressBook; + my $cartProperties = {}; my %billingData = $book->processAddressForm('billing_'); my $billingAddressId = $form->process('billingAddressId'); if ($billingAddressId eq 'new_address' && ! exists $billingData{'error'}) { ##Add a new address my $newAddress = $book->addAddress(\%billingData); - $self->update({billingAddressId => $newAddress->get('addressId'), }); + $cartProperties{billingAddressId} = $newAddress->get('addressId'); } elsif ($billingAddressId eq 'update_address' && $self->get('billingAddressId')) { ##User changed the address selector @@ -658,7 +660,7 @@ sub updateFromForm { $address->update(\%billingData); } elsif ($billingAddressId ne 'new_address' && $billingAddressId) { - $self->update({billingAddressId => $billingAddressId}); + $cartProperties{billingAddressId} = $billingAddressId; } else { $self->session->log->warn('billing address: something else: '. $billingData{error}); @@ -667,12 +669,12 @@ sub updateFromForm { my %shippingData = $book->processAddressForm('shipping_'); my $shippingAddressId = $form->process('shippingAddressId'); if ($form->process('sameShippingAsBilling', 'yesNo')) { - $self->update({shippingAddressId => $self->get('billingAddressId'), }); + $cartProperties{shippingAddressId} = $self->get('billingAddressId'); } elsif ($shippingAddressId eq 'new_address' && ! exists $shippingData{'error'}) { ##Add a new address my $newAddress = $book->addAddress(\%shippingData); - $self->update({shippingAddressId => $newAddress->get('addressId'), }); + $cartProperties{shippingAddressId} = $newAddress->get('addressId'); } elsif ($shippingAddressId eq 'update_address' && $self->get('shippingAddressId')) { ##User changed the address selector @@ -680,14 +682,14 @@ sub updateFromForm { $address->update(\%shippingData); } elsif ($shippingAddressId ne 'new_address' && $shippingAddressId) { - $self->update({shippingAddressId => $shippingAddressId}); + $cartProperties{shippingAddressId} = $shippingAddressId}; } else { $self->session->log->warn('shipping address: something else: '. $shippingData{error}); } - my $cartProperties = {}; $cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' ); + $cartProperties->{ gatewayId } = $form->process( 'gatewayId' ) if $form->process( 'gatewayId' ); $self->update( $cartProperties ); } @@ -897,6 +899,7 @@ sub www_view { , 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, {name => 'checkout', value=>$i18n->get("checkout button"), extras=>q|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"|}), subtotalPrice => $self->formatCurrency($self->calculateSubtotal()), @@ -1011,6 +1014,20 @@ sub www_view { }); } + # Payment methods + my $pay = WebGUI::Shop::Pay->new($session); + tie my %paymentOptions, 'Tie::IxHash'; + $paymentOptions{''} = $i18n->get('Choose a payment method'); + my $gateways = $pay->getOptions($self); + while (my ($gatewayId, $label) = each %{ $gateways }) { + $paymentOptions{$gatewayId} = $label; + } + $var{paymentOptions} = WebGUI::Form::selectBox($session, { + name => 'gatewayId', + options => \%paymentOptions, + value => $self->get('gatewayId') || $form->get('gatewayId') || '', + }); + # POS variables $var{isCashier} = WebGUI::Shop::Admin->new($session)->isCashier; $var{posLookupForm} = WebGUI::Form::email($session, {name=>"posEmail"}) diff --git a/lib/WebGUI/Shop/Pay.pm b/lib/WebGUI/Shop/Pay.pm index 45a3438eb..7f0d83f6a 100644 --- a/lib/WebGUI/Shop/Pay.pm +++ b/lib/WebGUI/Shop/Pay.pm @@ -104,9 +104,9 @@ sub getDrivers { =head2 getOptions ( $cart ) Returns a set of options for the user to pay to. It is a hash of -hashrefs, with the key of the primary hash being the paymentGatewayId -of the driver, and sub keys of label and button. The hash will only -contain payment gateways that this user is allowed to use. +gatewayIds and labels. + +The hash will only contain payment gateways that this user is allowed to use. =head3 $cart @@ -120,17 +120,13 @@ sub getOptions { WebGUI::Error::InvalidParam->throw(error => q{Need a cart.}) unless defined $cart and $cart->isa("WebGUI::Shop::Cart"); - my $session = $cart->session; my $recurringRequired = $cart->requiresRecurringPayment; my %options = (); foreach my $gateway (@{ $self->getPaymentGateways() }) { next unless $gateway->canUse; if (!$recurringRequired || $gateway->handlesRecurring) { - $options{$gateway->getId} = { - label => $gateway->get("label"), - button => $gateway->getButton( $cart ), - }; + $options{$gateway->getId} = $gateway->get("label"); } } return \%options; diff --git a/lib/WebGUI/i18n/English/PayDriver.pm b/lib/WebGUI/i18n/English/PayDriver.pm index 3da096822..c91fb0341 100644 --- a/lib/WebGUI/i18n/English/PayDriver.pm +++ b/lib/WebGUI/i18n/English/PayDriver.pm @@ -77,7 +77,7 @@ our $I18N = { }, 'payment methods' => { - message => q|Payment Methods.|, + message => q|Payment Methods|, lastUpdated => 1213313375, context => q|Help body for the email receipt template|, }, diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index 48e086ab5..616630df4 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -1761,6 +1761,12 @@ our $I18N = { context => q|form label for the cart. Allows user to build a new address.| }, + 'Choose a payment method' => { + message => q|Choose a payment method|, + lastUpdated => 0, + context => q|form label for the cart. Allows user to choose a payment method. Bart Jol for Minister in 2012!| + }, + }; 1;