[ic] My first usertag... see any glaring errors?

DB interchange-users@icdevgroup.org
Thu Feb 13 22:31:01 2003


Here's my first usertag... I didn't write it from scratch but modified 
one I found. It seems to work but sometimes I get error log entries like:

  Safe: syntax error at (eval 749) line 1, near ">"
  >
  > >0
  >

I thought I had this solved before but spoke too soon. The tag totals 
(price*qty) of all items that have an sku starting with "AT-" and writes 
this total to a scratch variable used on the cart page (the error *may* 
occur when the total is zero but I need more testing to confirm that). 
If any ic/perl gurus can glance over the tag I'd very much like to have 
feedback.

Here's the tag:

#---- begin tag------------
UserTag atv Routine <<EOR
sub {
         my $atvtot = 0;
foreach my $atvindex (0 .. $#$Vend::Items) {
         my $atvcode = $Vend::Items->[$atvindex]{code};
         my $atvbase = $Vend::Items->[$atvindex]{mv_ib};
         my $atvqty = $Vend::Items->[$atvindex]{quantity};
         my $atvprice = $Tag->price({code => $atvcode , quantity => 
$atvqty , noformat => 1});
         my $isatv = 1           if $atvcode =~ m/^AT-/;
         $atvprice = 0         if !$isatv;
         $atvtot = $atvtot + ($atvprice * $atvqty);

$Scratch->{'atvtotal'} = $atvtot;
}}
EOR
#----  end tag ------------

I use the scratch variable in following code on the cart page and this 
is what I think causes the error. But it doesn't happen all the time and 
the calculations are made correctly.

[if type=explicit compare="[calc][scratch atvtotal]>0 [/calc]"]
[and type=explicit compare="[calc][scratch atvtotal]<25 [/calc]"]
[then]
[discount ENTIRE_ORDER] $s + 4 [/discount]
[/then]
[/if]

I tried Racke's suggestion of using
$Scratch->{atvtotal} = $atvtot || 0;
but that broke the calculations... maybe just a typo was to blame there?

DB