knitting

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

aurax

  • Beginner
  • *
  • Posts: 19
Show subcategories products in parent category
« on: November 18, 2008, 19:04:08 pm »
Hi all,

I want to show subcategories products in parent category

I have a category named 'cards' with subcategories 'pocker' 'dice' and 'cases' and i want the products inside the subcats to show in 'cards' with subcat title for each category.

I am willing to pay for such patch and advertise it here for free...

thank you.


Forrest

  • Global Moderator
  • Hero Member
  • *
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Show subcategories products in parent category
« Reply #1 on: May 26, 2009, 12:51:35 pm »
Been too long for this to help you, but this post has been viewed several times. This is easy to accomplish.

If you want to have your products in sub categories show in parent categories, select the parent category and sub category in the product item page.

You probably only selected the sub-category, but by holding shift key, you can select multiple categories for one product to display in.

Hope this helps!

Canonier

  • Beginner
  • *
  • Posts: 8
Re: Show subcategories products in parent category
« Reply #2 on: September 22, 2009, 00:14:30 am »
Yes it is some way, but will nice option to show random numberes from subcategories to show it in parent.

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Show subcategories products in parent category
« Reply #3 on: September 22, 2009, 03:52:07 am »
I'm also interested in this - but not the way Forrest said. I know you can select multiple categories for a specific article. But this also brings in SEO garbage, because two different links are created for the same article - for the one in the category and for the article in subcategory (and any other category the article might be in).

I was wondering, is it possible to publish articles only in subcategories, but that would still appear on the parent category?

And the links generated would lead to the subcategory article?

mikeyt

  • Beginner
  • *
  • Posts: 7
Re: Show subcategories products in parent category
« Reply #4 on: December 03, 2009, 10:26:09 am »
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!

AGuerrero

  • Beginner
  • *
  • Posts: 6
Re: Show subcategories products in parent category
« Reply #5 on: December 05, 2009, 16:14:05 pm »
I have tried it, and works great.

i think this should be a "must have" in the next virtuemart version:

"Do you want to show subcategories products in parents categorys?"

Or better: It should be selected in the category propierties:

"Do you want to show subcategories products in THIS category?

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Show subcategories products in parent category
« Reply #6 on: December 11, 2009, 09:32:32 am »
Thanks - that's exactly what I needed. Now updating my page will take less time. You saved the day  ::)

sanmatteo

  • Beginner
  • *
  • Posts: 4
Re: Show subcategories products in parent category
« Reply #7 on: May 05, 2010, 04:50:06 am »
I used this hack and it worked for me, but now i got blank rss pages for parent category product feeds.
Is there a way to hack the rss feed too?

Thank you very much

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Show subcategories products in parent category
« Reply #8 on: May 05, 2010, 05:21:17 am »
Now that you mention it I saw the same problem occurs by us. Didn't notice that problem before.

Anyone any ideas? I'll also have a look into it and post here if I happen to find a solution.

sanmatteo

  • Beginner
  • *
  • Posts: 4
Re: Show subcategories products in parent category
« Reply #9 on: May 07, 2010, 02:23:56 am »
in line 112 of shop.feed.php try to replace

Code: [Select]
$info['category_id'] = $category_id;// Filter by category? At this place, category_id is INT
with

Code: [Select]
$info['category_id'] = $category_child_id;// Filter by category? At this place, category_id is INT
it works for me...

rhand-vm

  • Jr. Member
  • **
  • Posts: 74
Re: Show subcategories products in parent category
« Reply #10 on: May 18, 2010, 00:37:06 am »
Is there a possibility by now for a category page to simply display sub categories when there are some and products if this is not the case? The solution mentioned here does not seem to cover this..

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Show subcategories products in parent category
« Reply #11 on: May 18, 2010, 02:13:32 am »
Is there a possibility by now for a category page to simply display sub categories when there are some and products if this is not the case? The solution mentioned here does not seem to cover this..
The solution here does just that. I think the only limitation is that it cannot show products from subcategories deeper than the 2. level.

rhand-vm

  • Jr. Member
  • **
  • Posts: 74
Re: Show subcategories products in parent category
« Reply #12 on: May 18, 2010, 02:54:26 am »
@ Bobysolo Well I just tested the code mentioned here earlier and I only got sub category products to display on the category page. So the category parent did not display its children. Maybe a VM configuration issue?

roncse29

  • Beginner
  • *
  • Posts: 1
Re: Show subcategories products in parent category
« Reply #13 on: May 25, 2010, 02:50:23 am »
i just want to turn off the titles of the sub category.

in details

i have 1 category 'eStore', 2 sub-category 'Category 1' & 'Category 2' undher the 'eStore'.

After hacking the shop_browse_queries.php file, now when i go to index.php?option=com_virtuemart, all products of these 2 category are displayed here but my problem is, there are the links 'Category 1' and 'Category 2' are still in this page, which i cant remove. can anyone help please?

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Show subcategories products in parent category
« Reply #14 on: May 25, 2010, 03:03:15 am »
@ rhand-vm and roncse29 - I think you both have to modify your browse includes file in your VM template - themes\default\templates\browse\includes\browse_header_category.tpl.php

There there's this code:
Code: [Select]
<div style="text-align:left;">
<?php echo $navigation_childlist?>
</div>
If you remove it, the subcategories will not be listed.

VirtueMart Forum

Re: Show subcategories products in parent category
« Reply #14 on: May 25, 2010, 03:03:15 am »