Akopia Akopia Services

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

Re: [mv] Can I use Perl to change shipping-desc??



******    message to minivend-users from "kyle@invisio.com" <kyle@invisio.com>     ******

Scott,

It seems to me that an easier way to do this is to set up
a user tag to be used in shipping.asc to determine which
shipping methods can be used:

Modified code from other examples from Mike is used:

(note you will need tabs in the next few lines!)

upsg UPS Ground [compute-weight] 0 150 f [ups-each Ground]
upsg UPS Ground [compute-weight] 150.01 99999 e Too big for UPS shipping!

ltl Via Truck weight 0 150 e You should use UPS ground
ltl Via Truck weight 150.01 9999 f [your own tag here or simple math]

UserTag compute_weight Order cart 
UserTag compute_weight Routine <<EOR 
sub { 
my ($name) = @_; 
my $cart; 
if($name) { 
$cart = $Vend::Session->{carts}{$name}; 
} 
else { 
$cart = $Vend::Items; 
} 
return 0 unless $cart; 
my $weight; 
foreach my $item (@$cart) { 
my $item_weight = 0; 
$item_weight = Vend::Interpolate::tag_data( 
'products', 
'weight', 
$item->{code}, 
);
if ($weight < $item_weight) {
$weight = $item_weight;
}
} 
return $weight; 
} 
EOR


Again not tested, but now the largest weight will be returned to
see if it falls between 0 and 150. So if no item is larger than 150
it will use the original ups-each UserTag to compute the cost.

If any item is larger than 150, then you can set up another shipping
method (ltl) in shipping.asc to calculate cost and at the same time
take care of the display of shipping method.

Hope this helps,
Kyle



At 10:33 AM 2/1/00 -0500, you wrote: 

>
> Some help for a perl novice please?? 
>
> I'm using Mike's UPS User-Tag (thank you Mike, a thousand times over) 
> to calculate shipping costs per item. 
>
> I made a little mod in the code that, if the item weight is greater 
> that 150lbs, sets the shipping cost to $85.00 per such item (we ship 
> heavy items via truck).  This works very well, to a point. 
> Of course, the cost is correct, but the shipping-desc still returns 
> UPS x.  
>
> Is there a way to set the shipping-desc in the perl code so 
> that it matches the actual shipping method?? 
>
> Here is what I changed in the user tag: 
> This might be a conveluted way of doing this, 
> but like I said, I'm just learning Perl. 
> ---------- 
> my $cost = 0; 
> # a cost variable for ltl shipping 
> my $ltl_cost = 0; 
>         for(@queue) { 
> # if the weight is ups shipable, get the cost from the table 
>               if ($_ < 150) { 
>                       $cost += Vend::Interpolate::tag_ups(
>
>                             $mode, 
>                                     $opt->{zip}, 
>                               $_, 
>                                 $opt->{zone}, 
>                                 ); 
> # otherwise, add a fixed cost the ltl shipping cost 
>               }else{ 
>                   $ltl_cost += 85; 
>               }   
>         }     
> # if ltl shipping cost is more than zero, the whole order goes via truck 
> # set the return cost to ltl shipping cost 
>         if ($ltl_cost > 0) { 
>               $cost = $ltl_cost; 
>         }     
> return $cost; 
> --------- 
> TIA 
> Scott 



-
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: