check for mixed recurring and non-recurring items in the cart

This commit is contained in:
JT Smith 2008-05-21 20:14:46 +00:00
parent a6bd5d0b99
commit e71946fb94
3 changed files with 39 additions and 3 deletions

View file

@ -218,13 +218,13 @@ sub getOptions {
=head2 getMaxAllowedInCart ( ) =head2 getMaxAllowedInCart ( )
Returns getQuantityAvailable(). Should be overriden by subclasses that have a specific value. Subclasses that are unique should return 1. Subclasses that have an inventory count should return the amount in inventory. Returns getQuantityAvailable() or 1 if isRecurring() return 1. Should be overriden by subclasses that have a specific value. Subclasses that are unique should return 1. Subclasses that have an inventory count should return the amount in inventory.
=cut =cut
sub getMaxAllowedInCart { sub getMaxAllowedInCart {
my $self = shift; my $self = shift;
return $self->getQuantityAvailable; return $self->isRecurring || $self->getQuantityAvailable;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -398,6 +398,30 @@ sub getShippingAddress {
return $self->getAddressBook->getAddress($self->get("shippingAddressId")); return $self->getAddressBook->getAddress($self->get("shippingAddressId"));
} }
#-------------------------------------------------------------------
=head2 hasMixedItems ()
Returns 1 if there are too many recurring items, or there are mixed recurring and non-recurring items in the cart.
=cut
sub hasMixedItems {
my $self = shift;
my $recurring = 0;
my $nonrecurring = 0;
foreach my $item (@{$self->getItems}) {
if ($item->getSku->isRecurring) {
$recurring += $item->get('quantity');
}
else {
$nonrecurring += $item->get('quantity');
}
return 1 if ($recurring > 0 && $nonrecurring > 0);
return 1 if ($recurring > 1);
}
return 0;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -472,6 +496,9 @@ sub readyForCheckout {
# Check if the cart has items # Check if the cart has items
return 0 unless scalar @{ $self->getItems }; return 0 unless scalar @{ $self->getItems };
# fail if there are multiple recurring items or if
return 0 if ($self->hasMixedItems);
# All checks passed so return true # All checks passed so return true
return 1; return 1;
} }
@ -551,7 +578,10 @@ sub updateFromForm {
} }
} }
} }
if ($self->hasMixedItems) {
my $i18n = WebGUI::International->new($self->session, "Shop");
$error{id $self} = $i18n->get('mixed items warning');
}
my $cartProperties = {}; my $cartProperties = {};
$cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' ); $cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' );
$self->update( $cartProperties ); $self->update( $cartProperties );

View file

@ -3,6 +3,12 @@ package WebGUI::i18n::English::Shop;
use strict; use strict;
our $I18N = { our $I18N = {
'mixed items warning' => {
message => q|You are not able to check out with both recurring and non-recurring items in your cart. You may have either one recurring item, or as many non-recurring items as you want in your cart at checkout time. If you need to purchase both, then please purchase them under separate transactions.|,
lastUpdated => 0,
context => q|a warning message displayed in the cart|,
},
'print' => { 'print' => {
message => q|Print|, message => q|Print|,
lastUpdated => 0, lastUpdated => 0,