[interchange-cvs] interchange - heins modified lib/Vend/Interpolate.pm

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Thu Jul 3 20:19:00 EDT 2003


User:      heins
Date:      2003-07-03 23:19:37 GMT
Modified:  lib/Vend Interpolate.pm
Log:
* Fix bug in [PREFIX-discount-subtotal] where quantity was greater
  than one. We were overloading the discount_price() routine, which
  was dumb, so a new discount_subtotal() routine takes over.

Revision  Changes    Path
2.177     +27 -10    interchange/lib/Vend/Interpolate.pm


rev 2.177, prev_rev 2.176
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.176
retrieving revision 2.177
diff -u -r2.176 -r2.177
--- Interpolate.pm	3 Jul 2003 23:16:03 -0000	2.176
+++ Interpolate.pm	3 Jul 2003 23:19:36 -0000	2.177
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 # 
-# $Id: Interpolate.pm,v 2.176 2003/07/03 23:16:03 mheins Exp $
+# $Id: Interpolate.pm,v 2.177 2003/07/03 23:19:36 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -28,7 +28,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = substr(q$Revision: 2.176 $, 10);
+$VERSION = substr(q$Revision: 2.177 $, 10);
 
 @EXPORT = qw (
 
@@ -4401,11 +4401,7 @@
 		$run =~ s:$QR{modifier_name}:$1$item->{mv_ip}:g;
 		$run =~ s!$B$QR{_subtotal}!currency(item_subtotal($item),$1)!ge;
 		$run =~ s!$B$QR{_discount_subtotal}!
-						currency( discount_price(
-										$item,item_subtotal($item)
-									),
-								$1
-								)!ge;
+						currency( discount_subtotal($item), $1 )!ge;
 		$run =~ s:$B$QR{_code}:$code:g;
 		$run =~ s:$B$QR{_field}:ed($Hash_code{field}->($item, $1) || $item->{$1}):ge;
 		$run =~ s:$B$QR{_common}:ed($Hash_code{common}->($item, $1) || $item->{$1}):ge;
@@ -5030,6 +5026,22 @@
 	return ($price * $q) - discount_price($code,$price,$q) * $q;
 }
 
+sub discount_subtotal {
+	my ($item, $price) = @_;
+
+	unless (ref $item) {
+		::logError("Bad call to disount price, item is not reference: %s", $item);
+		return 0;
+	}
+
+	my $quantity = $item->{quantity} || 1;
+
+	$price ||= item_price($item);
+	my $new_price = discount_price($item, $price);
+	
+	return $new_price * $quantity;
+}
+
 sub discount_price {
 	my ($item, $price, $quantity) = @_;
 	my $extra;
@@ -5054,17 +5066,22 @@
 	$Vend::Interpolate::q = $quantity || 1;
 	$Vend::Interpolate::s = $price;
 
+	my $subtotal = $price * $quantity;
+
+#::logDebug("quantity=$q code=$item->{code} price=$s");
+
 	my ($discount, $return);
 
 	for($code, 'ALL_ITEMS') {
 		next unless $discount = $Vend::Session->{discount}->{$_};
-		$Vend::Interpolate::s = $return = $price;
+		$Vend::Interpolate::s = $return ||= $subtotal;
         $return = $ready_safe->reval($discount);
 		if($@) {
-			$return = $price;
+			::logError("Bad discount code for %s: %s", $discount);
+			$return = $subtotal;
 			next;
 		}
-        $price = $return;
+        $price = $return / $q;
     }
 
 	if($extra) {







More information about the interchange-cvs mailing list