[ic] Help with custom shipping

Kyle Cook interchange-users@interchange.redhat.com
Tue Oct 23 19:19:00 2001


At 03:15 PM 10/23/01, you wrote:
>Help!  I have been trying to write a custom shipping formula, wiht no 
>luck.  Here's the info:
>
>products database has an additional field called ship_charge, set to Yes/No
>
>Shipping should be charged at a $3 flat rate per item for thos marked yes, 
>no shipping charge for those marked no.
>
>How can I look up the ship_charge field from the shipping formula?  I'm 
>stuck, and my boss is getting impatient.
>
>################## In after.cfg:
>
>UserTag bgcalc Order cart
>UserTag bgcalc Routine <<EOR
>sub{
>  my ($name) = @_;
>  my ($cart, $item, $yn);
>  if($name) {
>    $cart = $Vend::Session->{carts}{$name};
>  }
>  else {
>    $cart = $Vend::Items;
>  }
>  my $charge = 0;
>  foreach $item (0 .. $#$cart) {
>    $yn = $cart->[$item]{'ship_charge'};
>    if($yn =~ /Yes/i) {
>      $charge++;
>    }
>  }
>  return $charge;
>}
>EOR
>
>################# In shipping.asc:
>
>bgship  Standard        [bgship]        0       0       0
>{'Price Divide' => "1",}
>bgship  Standard        [bgship]        0       999999  f @@TOTAL@@ * [var 
>SHIP_FLAT_DOM_RATE]         {'PriceDivide' => "1",}
>
>#################
>
>Obviously I'm off the mark somewhere, but an afternoon of head-pounding 
>hasn't shown me the light yet...
>
>Thanks in advance,
>
>--Moe Pitman
>Lone Star Internet

2 things:

1. your usertag is defined as bgcalc, but in shipping.asc you refer to bgship.

2. Maybe this will help, not tested but should show how to get the field 
data you need:

UserTag bgcalc Order cart
UserTag bgcalc Routine <<EOR
sub {
my ($name) = @_;
my $cart = ($name) ?
         $Vend::Session->{carts}{$name} : $Vend::Items;
return 0 unless $cart; # and or log error...
my $charge = 0;
foreach my $item (@$cart) {
         $yn = Vend::Interpolate::tag_data(
                         'products',
                         "ship_charge",
                         $item->{code},);
         $charge++ if ($yn =~ /^y/i);
}
return $charge;
}

Good Luck,
Kyle Cook