[interchange-cvs] interchange - danb modified lib/Vend/Ship.pm

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Fri Apr 11 08:44:20 UTC 2008


User:      danb
Date:      2008-04-11 08:44:20 GMT
Modified:  lib/Vend Ship.pm
Log:
Allow the shipping.asc weight to be modified with weight_callout SpecialSub.

This SpecialSub modifies the 'weight' criteria in shipping.asc. It does not
affect other calculations, such as the [weight] usertag. In the following
example, it is used to exclude items that are part of a free shipping
promotion from the calculation of the shipping cost. That is, if two out of
three items qualify for free shipping, then only the weight of the third
item would be used for weight-based shipping methods.

# Override the normal shipping.asc weight calculations to take the free
# shipping promotion into consideration. Uses custom is_free_shipping and
# weight Item Modifiers. Only non-free-shipping items have their weight
# included.
Sub custom_weight <<EOF
sub {
    my ($normal_weight) = @_;

    my $new_weight = 0;
    for my $item (@$Items) {
        $new_weight += $item->{weight} * $item->{quantity}
            unless $item->{is_free_shipping};
    }
    return $new_weight;
}
EOF
SpecialSub weight_callout custom_weight

Revision  Changes    Path
2.28                 interchange/lib/Vend/Ship.pm


rev 2.28, prev_rev 2.27
Index: Ship.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Ship.pm,v
retrieving revision 2.27
retrieving revision 2.28
diff -u -r2.27 -r2.28
--- Ship.pm	11 Apr 2008 07:47:16 -0000	2.27
+++ Ship.pm	11 Apr 2008 08:44:20 -0000	2.28
@@ -1,6 +1,6 @@
 # Vend::Ship - Interchange shipping code
 # 
-# $Id: Ship.pm,v 2.27 2008-04-11 07:47:16 danb Exp $
+# $Id: Ship.pm,v 2.28 2008-04-11 08:44:20 danb Exp $
 #
 # Copyright (C) 2002-2008 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -714,6 +714,18 @@
 	    }
 	}
 
+	if ($field eq 'weight') {
+		if (my $callout_name = $Vend::Cfg->{SpecialSub}{weight_callout}) {
+#::logDebug("Execute weight callout '$callout_name(...)'");
+			my $weight_callout_sub = $Vend::Cfg->{Sub}{$callout_name} 
+				|| $Global::GlobalSub->{$callout_name};
+			eval {
+				$total = $weight_callout_sub->($total) || 0;
+			};
+			::logError("Weight callout '$callout_name' died: $@") if $@;
+		}
+	}
+	
 	# We will LAST this loop and go to SHIPFORMAT if a match is found
 	SHIPIT: 
 	foreach $row (@lines) {







More information about the interchange-cvs mailing list