
db at endpoint
Dec 10, 2008, 1:37 PM
Post #2 of 3
(567 views)
Permalink
|
|
Re: add fixed amount to shipping based on cart's total weight
[In reply to]
|
|
On Wednesday 10 December 2008 1:01:20 pm DB wrote: > I need a way to add an additional, fixed amount to an order's shipping if > the total weight of items in the cart exceeds a certain value. I recently suggested the shipping_callout method to seomeone else. This feature allows you to build a GlobalSub that takes the existing shipping amount, checks the cart for applicable items, then adds the fee. Whatever customizations you need will automatically apply to every shipping method. I prefer it over [assign] because it takes effect everywhere automatically without adding any code to the checkout pages. For example (untested): # A perly true value in 'products.oversized' field adds UPS fee. AutoModifier oversized Variable OVERWEIGHT_LIMIT 25 Variable OVERWEIGHT_FEE 10.00 Sub custom_shipping <<EOS sub { my ($final, $mode, $opt, $o) = @_; my $total_weight = $Tag->weight({noformat=>1}) || 0; $final += $Variable->{OVERWEIGHT_FEE} if $total_weight > $Variable->{OVERWEIGHT_LIMIT}; return $final; } EOS SpecialSub shipping_callout custom_shipping The feature was added in 5.6.0, but the patch to older versions is pretty simple: http://www.icdevgroup.org/cgi-bin/cvsweb/interchange/lib/Vend/Ship.pm.diff?r1=text&tr1=2.26&r2=text&tr2=2.27 -- Daniel "the other DB" Browning End Point Corporation http://www.endpoint.com/ --- interchange/lib/Vend/Ship.pm 2007/08/09 13:40:54 2.26 +++ interchange/lib/Vend/Ship.pm 2008/04/11 07:47:16 2.27 @@ -1,8 +1,8 @@ # Vend::Ship - Interchange shipping code # -# $Id: Ship.pm,v 2.26 2007/08/09 13:40:54 pajamian Exp $ +# $Id: Ship.pm,v 2.27 2008/04/11 07:47:16 danb Exp $ # -# Copyright (C) 2002-2007 Interchange Development Group +# Copyright (C) 2002-2008 Interchange Development Group # Copyright (C) 1996-2002 Red Hat, Inc. # # This program was originally based on Vend 0.2 and 0.3 @@ -909,6 +909,16 @@ sub shipping { } undef $opt->{default}; } + if (my $callout_name = $Vend::Cfg->{SpecialSub} {shipping_callout}) { +#::logDebug("Execute shipping callout '$callout_name(...)'"); + my $sub = $Vend::Cfg->{Sub}{$callout_name} + || $Global::GlobalSub->{$callout_name}; + eval { + my $callout_result = $sub->($final, $mode, $opt, $o); + $final = $callout_result if defined $callout_result; + }; + ::logError("Shipping callout '$callout_name' died: $@") if $@; + } return $final unless $opt->{label}; my $number; if($o->{free} and $final == 0) { _______________________________________________ interchange-users mailing list interchange-users [at] icdevgroup http://www.icdevgroup.org/mailman/listinfo/interchange-users
|