You are here:  » If price = X, then don't display Y

Support Forum



If price = X, then don't display Y

Submitted by PipSqueak on Fri, 2007-06-22 18:59 in

Hi David,

Please help me with the code for something like that. I have already modded the script to include min/max prices in the search. I have products with no savings at all and it shows up as "Savings up to 0%!". Looks funny hehehe

Thanks!

Submitted by support on Fri, 2007-06-22 19:05

Hi,

Easiest thing to do is enclose your code that displays "Savings up to..." within an IF statement that checks the price first. The variable you need to test depends on where you are displaying the text. On the product page - html/product.php it would be something like:

if ($mainProduct["price"] <> X)
{
  print "Savings up to...";
}

(where X is the price you don't want to display the savings text against).

On the search results page (html/searchresults.php) use simlar code but compare against the variable $product["price"].

Hope this helps!
Cheers,
David.

Submitted by PipSqueak on Fri, 2007-06-22 19:44

Hi David,

I used this:

 <?php if ($mainProduct["price"] <> 0.00)
  print "Savings up to ".$mainProduct["field1"]."!";
?>

and it shows the text even when it's $0

Submitted by support on Fri, 2007-06-22 19:49

Hi,

Zero comparison can be a bit tricky with PHP. First try:

<?php
 
if ($mainProduct["price"] != 0)
  print 
"Savings up to ".$mainProduct["field1"]."!";
?>

...and then

<?php
 
if (floatval($mainProduct["price"]))
  print 
"Savings up to ".$mainProduct["field1"]."!";
?>

Hope this helps!
Cheers,
David.

Submitted by PipSqueak on Fri, 2007-06-22 20:54

Hi David

So sorry. I'm afraid I got myself confused. I went for: "when price is more than 0, then display field1 (savings)". Which makes no sense, why shouldn't I show 100% savings on free products?!

This works fine (for anyone who wants to do the same):

<?php
 if ($mainProduct["field1"] > 0)
  print "Savings up to ".$mainProduct["field1"]."!";
?>

Sorry for the trouble.

Submitted by philstone on Sat, 2007-06-23 08:10

Hi Dave, if i was looking to have a piece of script included in the product to say Save up to __ % what piece of script would i need to use?

Regards

phil

Submitted by support on Sat, 2007-06-23 09:23

Hi Phil,

What price do you want to make the saving comparison against? If you have a feed with an original price as well as a sales price then you would need to add a new field to your system to allow you to import the original price...

http://www.pricetapestry.com/node/313

...then you could write code to compare "price" against "originalprice" (or whatever you call the new field). An alternative would be to compare the cheapest merchant's price against the most expensive which could be done on the product page. Let me know what values you are looking to use and i'll try and help out...

Cheers,
David.

Submitted by philstone on Sat, 2007-06-23 10:45

sorry for not making that clear

i already have a piece in the script that prints a line

"Buy _product_ Today and Save Up to £____ by Comparing Prices from _ Online Stores

i was looking to add a / __ % after that amount of savings, so it would be comparing the cheapest price on he product page, to the dearest price

Regards

phil

Submitted by support on Sat, 2007-06-23 11:14

Hi Phil,

Can you post the code you're already using to display the saving and i'll work out the code for adding the percentage (it will make sure i'm using the same variables!)...

Cheers,
David.