[ic] Help? - PERL and Discount Calculation

Peter peter at pajamian.dhs.org
Wed Apr 21 21:19:55 UTC 2010

> On 4/6/2010 4:30 PM, Thomas J.M. Burton wrote:
>> Now for my question:
>> The problem I'm having is in displaying discounted prices when
>> discounts are applied to the items in question. Since I'm not using a
>> [price] tag to display pricing for each tier, I need to add some code
>> to my embedded perl that uses the sku's corresponding discount from
>> $Session->{discount} to calculate the discounted price of each tier.
>> I'm setting discounts for products on the site using the discount tag,
>> nothing out of the ordinary there. So $Session->{discount} typically
>> looks something like this (except with discounts for many more skus
>> than those snipped here):
>> {
>>   'MB6SL' =>  '$s * 0.9',
>>   'TT537-BR-SP' =>  '$s * 0.8',
>>   '500516CRYSAB' =>  '$s*0.9',
>>   '473714CRYSCOP' =>  '$s*0.9',
>>   'ABCC03' =>  '$s * 0.8'
>> }
>> What would be the best way to take the value of an sku's discount
>> setting and apply that calculation to a quantity price that I have
>> assigned to a variable in my embedded perl? In other words, if I have
>> a $price for each tier and want to calculate $s * 0.9 but use $price
>> instead of $s, how best would I do that?

Probably something like this:

	if (my $discount = $Session->{discount}->{$Row->{code}}) {
		return '[' . "calcn]my \$s = $price; $discount;[" . '/calcn]';

	else {
		return $price;

Note that unless you are using global code (such as in a global usertag)
then that's the only way I'm aware of to get an arbitrary perl
expression to be parsed like that (is to get it in the reparse stage of
the perl, calc or calcn tag).  The opening '[' is separated out from the
'calcn]' and '/calcn]' in order to prevent the interchange parser from
trying to parse it in the wrong place.


More information about the interchange-users mailing list