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;
# 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;
}

View file

@ -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"})

View file

@ -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;

View file

@ -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|,
},

View file

@ -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;