[ic] UPS Look up for each item

Desjardins, Ray interchange-users@interchange.redhat.com
Mon May 20 16:18:01 2002


I currently have the below ups-each sub-routine running against 4.6.x and
recently upgraded a server to 4.8.5.  I have installed the ups-each routine
and for some reason am unable to get it to work now.  Has anyone implemented
the ups-each in 4.8.5 using web lookup?  That would be ideal.  Is there a
new way to calculate each item with separate shipping that I've missed in
the new version?  Either with UPS or FedEx?

Thanks,

Ray Desjardins



Mike Hein's Note:

I recommend not basing things on the "s" type for shipping -- this
goes away in MV4.

Better would be a global usertag -- the one appended is an actual
operational tag and is fully tested. It is called with:

ups_each	Separate item UPS Ground	quantity	1	20
f [ups-each Ground]
ups_each	Separate item UPS Blue`	quantity	1	20	f
[ups-each 2ndDayAir]

The defaults should work with any checkout resembling the MV demo.
You can change the zip and zone with zip="[value postcode]" and
zone="[value upszone]" if necessary -- check the docs.

You can put an adder in by appending a number (or other MV tags)
to the cost field.

Thanks for all of *your* help to users on this list....

Best,

Mike Heins

UserTag ups-each Order  mode
UserTag ups-each PosNumber 1
UserTag ups-each AddAttr
UserTag ups-each Routine <<EOR
sub {
    my($mode, $opt) = @_;
    $mode = 'Ground' unless $mode;
    $opt->{'zip'}    = $::Values->{zip} unless $opt->{zip};
    $opt->{'zone'}   = 'u'              unless $opt->{zone};
    my $table        = $opt->{'table'}      || 'products';
    my $weight_field = $opt->{weight_field} || 'weight';
    my $group_field  = $opt->{group}        || undef;
 
    $opt->{zip} =~ s/\W//g;
    if($opt->{zip} !~ /^\d\d\d/) {
        $Vend::Session->{ship_message} .=
                "Can't do UPS without a zip code.\n";
        return;
    }
    my $cart = $Vend::Items;
    my @queue;
    my %queue;
    my $item;
    my ($group, $weight);

    foreach $item (@$cart) {
        $group = defined $group_field
                ? Vend::Interpolate::tag_data($table, $group_field,
$item->{code})
                : '';
        $weight = Vend::Interpolate::tag_data(
                        $table, $weight_field, $item->{code}
                        );
        unless ($weight > 0) {
            $Vend::Session->{ship_diagnostic} .=
                    "Item $item->{code} had no weight.\n";
            next;   
        }
        my (@subqueue) = ();
        my $i;
        for ($i = 1; $i <= $item->{'quantity'}; $i++) {
            push(@subqueue, $weight);
        }
        unless ($group) {
            push(@queue, @subqueue);
            next;
        }
        else {
            $queue{$group} += $weight * $item->{'quantity'};
        }
    }
    for(keys %queue) {
        push(@queue, $queue{$_});
    }
    my $cost = 0;
    for(@queue) {
        $cost += Vend::Interpolate::tag_ups(
                            $mode,
                            $opt->{zip},
                            $_,
                            $opt->{zone},
                        );
    }
    return $cost;
}
EOR
-