You are here:  » Parent product listing under sub menu list


Parent product listing under sub menu list

Submitted by Nic0904 on Mon, 2016-05-16 15:22 in

Hi David,

Our categories are pretty deep in hierarchy, so the user has to go through a lot of options before they see their first product.

I had an idea to get them results faster but still allow them to dive deeper into sub cats if they wish

On your demo site you have domestic appliances, that includes washing machines, dishwashers etc..

I wanted to display products for ALL the sub cats under the usual atoz listing of the subcategories. If you could point me to the right area of code, I can adapt it to fit in with my custom category system.

Thanks
Dave

Submitted by support on Tue, 2016-05-17 08:33

Hello Dave,

One thing you could do easily is to add a "Featured Products" section below the A-Z results using the current category and all subcategories as the selection criteria. As a starting point, in categories.php, look for the following code at line 101;

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

...and REPLACE with:

  if (isset($atoz))
  {
    require("html/atoz.php");
    $wheres = array();
    foreach($nodeInfo["lowerarchy"] as $categoryid)
    {
      $wheres[] = " categoryid LIKE '%~".$categoryid."~%' ";
    }
    $where = implode(" OR ",$wheres);
    $sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." LIMIT 4";
    if (database_querySelect($sql,$rows))
    {
      $sqlNames = array();
      $sqlCase = "CASE normalised_name";
      foreach($rows as $featured)
      {
        $featured["name"] = tapestry_normalise($featured["name"]);
        $sqlNames[] = "'".$featured["name"]."'";
        $sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
      }
      $sqlCase .= " END AS sequence";
      $sqlIn = implode(",",$sqlNames);
      $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
      database_querySelect($sql,$rows);
      $featured["products"] = $rows;
      foreach($featured["products"] as $k => $product)
      {
        $featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
        $featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
      }
    }
    if (isset($featured)) require("html/featured.php");
  }

Hope this points you in the right direction!

Cheers,
David.
--
PriceTapestry.com

Submitted by Nic0904 on Wed, 2016-05-18 10:57

Hi David,

Thank-you that did point me in the right direction and I got featured products working on the page.

That got me thinking, it would be even better if I put the subcategory display in one of my side bars, and included a full product display with paging as i show for a normal subcategory.

I tried some experiments and got a lot of it working, but found I was including more and more of the search.php into categories.php. Would there be an easier way of getting this effect without effectively duplicating a lot of code in two places?

Thanks
Dave

Submitted by support on Wed, 2016-05-18 11:35

Hi Dave,

What I normally do in this kind of scenario to avoid code duplication is to split the code out into a new file e.g. searchcode.php. Then have this file included as required - including by search.php itself so you would have for example:

  require_once("includes/common.php");
  require("searchcode.php");
  require("html/header.php");
  ...

And then to use elsewhere, you can populate $_GET as required, so for example to show the first page of search results for "Blue Widgets" you would use:

  $_GET["q"] = "Blue Widgets";
  require("searchcode.php");
  require("html/searchresults.php");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com