[ic] [repost] per item shipping cost schedule

Guido Sohne caught_one@yahoo.com
Wed, 14 Mar 2001 06:47:19 -0800 (PST)

I posted earlier on a shipping problem I was having and was basically
to either

1) Iterate over the cart items in Perl and watch the sun rising ... :-)
2) Or use an add-on product called shipd ...

I opted for 'roll-your-own' :-) and am being rolled over by a steam

I'm trying to calculate shipping for a set of items in a shopping cart.
Each item could potentially have its own shipping method. 

This is intended to allow for widely varying types of goods. For
shipping iron rods is different from shipping jewelry, yet both can be
at the same time. 

As far as I am aware, Interchange calculates shipping based on the
weight/quantity of the items in a cart by applying a data table to this

aggregate quantity. We're shipping based on weight.

I've identified a strategy which seems workable except I do not know
the steps needed to achieve it.

1) Add a field to products database called ship. This field is the
of shipping (ie. the data table to be applied to this product)

2) Define tags that are used with [item-list] to be used as below:-

	([]'s shifted around for clarity)

				shipmode="[item-field ship]" 
				weight="[item-field weight]" 
	[calculate-shipping-to "New Jersey"]

3) These UserTags go into the catalog.cfg for the store.

This UserTag resets all shipping values to zero and should
be used each time one is going to do something related to 
calculating shipping.

UserTag reset-shipping Routine <<EOR
sub { $Vend::Session->{SendToAfrica} = undef; return ""; }

This UserTag sorts the products into bins according to shipping class
and calculates the aggregate weight for each bin.

UserTag add-to-shipping Order shipmode weight quantity
UserTag add-to-shipping Routine <<EOR
sub {
        my ($shipmode,$weight,$quantity) = @_;
        $Vend::Session->{SendToAfrica}{$shipmode} += $weight *
        return "";

This UserTag is supposed to apply a data table used in regular
shipping to each bin. If the bin are called '1', '2' and '3', and we
shipping to 'USA', then this UserTag should apply data table USA1 to
aggregate weight of items in bin '1'; apply data table USA2 to the 
aggregate weight of items in bin '2' etc.

I'm setting $::Values->{mv_shipmode} to the concatenation of the
destination and the shipping class. That would make data table 'USA1'
to destination 'USA' and shipping class '1'.

Now I want to call an Interchange function, telling it to calculate
for the items in bin '1' for destination 'USA'. From looking at the
code for sub shipping in Interpolate.pm, I guess the next step is to
a cart for each bin, put all items in the bin into the cart.

I'm having problems trying to work out how to do the
UserTag properly. This code doesn't work ... and I need help with it
as this is my first descent into the Perl side of developing with

Any ideas ? This would be much easier if Interchange had API level 
documentation. If something like that exists, please let me know !!!!

I'm tearing my hair out trying to grok this Perl :) it's too 
elite for me, maybe ... Maybe ?!?

UserTag calculate-shipping-to Order region
UserTag calculate-shipping-to Routine <<EOR
sub {
        my $region = shift;
        my $method = undef;
        my $cat = undef;
        my $total = undef;

        foreach $cat (keys %{$Vend::Session->{SendToAfrica}}) {
                # TODO: from region get shipping data table
                # this is done by setting mv_shipmode
                $::Values->{mv_shipmode} = $region . $cat;

                print $Vend::Interpolate::shipping($region . $cat);
                # TODO: use mv_shipmode on category weight
                $total += $Vend::Session->{SendToAfrica}{$cat};
        return "$total";

Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.