You are here:  » How to show savings in Featured Products


How to show savings in Featured Products

Submitted by IG on Thu, 2018-04-12 09:49 in

Hi David

I have created an additional field "old price", which I managed to show in Featured Products.

In addition, I would like to show the savings (price - old price) in absolute terms.

For example: (price = 100 usd) (old price = 150 usd)

How can I show the savings of 50 usd in Featured products?

Cheers, IG

Submitted by support on Thu, 2018-04-12 10:03

Hi,

In your Featured Products / Each template, use %SAVINGS% as the placeholder and then edit pto_featured.php and look for the following code at line 145:

  $each = str_replace("%PRICE%",$pto_config_currencyHTML.$row->minPrice,$each);

...and REPLACE with:

  if ($row->old_price > $row->minPrice)
  {
    $savings = "SAVE ".$pto_config_currencyHTML.pto_common_decimalise($row->old_price - $row->minPrice);
  }
  else
  {
    $savings = "";
  }
  $each = str_replace("%SAVINGS%",$savings,$each);
  $each = str_replace("%PRICE%",$pto_config_currencyHTML.$row->minPrice,$each);

(if old_price isn't exactly what you have used for the old price field name, modify the two instances in the above replacement as required...)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Thu, 2018-04-12 12:30

Works perfectly. Thank you very much.

Is there a way to see in the backend, which products have the biggest savings?

Submitted by support on Thu, 2018-04-12 13:16

Hi,

Sure - in the backend / Price Tapestry installation ( e.g. /pt/ ) edit search.php and look for the following code at line 83:

    $orderByDefault["rating"] = "rating DESC";

...and REPLACE with:

    $orderByDefault["saving"] = "(old_price - price) DESC";
    $orderByDefault["rating"] = "rating DESC";

(as above, if old_price isn't exactly what you have used modify as required)

Then browse to

/pt/search.php?q=bw:&sort=saving

(bw: is the "begins with" search operator, and without anything after the ":" it returns all products...)

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Thu, 2018-04-12 18:13

Super cool. One more time a big THANK YOU!

Submitted by IG on Thu, 2018-04-12 19:00

Hi David

How can I show the savings on this page: /pt/search.php?q=bw:&sort=saving

Cheers, IG

Submitted by support on Fri, 2018-04-13 07:58

Hi,

If you edit search.php and first change the replacement above to add the sort so that instead of:

    $orderByDefault["saving"] = "(old_price - price) DESC";

...you now have:

    $orderByDefault["saving"] = "saving DESC";

Then look for the following code at line 234:

  $sql = "SELECT SQL_CALC_FOUND_ROWS id,COUNT(id) AS numMerchants,MIN(price) as minPrice FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." GROUP BY search_name";

...and REPLACE with:

  $sql = "SELECT SQL_CALC_FOUND_ROWS id,COUNT(id) AS numMerchants,MIN(price) as minPrice,(MAX(old_price)-MIN(price)) AS saving FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." GROUP BY search_name";

Finally, in html/searchresults.php look for the following code at line 59:

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

...and REPLACE with:

  <span class='pt_sr_price'><?php print tapestry_price($product["minPrice"]); ?></span>
  <?php
    if (isset($product["saving"]))
    {
      print "<br />Saving ".tapestry_price(tapestry_decimalise($product["saving"]));
    }
  ?>

The saving will then be displayed below the price in search results...

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Fri, 2018-04-13 10:18

What can I say? I am speechless as usual. Your support is second to none!