You are here:  » Displaying Extended Fields in Search.php


Displaying Extended Fields in Search.php

Submitted by ChrisNBC on Fri, 2017-11-03 23:00 in

Hi David,

I’m working on a new project and have decided to move on to v16.10A. The install went very smoothly and I have already added additional product fields and a few mods which all work fine. However, I need to include some of the new extended fields in the search results page. I realise the new fields are out of context but I can’t remember the mod to apply so I can use the new fields in search.php. I wondered if you could possibly remind me what needs to be modified…I’m guessing the new fields need to be included in the array so I can call them?

Thanks in advance.

Best regards
Chris

Submitted by support on Sat, 2017-11-04 09:39

Hi Chris,

16/10A already includes the full field set in the re-query so all fields in the products table are available for display in html/searchresults.php. If values are optional, it's best to use an IF condition for example;

  <?php if ($product["size"]): ?>
    Size: <?php print $product["size"]; ?>
  <?php endif; ?>

However, if using Related Products (which is displayed by the search results HTML module) and you want the same information to be displayed you will need to modify products.php - look for the following code at 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 ORDER BY NULL";

...and REPLACE with:

      $sql2 = "SELECT *,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name ORDER BY NULL";

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2017-11-06 10:08

Hi David,

Thank you as always for your super quick reply.

I added the if statement above and then realised the field I was calling was empty!...

Thanks again.

Best regards
Chris