Author Topic: Show subcategories products in parent category  (Read 23237 times)

klitoriks

  • Jr. Member
  • **
  • Posts: 53
Re: Show subcategories products in parent category
« Reply #15 on: June 03, 2010, 13:05:10 pm »
Hello all,

maybe anybody can modify this code that to show not only subcategory items in parent, but also subsubcategory items.

Anybody?

Hi,

I ran into the same problem, so have written a bit of code to sort it out - it's not very elegant and hasn't been extensively tested. At the moment only products within sub categories one level down will get shown (if I get time I'll get it to search down through the tree).

Here it is...

In administrator\components\com_virtuemart\html\shop_browse_queries.php starting on approx line 63 replace:

Code: [Select]
// Filter Products by Category
if( $category_id ) {
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
} elseif( empty( $keyword ) && empty( $manufacturer_id )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
}
}
with

Code: [Select]
// Filter Products by Category
if( $category_id ) {
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
} elseif( empty( $keyword ) && empty( $manufacturer_id )) {
$cat_child = "(`#__{vm}_product_category_xref`.`category_id`=".$category_id." OR";

// Find Child Category Products
$q  = "SELECT `category_child_id` FROM `#__{vm}_category_xref` WHERE `category_parent_id`='$category_id'";
$db_browse->query($q);
while ($db_browse->next_record()) {
$cat_child_id=$db_browse->f("category_child_id");
$cat_child .="`#__{vm}_product_category_xref`.`category_id`='$cat_child_id' OR";
}
$cat_child = substr($cat_child, 0, -3);
$cat_child .=")";
$where_clause[] = $cat_child;
}
}



As always, make sure you make a backup before trying!

qnstnerzkilz

  • Beginner
  • *
  • Posts: 1
Re: Show subcategories products in parent category
« Reply #16 on: June 10, 2010, 14:53:10 pm »
I am using this code and it works very well, but i have a question.
I have a search field on top of my page. If i search after one subcategory i get all the products listed in that subcategory. Is it possible to modify this code so that when i search a subcategory it list the link to the subcategory so when i click on it you come inside it and can view all the products?

Best regards

ady77

  • Beginner
  • *
  • Posts: 21
Re: Show subcategories products in parent category
« Reply #17 on: July 29, 2010, 19:32:56 pm »
I can't find the file In administrator\components\com_virtuemart\html\shop_browse_queries.php

HELP PLEASE!

Theres only shop.browse.php

IntraX

  • Jr. Member
  • **
  • Posts: 87
Re: Show subcategories products in parent category
« Reply #18 on: October 10, 2010, 15:30:18 pm »
Maybe because it is always added to the bottom of the shop-files listed. In FTP they are sorted alphabetically, so the _ underscore after shop and before browse places them NOT after shop.browse.php but at the end of the files starting with shop.

Vicki Payne

  • Beginner
  • *
  • Posts: 39
Re: Show subcategories products in parent category
« Reply #19 on: November 05, 2010, 00:06:40 am »
Thanks, mikeyt, your solution works great! I am trying to call the Category name (the child category, not the parent category) just above where its products are listed. $category_name brings up the parent category name, but I can't find a variable for the child name. Anybody have an idea? Thanks again!

silut7

  • Beginner
  • *
  • Posts: 3
Re: Show subcategories products in parent category
« Reply #20 on: September 13, 2011, 16:22:52 pm »
Hi,

I ran into the same problem, so have written a bit of code to sort it out - it's not very elegant and hasn't been extensively tested. At the moment only products within sub categories one level down will get shown (if I get time I'll get it to search down through the tree).

Here it is...

In administrator\components\com_virtuemart\html\shop_browse_queries.php starting on approx line 63 replace:

Code: [Select]
// Filter Products by Category
if( $category_id ) {
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
} elseif( empty( $keyword ) && empty( $manufacturer_id )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
}
}
with

Code: [Select]
// Filter Products by Category
if( $category_id ) {
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
} elseif( empty( $keyword ) && empty( $manufacturer_id )) {
$cat_child = "(`#__{vm}_product_category_xref`.`category_id`=".$category_id." OR";

// Find Child Category Products
$q  = "SELECT `category_child_id` FROM `#__{vm}_category_xref` WHERE `category_parent_id`='$category_id'";
$db_browse->query($q);
while ($db_browse->next_record()) {
$cat_child_id=$db_browse->f("category_child_id");
$cat_child .="`#__{vm}_product_category_xref`.`category_id`='$cat_child_id' OR";
}
$cat_child = substr($cat_child, 0, -3);
$cat_child .=")";
$where_clause[] = $cat_child;
}
}



As always, make sure you make a backup before trying!

I tried this hack, but it show all product under subcategories too. I just want show subcategories only, not include all products. Please help me! I'm using Joomla 1.5 and Virtuemart 1.9

silut7

  • Beginner
  • *
  • Posts: 3
Re: Show subcategories products in parent category
« Reply #21 on: September 13, 2011, 16:44:29 pm »
I found my solution. If interested, you can read this post http://forum.virtuemart.net/index.php?topic=88020.0 at Reply #8

kamnnm

  • Beginner
  • *
  • Posts: 3
Re: Show subcategories products in parent category
« Reply #22 on: October 20, 2011, 08:36:47 am »
mb somebody still searching code which show all products of sub(and subsub and deeper)categories
replace or comment this part of shop_browse_queries.php
Code: [Select]
// Filter Products by Category
if( $category_id ) {
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
} elseif( empty( $keyword ) && empty( $manufacturer_id )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
}
}
with
Code: [Select]
function GetChilds ($catid, $cats = array()) {
  $q  = "SELECT `category_child_id` FROM `#__{vm}_category_xref` WHERE `category_parent_id`='$catid'";
  $db_browse = new ps_DB;
$db_browse->query($q);
while ($db_browse->next_record()) {
$cats[]=$db_browse->f("category_child_id");
$cats = GetChilds($db_browse->f("category_child_id"), $cats);
}
return $cats;
}
if( $category_id ) {
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
} elseif( empty( $keyword ) && empty( $manufacturer_id )) {
$cat_child = "(`#__{vm}_product_category_xref`.`category_id`=".$category_id." OR";

$childs = GetChilds($category_id);
foreach ($childs as $child) {
      $cat_child .="`#__{vm}_product_category_xref`.`category_id`='$child' OR";
    }
$cat_child = substr($cat_child, 0, -3);
$cat_child .=")";
$where_clause[] = $cat_child;
}
}

aibek

  • Beginner
  • *
  • Posts: 1
    • หมึกพิมพ์ หมึกเติม ตลับหมึก
Re: Show subcategories products in parent category
« Reply #23 on: October 20, 2011, 09:09:35 am »
thank you very much

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Show subcategories products in parent category
« Reply #24 on: October 20, 2011, 09:46:40 am »
Thanks for this. I have now replaced mikeyt code with this and it works - also the RSS feeds work for the subcategories.

The only problem is, that the RSS FEED doesn't work for the parent category - the top category - if it has subcategories.

FEEDS WORK
- in subcategories
- in parent categories without subcategories

FEEDS DON'T WORK
- in parent categories with subcategories

Does anyone know how to fix that?

kamnnm

  • Beginner
  • *
  • Posts: 3
Re: Show subcategories products in parent category
« Reply #25 on: October 21, 2011, 07:59:11 am »
bobysolo, special for u :)

using part of code from my previous solution...

open shop.feed.php file

replace or comment this part
Code: [Select]
if( $feed_info['category_id'] > 0 ) {
$q_products .= "\nAND c.category_id = {$feed_info['category_id']}";
$q_products .= "\nAND c.category_publish = 'Y' ";
}
with
Code: [Select]
if( $feed_info['category_id'] > 0 ) {
$q_products .= "\nAND (c.category_id = {$feed_info['category_id']}";
if (!function_exists('GetChilds')) {
      function GetChilds ($catid, $cats = array()) {
        $q  = "SELECT `category_child_id` FROM `#__{vm}_category_xref` WHERE `category_parent_id`='$catid'";
        $db_browse = new ps_DB;
      $db_browse->query($q);
      while ($db_browse->next_record()) {
      $cats[]=$db_browse->f("category_child_id");
      $cats = GetChilds($db_browse->f("category_child_id"), $cats);
      }
      return $cats;
      }
    }
    $childs = GetChilds($feed_info['category_id']);
foreach ($childs as $child) {
      $q_products .= "\nOR c.category_id = {$child}";
    }
$q_products .= ") \nAND c.category_publish = 'Y' ";
}

but i'm not testing it ... please response if it will be useful for u)

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Show subcategories products in parent category
« Reply #26 on: October 21, 2011, 09:29:19 am »
@kamnnm

YOU ARE THE MAN!!! Thank you. I owe you a beer  :D

If you happen to pass in Slovenia, PM me, I'll buy you one.

This is what I like the most about VM - the community. And it is deffinetively a story apart from all the bad news you can hear in the latter times. Positiveness rules ;-) I'm happy and I will definitively make others also happy today.... WHOOO...HOOOO... ;-)

kamnnm

  • Beginner
  • *
  • Posts: 3
Re: Show subcategories products in parent category
« Reply #27 on: October 21, 2011, 10:32:57 am »
I am happy to hear that ur problem is resolved now  ;)
Good day for u :)

arist1213

  • Beginner
  • *
  • Posts: 7
  • Stay foolish
Re: Show subcategories products in parent category
« Reply #28 on: December 03, 2011, 06:32:30 am »
If I have a main category of security, I want to display all it's subcategory in this way which describes in the attachment.

The category list of mine only have three level. I want to retrieve all of them.

Can anybody tell me how to do it ?

[attachment cleanup by admin]

luanlun

  • Beginner
  • *
  • Posts: 2
Re: Show subcategories products in parent category
« Reply #29 on: December 23, 2011, 04:48:38 am »
thank so much, great work. Thank again pro.
http://longtk.webchuyennghiep.net/khach-san-phu-quoc - Visit for Information about hotel at Phu Quoc Island