[interchange-cvs] interchange - kwalsh modified lib/Vend/Interpolate.pm
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Wed May 29 01:02:01 2002
User: kwalsh
Date: 2002-05-29 05:01:05 GMT
Modified: lib/Vend Interpolate.pm
Log:
* Handle shipping calculations by weight, price or other attributes
for "on the fly" items, or for a mix of database-driven and onfly
items.
To do this, I have introduced a new MV_SHIP_MODIFIERS variable
to specify which item attributes should be considered for use by
the shipping routine. The variable can be set as follows:
Variable MV_SHIP_MODIFIERS weight
or:
Variable MV_SHIP_MODIFIERS weight|price
Any reasonable pipe-separated list of item attributes will do.
The variable should not contain attributes such as 'quantity'
for obvious reasons.
Revision Changes Path
2.65 +19 -8 interchange/lib/Vend/Interpolate.pm
rev 2.65, prev_rev 2.64
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.64
retrieving revision 2.65
diff -u -r2.64 -r2.65
--- Interpolate.pm 17 May 2002 03:15:19 -0000 2.64
+++ Interpolate.pm 29 May 2002 05:01:05 -0000 2.65
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.64 2002/05/17 03:15:19 jon Exp $
+# $Id: Interpolate.pm,v 2.65 2002/05/29 05:01:05 kwalsh Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.64 $, 10);
+$VERSION = substr(q$Revision: 2.65 $, 10);
@EXPORT = qw (
@@ -5685,15 +5685,26 @@
}
else {
#::logDebug("standard field selection");
- unless (column_exists $field) {
+ my $use_modifier;
+ if (defined $::Variable->{MV_SHIP_MODIFIERS} && $field =~ /^($::Variable->{MV_SHIP_MODIFIERS})$/){
+ $use_modifier = 1;
+ }
+ my $col_checked;
+ foreach my $item (@$Vend::Items){
+ my $value;
+ if ($use_modifier && defined $item->{$field}){
+ $value = $item->{$field};
+ }else{
+ unless ($col_checked++ || column_exists $field){
logError("Custom shipping field '$field' doesn't exist. Returning 0");
+ $total = 0;
goto SHIPFORMAT;
+ }
+ my $base = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
+ $value = tag_data($base, $field, $item->{code});
}
- foreach my $item (@$Vend::Items) {
- my $base = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
- my $value = tag_data($base, $field, $item->{code});
- $total += $value * $item->{quantity};
- }
+ $total += ($value * $item->{quantity});
+ }
}
# We will LAST this loop and go to SHIPFORMAT if a match is found