User: pajamian
Date: 2009-05-20 22:13:32 GMT
Modified: . WHATSNEW-5.7
Modified: lib/Vend Cart.pm
Log:
MaxQuantity fixes:
* A null or non-numerical entry in the table(s) for the maxquantity field should
result in no maximum quantity enforcement for that product.
* Remove redundant code for fetching the quantity from the table(s).
* Fix instance where two DB hits are used to fetch one value.
* Get rid of goto.
* Basically a rewrite of the correspondign block of code.
Revision Changes Path
2.44 interchange/WHATSNEW-5.7
rev 2.44, prev_rev 2.43
Index: WHATSNEW-5.7
===================================================================
RCS file: /var/cvs/interchange/WHATSNEW-5.7,v
retrieving revision 2.43
retrieving revision 2.44
diff -u -r2.43 -r2.44
--- WHATSNEW-5.7 20 May 2009 09:39:19 -0000 2.43
+++ WHATSNEW-5.7 20 May 2009 22:13:32 -0000 2.44
@@ -111,6 +111,10 @@
* _set_acl() in UserDB.pm now uses adjust_time() instead of time_to_seconds().
+* Fix MaxQuantityField to allow a null, blank, or non-numerical entry in the
+ field to represent that no maximum quantity should be enforced for that
+ product.
+
Payment
-------
2.26 interchange/lib/Vend/Cart.pm
rev 2.26, prev_rev 2.25
Index: Cart.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Cart.pm,v
retrieving revision 2.25
retrieving revision 2.26
diff -u -r2.25 -r2.26
--- Cart.pm 16 Apr 2009 14:51:41 -0000 2.25
+++ Cart.pm 20 May 2009 22:13:32 -0000 2.26
@@ -1,8 +1,8 @@
# Vend::Cart - Interchange shopping cart management routines
#
-# $Id: Cart.pm,v 2.25 2009-04-16 14:51:41 mheins Exp $
+# $Id: Cart.pm,v 2.26 2009-05-20 22:13:32 pajamian Exp $
#
-# Copyright (C) 2002-2008 Interchange Development Group
+# Copyright (C) 2002-2009 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
#
# This program was originally based on Vend 0.2 and 0.3
@@ -25,7 +25,7 @@
package Vend::Cart;
-$VERSION = substr(q$Revision: 2.25 $, 10);
+$VERSION = substr(q$Revision: 2.26 $, 10);
use strict;
@@ -247,55 +247,65 @@
}
}
- if($Vend::Cfg->{MaxQuantityField}) {
- $item->{mv_max_quantity} = 0;
-
- foreach my $fieldspec (split('[,\s]+', $Vend::Cfg->{MaxQuantityField})) {
- next unless $fieldspec;
-
- my ($tab, $col) = split /:+/, $fieldspec;
- if(! length $col) {
- $col = $tab;
- $tab = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
- }
- if ( $tab =~ s/^=// ) {
- $item->{mv_max_quantity} = $quantity_cache{"$tab.$col.$item->{code}"} = ::tag_data($tab, $col, $item->{code});
- goto DONE_QUANTITY_ADJUST;
- }
- elsif ( $tab =~ s/^\?// ) {
- if ( $item->{mv_max_quantity} ) {
- $item->{mv_max_quantity} = $quantity_cache{"$tab.$col.$item->{code}"} = ::tag_data($tab, $col, $item->{code}) if
- ::tag_data($tab, $col, $item->{code});
- goto DONE_QUANTITY_ADJUST;
- }
- }
- else {
- $item->{mv_max_quantity} += $quantity_cache{"$tab.$col.$item->{code}"} || ($quantity_cache{"$tab.$col.$item->{code}"} = ::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;
-
- DONE_QUANTITY_ADJUST:
-
- if(
- length $item->{mv_max_quantity}
- and
- $item->{quantity} > $item->{mv_max_quantity}
- )
- {
- $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,
- $old_item,
- $event_cartname
- ) if $quantity_raise_event;
- }
- }
+ MAX_QUANTITY: {
+ last MAX_QUANTITY unless $Vend::Cfg->{MaxQuantityField};
+ my $mv_max = \$item->{mv_max_quantity};
+ undef $$mv_max;
+
+ QUANTITY_ADJUST: {
+ QUANTITY_FIELD: foreach my $fieldspec (split('[,\s]+', $Vend::Cfg->{MaxQuantityField})) {
+ next QUANTITY_FIELD unless $fieldspec;
+
+ my ($tab, $col) = split /:+/, $fieldspec;
+ if(! length $col) {
+ $col = $tab;
+ $tab = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
+ }
+
+ my ($prefix) = $tab =~ s/^([=\?])//;
+ $prefix ||= '';
+
+ my $max = \$quantity_cache{"$tab.$col.$item->{code}"};
+ $$max ||= ::tag_data($tab, $col, $item->{code});
+ undef $$max unless $$max =~ /\d/;
+
+ if ($prefix eq '=') {
+ $$mv_max = $$max;
+ last QUANTITY_ADJUST if defined $$max;
+ last MAX_QUANTITY;
+ }
+
+ elsif ($prefix = '?') {
+ next QUANTITY_FIELD if !defined $$max || $$max <= 0;
+ $$mv_max = $$max;
+ last QUANTITY_ADJUST;
+ }
+
+ elsif (defined $$max) {
+ $$mv_max ||= 0;
+ $$mv_max += $$max;
+ }
+ } # QUANTITY_FIELD
+
+ last MAX_QUANTITY unless defined $$mv_max;
+
+ $$mv_max -= $total_quantity{$item->{code}};
+ $$mv_max = 0 if $$mv_max < 0;
+ } # QUANTITY_ADJUST
+
+ if($item->{quantity} > $$mv_max) {
+ $old_item = { %$item } if $quantity_raise_event;
+ $item->{quantity} = $$mv_max;
+ $item->{mv_max_over} = 1;
+ delete $item->{mv_min_under};
+ trigger_update(
+ $s,
+ $item,
+ $old_item,
+ $event_cartname
+ ) if $quantity_raise_event;
+ }
+ } # MAX_QUANTITY
for(@{$Vend::Cfg->{AutoModifier}}) {
next unless /^!/;
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.