You are here:  » If field is set, then...else...

Support Forum



If field is set, then...else...

Submitted by daem0n on Sun, 2009-06-21 04:13 in

Hi David,

Quick question I hope! I have two fields in my db - price and saleprice. I also compare based on price and I'm fine with the imported results and comparisons. I'm wondering if I can include a function that can display a sale price beside a regular price...only if that db field is populated and not set to 0.00, etc?

Any ideas? I'm sure it's a simple PHP routine. I just want to put it into product.php...search results are not important at the moment.

Thanks for any help! -Joe

Submitted by support on Mon, 2009-06-22 07:37

Hello Joe,

Sure - on it's own, the code is basically;

<?php
if ($mainProduct["saleprice"])
{
  print 
$config_currencyHTML.$mainProduct["saleprice"];
}
?>

(in other situations the variable would be $product["saleprice"] - just check what is being used by whatever code is displaying the main price)

So, in html/product.php, the main price is displayed by this code on line 23:

<?php print $config_currencyHTML.$mainProduct["price"]; ?>&nbsp;<?php print translate("from"); ?>&nbsp;

...so you could replace that with:

<?php print $config_currencyHTML.$mainProduct["price"]; ?>&nbsp;<?php if ($mainProduct["saleprice"]) print ("Sale Price: ".$config_currencyHTML.$mainProduct["saleprice"].")"?>&nbsp;<?php print translate("from"); ?>&nbsp;

...but be careful if your product pages are displaying more than one merchant - in which case it would be better to add the sale price to the prices table...

Hope this helps!

Cheers,
David.

Submitted by daem0n on Mon, 2009-06-22 07:46

That's great David, helps me out a lot - thanks! I will probably just apply it to the table like you suggest, I think that'd be the best idea since I don't want it interfering with the comparison :)

-Joe