You are here:  » Category Hierarchy results with subcategories

Active Forum Topics


Category Hierarchy results with subcategories

Submitted by sirmanu on Mon, 2019-09-09 12:08 in

Hi David.

I am pretty sure that this topic has been already discussed, but I can't find it.

I'm trying to modify a bit how products are displayed via category mapping.

RewriteRule ^category/$ categories.php [L]
RewriteRule ^category/(.*)/$ categories.php?path=$1 [L,B]
RewriteRule ^category/(.*)/(.*).html$ search.php?q=category:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L,B]

What I want to achieve, is to always display products under a category.

The only difference is that if the category has not direct children, is like is now, but if it have some children, these children are displayed above the filters.

So for example. If we have

- Electronic / Portable devices / Smartwatches.

- Electronic / Portable devices / Mobiles phones

If we are displaying products from portable devices, it should display a menu to drill down to smartwatches or mobiles phones.

Is it possible? Thank you very much

Submitted by support on Tue, 2019-09-10 08:11

Hi,

Sure - categories.php only calls in search.php at the leaf nodes (no children) however it can be modified to be called in at any level - to do this, look for the following code at line 39:

    elseif($path)

...and REPLACE with:

    if($path)

Then in order to show the A-Z to lower level categories above the filters edit search.php and look for the following code at line 545:

  require("html/banner.php");

...and REPLACE with:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Tue, 2019-09-10 10:23

Impressive, so easy!!

Finally, how can I limit the number results so the query is faster. There are some parent categories which have several subcategories and the query is a bit slow.

Submitted by support on Tue, 2019-09-10 10:40

Hi,

You could slice the array of sub-categories to the last "n" which would reduce the number of categories in the query. To try this and limiting to 2 sub-categories, edit search.php and look for the following code at line 114:

          $in = implode(",",$ins);

...and REPLACE with:

          $ins = array_slice($ins,-2);
          $in = implode(",",$ins);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Tue, 2019-09-10 11:45

Okey! That is the only option, right?

Can't be done after sort results with order BY?

Submitted by support on Tue, 2019-09-10 13:29

Hi,

As an alternative to the above modification to search.php you could try a fixed limit when $atoz is set - look for the following code beginning at line 337:

    $offset = ($page-1) * $config_resultsPerPage;
    $sql .= " LIMIT ".$offset.",".$config_resultsPerPage;
    $numRows = database_querySelect($sql,$rows);
    $sqlResultCount = "SELECT FOUND_ROWS() as resultcount";
    database_querySelect($sqlResultCount,$rowsResultCount);
    $resultCount = $rowsResultCount[0]["resultcount"];

...and REPLACE with:

    if (!isset($atoz))
    {
      $offset = ($page-1) * $config_resultsPerPage;
      $sql .= " LIMIT ".$offset.",".$config_resultsPerPage;
      $numRows = database_querySelect($sql,$rows);
      $sqlResultCount = "SELECT FOUND_ROWS() as resultcount";
      database_querySelect($sqlResultCount,$rowsResultCount);
      $resultCount = $rowsResultCount[0]["resultcount"];
    }
    else
    {
      $sql .= " LIMIT 10";
      $numRows = database_querySelect($sql,$rows);
      $resultCount = $numRows;
    }

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Wed, 2019-09-11 08:58

Thank you David.

As I thought, it is still slow, as database needs to order first all results. No problem, I will use the previous solution. If someone needs to find a product, it can be found with children categories inside atoz!

Best regards