[ic] Bug in $Tag->subtotal when items discounted?

Thomas J.M. Burton tom at globalfocusdm.com
Wed Nov 3 18:08:31 EST 2004

Ed LaFrance (New Media E.M.S.) wrote:
> At 09:55 AM 10/26/2004, Thomas J.M. Burton wrote:
>> I seem to have encountered a bug when using $Tag->subtotal in embedded 
>> perl while items are discounted. The discounted prices are not being 
>> used when the subtotal is called using perl. Example:
>> [discount 51005JT] $s * .75 [/discount]
>> [perl tables="products pricing"]
>>   my $stotal = $Tag->subtotal({name=> main, noformat => 1,});
>>   return $stotal;
>> [/perl]
>> The discounted price for the item is $6.75. I have one in my cart and 
>> the discounts display correctly. The value returned by my perl script 
>> shows a subtotal for the item at its regular price ($9).
>> The catalog's error.log says:
>> beads /cgi-bin/beads/process.html Discount for 51005JT has bad 
>> formula. Not applied.
>> > 'eval "string"' trapped by operation mask at (tag 'perl') line 1.
>> >       (in cleanup) Undefined subroutine &main:: called at 
>> /usr/lib/perl5/5.8.1/i386-linux/Safe.pm line 223.
>> Server Info:
>>     Interchange 5.0
>>     Apache-AdvancedExtranetServer/2.0.47
>>     Mandrake Linux/6.3.92mdk
>>     mod_perl/1.99_09
>>     Perl/v5.8.1
>>     mod_ssl/2.0.47
>>         OpenSSL/0.9.7b
> I'm not sure if 'name=>' will cause a syntax error in Perl, but you 
> should insert a space between 'name' and '=>' just to be safe. Other 
> than that, try giving your catalog global powers. In interchange.cfg, add
>         AllowGlobal yourcatname
> and restart Interhchange. Then add 'global=1' to the opening [perl ...] 
> tag and see if that fixes it.
> - Ed

Hi Ed,

I tried what you suggested and it didn't help. The space issue in name=> 
didn't make a difference.

Adding AllowGlobal for the catalog, then using global=1 in my perl tag 
actually ended up causing the perl code to return nothing and, while 
eliminating the original error, gave me this instead: sUbLRNeD: - [03/November/2004:14:54:29 -0800] 
beads /cgi-bin/beads/gccode Safe: Bareword "main" not allowed while 
"strict subs" in use at (eval 969) line 2
 >   my $stotal = $Tag->subtotal( { name => main, noformat => 0, } );
 >   return $stotal;

To provide a little context:
In this catalog, shipping is based on price. I'm setting up gift 
certificates for this catalog and need to remove the total of gift 
certificates ordered from the subtotal in order to calculate shipping 
properly (no shipping charge for gift certs).

Customers should be allowed to order merchandise and gift certs in the 
same order, so I have some perl code in place of the [subtotal] tag to 
calculate shipping off of an adjusted subtotal if gift certificates are 
in the order.

The code works fine as long as there are no discounted items in the 
cart, or the item total is not discounted. This catalog regularly has 
items on sale and also has discounts at order subtotals of $100, $200 
and $500. Once any of these discounts is active, my perl code is all 
wrong and uses a non-discounted subtotal in its calculations. Here is 
the perl code I'm using:

   my $stot  = $Tag->subtotal( { name => main, noformat => 1, } );
   my $gctot = $Tag->scratch(gc_total);
   my $shipmode = $Tag->value(  { name => mv_shipmode, }  );
   my $out;

   if($gctot == $stot) {
     $Tag->assign(  { shipping => 0, }  );
     $out = $Tag->shipping( { mode => $shipmode, } );

   elsif($gctot) {
     # Calculate subtotal without gift certificates, assign to subtotal
     my $adj = ($stot - $gctot);
     $Tag->assign(  { subtotal => $adj, }  );

     # Calculate shipping cost from adjusted subtotal, write output
     $out = $Tag->shipping( { mode => $shipmode, } );

     # Set shipping and reset subtotal
     $Tag->assign(  { subtotal => $stot, }  );

   else {
     $out = $Tag->shipping( { mode => $shipmode, } );

   return $out;

So, long story short, when

	 $Tag->subtotal( { name => main, noformat => 1, } )

is used in embedded perl and there's a discount on individual items or 
the entire order, the perl-based subtotal tag uses a pre-discount 
subtotal rather than a post-discount subtotal as is given with

	[subtotal noformat=1]

outside of embedded perl. Is there any way to call the post-discount 
subtotal in embedded perl short of assigning the subtotal to a scratch 
variable and calling that scratch variable?



Global Focus Digital Media, LLC


More information about the interchange-users mailing list