[ic] Shipped Directly To Jail, Do Not Pass Go, Guru

cfm@maine.com cfm@maine.com
Wed, 14 Mar 2001 13:50:36 -0500


On Tue, Mar 13, 2001 at 09:05:19AM -0800, Guido Sohne wrote:
> I posted earlier on a shipping problem I was having and was basically
> told 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
> roller.
> 
> 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
> example, shipping iron rods is different from shipping jewelry, yet
> both can be bought at the same time. 
> 
> As far as I am aware, Interchange calculates shipping based on the
> aggregate 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
> all
> the steps needed to achieve it.
> 

This is not at all a trivial project.  What I'll lay out
here is going to have lots of holes.  There are also **OTHER**
ways to solve it.  YMMV.

We use a tag in shipping.asc specifically so we can build these
shipping routines outside of precompiled code.  We only do this
for exceptional cases; I think only a couple of our catalogs use
it.  It does allow you to do **anything**.

included        Shipping is by FedEx    quantity        1       9999    f [merchants_shipping]

[merchants_shipping]

UserTag merchants_shipping Order base
UserTag merchants_shipping Routine <<EOF
sub {
        require MV::Merchants;
        require MV::Shipping;
        my($M,$adj,%opt);

        $opt{config}=$Vend::Cfg->{CatalogName}; # opt hack
        $adj=0;
        $M=&MV::Merchants::load_merchant(\%opt,$Vend::Session->{values}); # stubbed
        $opt{shipping_rules}=$M->{$opt{config}}{shipping_rules} if($M);
        return unless ($opt{shipping_rules});
   	$adj+=&MV::Shipping::base_item_shipping(\%opt,$opt{shipping_rules});
        $adj+=&MV::Shipping::extra_item_shipping(\%opt,$opt{shipping_rules});
        $adj+=&MV::Shipping::gift_certificate_shipping(\%opt,$opt{shipping_rules});
        return $adj;
}
EOF

Any particular shipping routine checks to see if it
is enabled, then if it is, it iterates the cart,
touches it up as required, and then returns price
adjustment.




CommonAdjust    &{Vend::myModule::supa_pricing();}

That routine iterates the cart.
  for $item (@items) {


> 1) Add a field to products database called ship. This field is the
> class
> 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)
> 
> 	[reset-shipping]
> 	[item-list]
> 		[add-to-shipping 
> 				shipmode="[item-field ship]" 
> 				weight="[item-field weight]" 
> 				quantity="[item-quantity]"
> 		]
> 	[/item-list]
> 	[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 ""; }
> EOR
> 
> 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 *
> $quantity;
>         return "";
> }
> EOR
> 
> This UserTag is supposed to apply a data table used in regular
> Interchange shipping to each bin. If the bin are called '1', '2' and
> '3', and we are shipping to 'USA', then this UserTag should apply data
> table USA1 to the 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
> shipping destination and the shipping class. That would make data table
> 'USA1' apply to destination 'USA' and shipping class '1'.
> 
> Now I want to call an Interchange function, telling it to calculate
> shipping for the items in bin '1' for destination 'USA'. From looking
> at the source code for sub shipping in Interpolate.pm, I guess the next
> step is to create 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
> calculate-shipping-to UserTag properly. This code doesn't work ... and
> I need help with it especially as this is my first descent into the
> Perl side of developing with Interchange.
> 
> 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";
> }
> EOR
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - Buy the things you want at great prices.
> http://auctions.yahoo.com/
> 
> _______________________________________________
> Interchange-users mailing list
> Interchange-users@lists.akopia.com
> http://lists.akopia.com/mailman/listinfo/interchange-users

-- 

Christopher F. Miller, Publisher                             cfm@maine.com
MaineStreet Communications, Inc         208 Portland Road, Gray, ME  04039
1.207.657.5078                                       http://www.maine.com/
Content management, electronic commerce, internet integration, Debian linux