You are here:  » New fields on product page


New fields on product page

Submitted by wilkins on Mon, 2016-10-17 08:39 in

Hi David

Updating sites to include a lot of new fields that merchants are giving.

I have done the database side of it and they registerd OK, what I am having dificulty with is getting them to show on pages.

I am looking to put some on the product page, some in the price box and then some on the mercahnt, category and brand pages.

Is it possible to do this?

Regards

Brent

Submitted by support on Mon, 2016-10-17 11:07

Hello Brent,

The first thing to do is to make the search results re-query include all fields as by default, only the fields required by html/searchresults.php are included. To do this, edit search.php and 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 * FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

Then, wherever a product record is in context you will have access to all fields in the database. In html/searchresults.php (search results), html/featured.php and html/prices.php use $product within the loop, for example if you have a "weight" field and you want to display "Weight: 1.5kg" (and weight contains just "1.5" and is an optional field, use something like:

<?php if ($product["weight"]): ?>
Weight: <?php print $product["weight"]; ?>kg
<?php endif; ?>

For the main product information on the product page (html/product.php) use the $product_main in place of $product...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wilkins on Mon, 2016-10-17 16:32

Hi david

That works great, started to implement this, one question, could a link be put on these fields to search for that field, ie ean or brand

Regards

Brent

Submitted by support on Mon, 2016-10-17 17:32

Hello Brent,

To add search functionality for custom fields, for example "ean" and (continuing the above example) "weight", first edit search.php and look for the following code at line 138:

        $first = TRUE;

...and REPLACE with:

      case "ean":
      case "weight":
        $fields[] = "ean";
        $fields[] = "weight";
        $first = TRUE;

And with that in place, you will then be able to link to search.php using a query of, for example "weight:1.5", so to display the custom field "weight" as a link to other products of the same weight, you would use:

<?php if ($product["weight"]): ?>
Weight: <a href='<?php print $config_baseHREF."search.php?q=weight:".urlencode($product["weight"]); ?>'><?php print $product["weight"]; ?>kg</a>
<?php endif; ?>

Cheers,
David.
--
PriceTapestry.com