You are here:  » Related Products not always showing


Related Products not always showing

Submitted by Antony on Mon, 2020-10-19 07:28 in

Hi David,

Hope you're well,

My site has both Related and Featured product sections at the bottom of Product Pages. In some instances my Related/Featured do not appear and I can figure out why. I thing this is happening when there is No or Little number if merchants to compare. I've seen that on webpricecheck products with no comparable do trigger the related which I understand is triggered by searching names, and testing a search on this product name I would get results.

Examples here, 2 search results, 1 with 17 products (Featured product sections at the bottom of Product Pages) and one with 5 (Nothing at bottom)
{link saved}

Gone through forum and could not find my answers, any idea what may be causing this?

Thanks David,

Ant

Submitted by support on Mon, 2020-10-19 07:44

Hello Ant,

If a product has a category and/or brand value these are added to the Related Products query and may be the cause of the reduced (or no) related products so you might want to experiment with excluding these from the query. In products.php you'll find the following code beginning at line 92:

      if ($product["products"][0]["category"])
      {
        $wheres[] = "category = '".database_safe($product["products"][0]["category"])."'";
        $ignoreFullText = TRUE;
      }
      if ($product["products"][0]["brand"])
      {
        $wheres[] = "brand = '".database_safe($product["products"][0]["brand"])."'";
        $ignoreFullText = TRUE;
      }

To check if this is the cause in the first instance try commenting out both sections e.g.

      /*
      if ($product["products"][0]["category"])
      {
        $wheres[] = "category = '".database_safe($product["products"][0]["category"])."'";
        $ignoreFullText = TRUE;
      }
      */
      /*
      if ($product["products"][0]["brand"])
      {
        $wheres[] = "brand = '".database_safe($product["products"][0]["brand"])."'";
        $ignoreFullText = TRUE;
      }
      */

..and if results then appear, check the quality of course; and you may then want to try removing the comments from each section at a time to see whether it is category or brand equivalence that is causing the issue...

Hope this helps!
David.
--
PriceTapestry.com

Submitted by Antony on Mon, 2020-10-19 08:25

Thanks David, there is an improvement with the above. Some products that didn't show before now do - not all thou. Also was products.php

On my related.php I have

<?php
 
require("../html/searchresults.php"); 
?>

followed by

<?php
 $featuredSection
["section"] = "Category1"; require("featuredSection.php");
?>

<?php
 $featuredSection
["section"] = "Category2"; require("featuredSection.php");
?>

<?php
 $featuredSection
["section"] = "Category3"; require("featuredSection.php");
?>

Shouldn't the Featured sections appear anyway?

Many thanks for you're support!

Ant

Submitted by support on Mon, 2020-10-19 09:03

Hello Ant,

Another thing to try would be to ignore the FULLTEXT index anyway, if you edit products.php and look for the following code at line 84;

    $ignoreFullText = FALSE;

...and REPLACE with:

    $ignoreFullText = TRUE;

Regarding the Featured Products sections not being displayed; that would be because html/related.php is not being included if there are no related products to display so if you restore html/related.php to just:

<?php
 
require("../html/searchresults.php");
?>

And then edit products.php and look for the following code at line 164:

  if (isset($related)) require("html/related.php");

...and REPLACE with:

  if (isset($related)) require("html/related.php");
  $featuredSection["section"] = "Category1"; require("featuredSection.php");
  $featuredSection["section"] = "Category2"; require("featuredSection.php");
  $featuredSection["section"] = "Category3"; require("featuredSection.php");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Antony on Mon, 2020-10-19 09:45

Thanks David, the setting of $ignoreFullText = TRUE; did not make any change however with more control on the feature section being excluded from related this works great for me.

You're the best! Have a nice day!

Ant

Submitted by Antony on Mon, 2020-10-19 11:03

Sorry Im here again, can this code be amended to display only only if the product is in the same Category? ie. if the product is a Category2 product only this featured section will appear?

$featuredSection["section"] = "Category1"; require("featuredSection.php");
$featuredSection["section"] = "Category2"; require("featuredSection.php");
$featuredSection["section"] = "Category3"; require("featuredSection.php");

Thanks again David.

Ant

Submitted by support on Mon, 2020-10-19 11:22

Hello Ant,

Sure - have a go with something like this;

  $featuredSections = array("Category1","Category2","Category3");
  if (in_array($product_main["category"],$featuredSections))
  {
    $featuredSection["section"] = $product_main["category"];
    require("featuredSection.php");
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by Antony on Mon, 2020-10-19 12:09

This works like a charm! Thanks David.