Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: [mv] UPS lookup on each item



******    message to minivend-users from Mike Heins <mike@minivend.com>     ******

Quoting kyle@invisio.com (kyle@invisio.com):
> 
> Hey all,
> 
> I need to loop over every item ordered and do a ups
> lookup for each one to get a total shipping cost.
> 
> I know this has come up before and I have had a little
> time to go over the archives, faqs and docs. I have
> just slapped this together and have not tested it yet.
> I would appreciate any feedback before I build a new
> site to test this out (the current site I want to use it
> in is too busy to experiment on).
> 
> I believe my perl is sound, but am still a little unclear on
> passing the info to the sub.
> 
> Any comments are welcome.

Dear Kyle,

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
-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: