Checkout preparations. Change payment options to a dropdown in the cart. Pay->getOptions now returns just a hash.

This commit is contained in:
Colin Kuskie 2010-04-27 12:02:32 -07:00
parent b8098fb73b
commit 7ef8de2a1f
6 changed files with 35 additions and 15 deletions

View file

@ -146,6 +146,7 @@ sub alterCartTable {
print "\tAdd billing address column to the Cart table... " unless $quiet; print "\tAdd billing address column to the Cart table... " unless $quiet;
# and here's our code # and here's our code
$session->db->write("ALTER TABLE cart ADD COLUMN billingAddressId CHAR(22)"); $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; print "DONE!\n" unless $quiet;
} }

View file

@ -12,6 +12,7 @@ use WebGUI::Shop::AddressBook;
use WebGUI::Shop::CartItem; use WebGUI::Shop::CartItem;
use WebGUI::Shop::Credit; use WebGUI::Shop::Credit;
use WebGUI::Shop::Ship; use WebGUI::Shop::Ship;
use WebGUI::Shop::Pay;
use WebGUI::Shop::Tax; use WebGUI::Shop::Tax;
use WebGUI::User; use WebGUI::User;
use Tie::IxHash; use Tie::IxHash;
@ -645,12 +646,13 @@ sub updateFromForm {
my $book = $self->getAddressBook; my $book = $self->getAddressBook;
my $cartProperties = {};
my %billingData = $book->processAddressForm('billing_'); my %billingData = $book->processAddressForm('billing_');
my $billingAddressId = $form->process('billingAddressId'); my $billingAddressId = $form->process('billingAddressId');
if ($billingAddressId eq 'new_address' && ! exists $billingData{'error'}) { if ($billingAddressId eq 'new_address' && ! exists $billingData{'error'}) {
##Add a new address ##Add a new address
my $newAddress = $book->addAddress(\%billingData); my $newAddress = $book->addAddress(\%billingData);
$self->update({billingAddressId => $newAddress->get('addressId'), }); $cartProperties{billingAddressId} = $newAddress->get('addressId');
} }
elsif ($billingAddressId eq 'update_address' && $self->get('billingAddressId')) { elsif ($billingAddressId eq 'update_address' && $self->get('billingAddressId')) {
##User changed the address selector ##User changed the address selector
@ -658,7 +660,7 @@ sub updateFromForm {
$address->update(\%billingData); $address->update(\%billingData);
} }
elsif ($billingAddressId ne 'new_address' && $billingAddressId) { elsif ($billingAddressId ne 'new_address' && $billingAddressId) {
$self->update({billingAddressId => $billingAddressId}); $cartProperties{billingAddressId} = $billingAddressId;
} }
else { else {
$self->session->log->warn('billing address: something else: '. $billingData{error}); $self->session->log->warn('billing address: something else: '. $billingData{error});
@ -667,12 +669,12 @@ sub updateFromForm {
my %shippingData = $book->processAddressForm('shipping_'); my %shippingData = $book->processAddressForm('shipping_');
my $shippingAddressId = $form->process('shippingAddressId'); my $shippingAddressId = $form->process('shippingAddressId');
if ($form->process('sameShippingAsBilling', 'yesNo')) { if ($form->process('sameShippingAsBilling', 'yesNo')) {
$self->update({shippingAddressId => $self->get('billingAddressId'), }); $cartProperties{shippingAddressId} = $self->get('billingAddressId');
} }
elsif ($shippingAddressId eq 'new_address' && ! exists $shippingData{'error'}) { elsif ($shippingAddressId eq 'new_address' && ! exists $shippingData{'error'}) {
##Add a new address ##Add a new address
my $newAddress = $book->addAddress(\%shippingData); my $newAddress = $book->addAddress(\%shippingData);
$self->update({shippingAddressId => $newAddress->get('addressId'), }); $cartProperties{shippingAddressId} = $newAddress->get('addressId');
} }
elsif ($shippingAddressId eq 'update_address' && $self->get('shippingAddressId')) { elsif ($shippingAddressId eq 'update_address' && $self->get('shippingAddressId')) {
##User changed the address selector ##User changed the address selector
@ -680,14 +682,14 @@ sub updateFromForm {
$address->update(\%shippingData); $address->update(\%shippingData);
} }
elsif ($shippingAddressId ne 'new_address' && $shippingAddressId) { elsif ($shippingAddressId ne 'new_address' && $shippingAddressId) {
$self->update({shippingAddressId => $shippingAddressId}); $cartProperties{shippingAddressId} = $shippingAddressId};
} }
else { else {
$self->session->log->warn('shipping address: something else: '. $shippingData{error}); $self->session->log->warn('shipping address: something else: '. $shippingData{error});
} }
my $cartProperties = {};
$cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' ); $cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' );
$cartProperties->{ gatewayId } = $form->process( 'gatewayId' ) if $form->process( 'gatewayId' );
$self->update( $cartProperties ); $self->update( $cartProperties );
} }
@ -897,6 +899,7 @@ sub www_view {
, ,
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, {name => 'checkout', value=>$i18n->get("checkout button"), extras=>q|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"|}),
subtotalPrice => $self->formatCurrency($self->calculateSubtotal()), 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 # POS variables
$var{isCashier} = WebGUI::Shop::Admin->new($session)->isCashier; $var{isCashier} = WebGUI::Shop::Admin->new($session)->isCashier;
$var{posLookupForm} = WebGUI::Form::email($session, {name=>"posEmail"}) $var{posLookupForm} = WebGUI::Form::email($session, {name=>"posEmail"})

View file

@ -104,9 +104,9 @@ sub getDrivers {
=head2 getOptions ( $cart ) =head2 getOptions ( $cart )
Returns a set of options for the user to pay to. It is a hash of 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 gatewayIds and labels.
of the driver, and sub keys of label and button. The hash will only
contain payment gateways that this user is allowed to use. The hash will only contain payment gateways that this user is allowed to use.
=head3 $cart =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"); 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 $recurringRequired = $cart->requiresRecurringPayment;
my %options = (); my %options = ();
foreach my $gateway (@{ $self->getPaymentGateways() }) { foreach my $gateway (@{ $self->getPaymentGateways() }) {
next unless $gateway->canUse; next unless $gateway->canUse;
if (!$recurringRequired || $gateway->handlesRecurring) { if (!$recurringRequired || $gateway->handlesRecurring) {
$options{$gateway->getId} = { $options{$gateway->getId} = $gateway->get("label");
label => $gateway->get("label"),
button => $gateway->getButton( $cart ),
};
} }
} }
return \%options; return \%options;

View file

@ -77,7 +77,7 @@ our $I18N = {
}, },
'payment methods' => { 'payment methods' => {
message => q|Payment Methods.|, message => q|Payment Methods|,
lastUpdated => 1213313375, lastUpdated => 1213313375,
context => q|Help body for the email receipt template|, context => q|Help body for the email receipt template|,
}, },

View file

@ -1761,6 +1761,12 @@ our $I18N = {
context => q|form label for the cart. Allows user to build a new address.| 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; 1;