[interchange-cvs] interchange - kwalsh modified lib/Vend/Cart.pm

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Fri Feb 8 04:47:10 EST 2008


User:      kwalsh
Date:      2008-02-08 09:47:09 GMT
Modified:  lib/Vend Cart.pm
Log:
    * The maximum order quantity code wasn't taking existing line
      quantities into account:  If an item had a maximum order quantity of
      5 and the user tried to add 10 to the cart then it would correctly
      be knocked down to 5.  Unfortunately, the user could add a second
      cart item row (if SeparateItems was in use) and get another 5.

    * Same problem with minumum order quantities:  If the minimum was 5 and
      the user added 4 then the quantity would get bumped to 5.  If the
      user added another cart item row then they would have to order
      another 5 on that row, even though they had met the minimum order
      requirement.  The original line could be bumped to 6, but 5+1 was
      unacceptable.

    * Both of the above problems are corrected with this patch.

Revision  Changes    Path
2.20      +15 -3     interchange/lib/Vend/Cart.pm


rev 2.20, prev_rev 2.19
Index: Cart.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Cart.pm,v
retrieving revision 2.19
retrieving revision 2.20
diff -u -r2.19 -r2.20
--- Cart.pm	14 Sep 2007 16:36:56 -0000	2.19
+++ Cart.pm	8 Feb 2008 09:47:09 -0000	2.20
@@ -1,6 +1,6 @@
 # Vend::Cart - Interchange shopping cart management routines
 #
-# $Id: Cart.pm,v 2.19 2007/09/14 16:36:56 kwalsh Exp $
+# $Id: Cart.pm,v 2.20 2008/02/08 09:47:09 kwalsh Exp $
 #
 # Copyright (C) 2002-2007 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -25,7 +25,7 @@
 
 package Vend::Cart;
 
-$VERSION = substr(q$Revision: 2.19 $, 10);
+$VERSION = substr(q$Revision: 2.20 $, 10);
 
 use strict;
 
@@ -174,6 +174,10 @@
 
 # If the user has put in "0" for any quantity, delete that item
 # from the order list.
+#
+# Also adjust the cart to take minimum and maximum order quantities
+# into account.
+#
 sub toss_cart {
 	my($s, $cartname) = @_;
 	my $i;
@@ -185,7 +189,10 @@
 	$quantity_raise_event = $raise_event && $quantity_raise_event;
 	my $event_cartname = $cartname || $Vend::CurrentCart;
 	my $old_item;
+
 	DELETE: for (;;) {
+		my %total_quantity = ();
+
 		foreach $i (0 .. $#$s) {
 			my $item = $s->[$i];
 			if ($sub = $Vend::Cfg->{ItemAction}{$s->[$i]{code}}) {
@@ -224,7 +231,7 @@
 				if(
 					length $item->{mv_min_quantity}
 					and 
-					$item->{quantity} < $item->{mv_min_quantity}
+					$item->{quantity} + $total_quantity{$item->{code}} < $item->{mv_min_quantity}
 					)
 				{
 					$old_item = { %$item } if $quantity_raise_event;
@@ -252,6 +259,8 @@
 					}
 					$item->{mv_max_quantity} += ::tag_data($tab, $col, $item->{code});
 				}
+				$item->{mv_max_quantity} -= $total_quantity{$item->{code}};
+				$item->{mv_max_quantity} = 0 if $item->{mv_max_quantity} < 0;
 
 				if(
 					length $item->{mv_max_quantity}
@@ -262,6 +271,7 @@
 					$old_item = { %$item } if $quantity_raise_event;
 					$item->{quantity} = $item->{mv_max_quantity};
 					$item->{mv_max_over} = 1;
+					delete $item->{mv_min_under};
 					trigger_update(
 							$s,
 							$item,
@@ -270,6 +280,8 @@
 						) if $quantity_raise_event;
 				}
 			}
+
+			$total_quantity{$item->{code}} += $item->{quantity};
 
 			next unless $::Limit->{cart_quantity_per_line}
 				and $item->{quantity} > $::Limit->{cart_quantity_per_line};








More information about the interchange-cvs mailing list