check for mixed recurring and non-recurring items in the cart
This commit is contained in:
parent
a6bd5d0b99
commit
e71946fb94
3 changed files with 39 additions and 3 deletions
|
|
@ -218,13 +218,13 @@ sub getOptions {
|
|||
|
||||
=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
|
||||
|
||||
sub getMaxAllowedInCart {
|
||||
my $self = shift;
|
||||
return $self->getQuantityAvailable;
|
||||
return $self->isRecurring || $self->getQuantityAvailable;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -398,6 +398,30 @@ sub getShippingAddress {
|
|||
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;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -471,6 +495,9 @@ sub readyForCheckout {
|
|||
|
||||
# Check if the cart has items
|
||||
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
|
||||
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 = {};
|
||||
$cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' );
|
||||
$self->update( $cartProperties );
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@ package WebGUI::i18n::English::Shop;
|
|||
use strict;
|
||||
|
||||
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' => {
|
||||
message => q|Print|,
|
||||
lastUpdated => 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue