[ic] Help? - PERL and Discount Calculation

Thomas J.M. Burton tom at globalfocusdm.com
Thu Apr 22 23:44:36 UTC 2010


On 4/21/2010 2:19 PM, Peter wrote:
>> 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:
>
> [calcn]
> 	if (my $discount = $Session->{discount}->{$Row->{code}}) {
> 		return '[' . "calcn]my \$s = $price; $discount;[" . '/calcn]';
> 	}
>
> 	else {
> 		return $price;
> 	}
> [/calcn]
>
>
> 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.
>
>
> Peter
>    

Sweet! I just tried that out and it worked perfectly!

Thanks a million, Peter!

-Tom

-- 
_______________________________
Global Focus Digital Media, LLC
www.globalfocusdm.com



!DSPAM:4bd0df5576088831084870!





More information about the interchange-users mailing list