You are here:  » Show Lowest Price Displayed in Filtered Price Table


Show Lowest Price Displayed in Filtered Price Table

Submitted by ChrisNBC on Mon, 2017-06-12 15:00 in

Hi David,

Hope all is going well.

As you know, I’m using a size filter on my product pages. In some instances the price of identical products displayed in the price table varies depending on size. I wondered if you might be able to suggest how I could display the lowest price shown in the price table (so taking into account any size filter set). The current code (below) displays the lowest price but when the size filter is applied the price displayed by the code remains unchanged. I wondered if there might also be a way to refresh the lowest price using ajax (in the same way as the price table)?

<span><h3><br><?php print translate ("Prices From"); ?><span itemprop='lowPrice'><?php print $config_currencyHTML.$product["products"][0]["price"];?></br></h3></span>

Thanks in advance.

Best regards
Chris

Submitted by support on Tue, 2017-06-13 08:07

Hi Chris,

Have a go with the following;

<?php
  $sizeFilter = (isset($_GET["sizeFilter"])?$_GET["sizeFilter"]:"");
  if ($sizeFilter)
  {
    foreach($product["products"] as $i => $p)
    {
      $sizes = explode(",",$p["size"]);
      if (in_array($sizeFilter,$sizes)) break;
    }
  }
  else
  {
    $i = 0;
  }
?>
<span><h3><br><?php print translate ("Prices From"); ?><span itemprop='lowPrice'><?php print $config_currencyHTML.$product["products"][$i]["price"];?></br></h3></span>

This sets an index variable $i pointing to the lowest price result in the $product["products"] array, defaulting to 0 if no sizeFilter in effect, otherwise the foreach loops check each result against the filter value, breaking from the loop when found leaving $i as the index of the lowest price result...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Tue, 2017-06-13 11:01

Hi David,

Thanks as always for your super quick response. I've updated the site with the replacement code above but it does not seem appear to work...I wondered if you might be able to suggest anything to resolve this..

Thanks in advance.

Best regards
Chris

Submitted by support on Tue, 2017-06-13 11:06

Hi Chris,

Please could you email me the file containing the code and I'll check it out in context...

Thanks,
David.
--
PriceTapestry.com