Log cart errors for anything that prevents you from checking out. Fix an error in the PayDriver template variables.

This commit is contained in:
Colin Kuskie 2010-04-28 11:48:07 -07:00
parent b316e84feb
commit 5ebd6864cc
2 changed files with 29 additions and 11 deletions

View file

@ -533,12 +533,18 @@ sub readyForCheckout {
# Check if the billing address is set and correct # Check if the billing address is set and correct
my $address = eval{$self->getBillingAddress}; my $address = eval{$self->getBillingAddress};
return 0 if WebGUI::Error->caught; if (WebGUI::Error->caught) {
$self->error('no billing address');
return 0;
}
# Check if the shipping address is set and correct # Check if the shipping address is set and correct
if ($self->requiresShipping) { if ($self->requiresShipping) {
my $shipAddress = eval{$self->getShippingAddress}; my $shipAddress = eval{$self->getShippingAddress};
return 0 if WebGUI::Error->caught; if (WebGUI::Error->caught) {
$self->error('no shipping address');
return 0;
}
} }
# Check if the cart has items # Check if the cart has items
@ -554,12 +560,16 @@ sub readyForCheckout {
return 0; return 0;
} }
my $requiredAmount = $self->session->setting->get( 'shopCartCheckoutMinimum' ); my $requiredAmount = $self->session->setting->get( 'shopCartCheckoutMinimum' );
if ( $requiredAmount > 0 ) { if ( $requiredAmount > 0 && $total < $requiredAmount) {
return 0 if $total < $requiredAmount; $self->error('required amount not met in cart');
return 0;
} }
##Must have a configured shipping id. ##Must have a configured shipping id.
return 0 if ! $self->get('shipperId'); if (! $self->get('shipperId')) {
$self->error('no shipping method set');
return 0;
}
my $shipper = eval { WebGUI::Shop::ShipDriver->new($session, $self->get('shipperId'))}; my $shipper = eval { WebGUI::Shop::ShipDriver->new($session, $self->get('shipperId'))};
if (my $e = WebGUI::Error->caught) { if (my $e = WebGUI::Error->caught) {
@ -568,7 +578,10 @@ sub readyForCheckout {
} }
##Must have a configured payment method. ##Must have a configured payment method.
return 0 if ! $self->get('gatewayId'); if (! $self->get('gatewayId')) {
$self->error('no payment gateway set');
return 0;
}
my $gateway = eval { WebGUI::Shop::PayDriver->new($session, $self->get('gatewayId'))}; my $gateway = eval { WebGUI::Shop::PayDriver->new($session, $self->get('gatewayId'))};
if (my $e = WebGUI::Error->caught) { if (my $e = WebGUI::Error->caught) {
@ -661,7 +674,7 @@ sub update {
WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref."); WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref.");
} }
my $id = id $self; my $id = id $self;
foreach my $field (qw(billingAddressId shippingAddressId posUserId shipperId creationDate)) { foreach my $field (qw(billingAddressId shippingAddressId posUserId gatewayId shipperId creationDate)) {
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field}; $properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
} }
$self->session->db->setRow("cart","cartId",$properties{$id}); $self->session->db->setRow("cart","cartId",$properties{$id});
@ -875,11 +888,16 @@ Updates the cart totals and then displays the cart again.
=cut =cut
sub www_update { sub www_update {
my $self = shift; my $self = shift;
my $session = $self->session;
$self->updateFromForm; $self->updateFromForm;
if ($self->session->form->get('checkout') && $self->readyForCheckout()) { $session->log->warn('checkout form: '. $session->form->get('checkout'));
if ($session->form->get('checkout') && $self->readyForCheckout()) {
my $gateway = WebGUI::Shop::Pay->new($session)->getPaymentGateway($self->get('gatewayId'));
return $gateway->www_getCredentials;
} }
$session->log->warn('checkout form: '. $session->form->get('checkout'));
$session->log->warn('ready for checkout: '. $self->readyForCheckout());
return $self->www_view; return $self->www_view;
} }

View file

@ -102,7 +102,7 @@ sub appendCartVariables {
my $credit = WebGUI::Shop::Credit->new($session, $cart->getPosUser->userId); my $credit = WebGUI::Shop::Credit->new($session, $cart->getPosUser->userId);
$var->{inShopCreditAvailable} = $credit->getSum; $var->{inShopCreditAvailable} = $credit->getSum;
$var->{inShopCreditDeduction} = $credit->calculateDeduction($var->{totalPrice}); $var->{inShopCreditDeduction} = $credit->calculateDeduction($var->{totalPrice});
$var->{totalPrice } = $self->formatCurrency($totalPrice + $var->{inShopCreditDeduction}); $var->{totalPrice } = $cart->formatCurrency($totalPrice + $var->{inShopCreditDeduction});
return $self; return $self;
} }