You are here:  » Display sale price next to regular price in search results

Active Forum Topics


Display sale price next to regular price in search results

Submitted by Retro135 on Mon, 2016-11-28 04:38 in

If a sale price exists, is there a way to display it just to the right of the regular price on the search results page? I'd like to have the normal price switch to normal text style with a strikeout, and the sale price would be displayed in red (as I now have normal prices displayed). Example link: {link saved}

Would this significantly slow down search results display?

Submitted by support on Mon, 2016-11-28 08:34

Hi,

Firstly, to add Sale Price column, edit html/prices.php and look for the following code at line 27:

  <th><?php print translate("Price"); ?></th>

...and REPLACE with:

  <th><?php print translate("Price"); ?></th>
  <th><?php print translate("Sale Price"); ?></th>

And then to display price / sale price columns, with current price struck out if there is a sale price, look for the following code at line 59:

  <td class='pt_pr_price'><?php print tapestry_price($product["price"]); ?></td>

...and REPLACE with:

  <td class='pt_pr_price'>
    <?php print
      print ($product["saleprice"]?"<s>":"");
      print tapestry_price($product["price"]);
      print ($product["saleprice"]?"</s>":"");
    ?>
  </td>
  <td class='pt_pr_price'>
    <?php
      print ($product["saleprice"]?tapestry_price($product["saleprice"]):"&nbsp;");
    ?>
  </td>

(replace "saleprice" as required if your sale price field has a different name in the database)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Mon, 2016-11-28 21:32

I apologize for not making myself clearer. This isn't for the prices on the product page, but on main search results, merchant, brand, etc. pages.

I tried to adapt the code In searchresults.php, around line 23, but don't know how to write an if statement for this:
<?php print tapestry_price($product["minPrice"]); ?>

If there is a sale price, then apply a strikethrough to regular price, print sale price to right of regular price.

When trying in searchresults.php (code simply as is):

1. Strikethrough never appeared, also tried del and strike
2. Sale price never appeared, only a $. I made sure to change saleprice > sale_price
3. There's an extra "print" after the

Submitted by support on Tue, 2016-11-29 11:34

Hi,

This can be done in search results - however since search results are generated from a summary query, I would suggest only showing the sale price if numMerchants is 1...

Firstly, the sale_price field needs to be added to result set re-query, so in search.php look for the following code at line 476:

$sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

...and REPLACE with:

$sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating,sale_price FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

Then in html/searchresults.php where the price is display by the following code at line 59:

  <span class='pt_sr_price'><?php print tapestry_price($product["minPrice"]); ?></span>

...REPLACE with:

  <span class='pt_sr_price'>
  <?php if (($product["numMerchants"]==1) && ($product["sale_price"])): ?>
    <?php
      print "<s>".tapestry_price($product["minPrice"])."</s>";
      print "&nbsp;";
      print tapestry_price($product["sale_price"]);
    ?>
  <?php else: ?>
    <?php print tapestry_price($product["minPrice"]); ?>
  <?php endif; ?>
  </span>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Tue, 2016-11-29 14:59

Works a treat! 1 less click for shoppers to see if there's a sale price. Thank you mucho!

Submitted by Retro135 on Tue, 2016-11-29 15:27

One more tweak:
It's printing sale price field as $0.00 even for merchants with no sale price.

Never mind...figured it out (from prices.php): added " != "0.00")" after sale_price in searchresults.php
   <?php if (($product["numMerchants"]==1) && ($product["sale_price"] != "0.00")): ?>

Seems to work, is this the correct way?

I can't write code, but am a "monkey see, monkey do" coder...which sometimes works, sometimes not. Not sure of further implications.

Submitted by support on Tue, 2016-11-29 15:33

Spot on!

That implies that sale_price is DECIMAL(10,2) rather than the default VARCHAR(255) as suggested for custom fields so if left to the database default, will be "0.00" instead of "" if no sale price.

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Tue, 2016-11-29 15:38

Yet another tweak, this I can't figure out: Related products all display normal price with strikeout, then a "$"...

Submitted by support on Tue, 2016-11-29 18:34

Hi,

sale_price needs to be included in the Related Products query - products.php line 130:

$sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";

...REPLACE with:

$sql2 = "SELECT id,name,normalised_name,image_url,description,price,sale_price,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Wed, 2016-11-30 12:11

Done, thank you!