VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Development Projects, Modifications, Hacks & Tweaks. VM1.1 => Topic started by: lashae on August 11, 2006, 22:44:04 pm

Title: Displaying all products under sub-categories too
Post by: lashae on August 11, 2006, 22:44:04 pm
Hi all,

if you need to display all products under the sub-categories of the current category too, you can simply do the following.

1. Open administrator/components/com_virtuemart/html/shop_browse_queries.php

2. At the top of the file after the line starting with mm_showMyFileName... insert the following;

Code: [Select]
function untreeCat($kat, &$container)
{
$parentsql = mysql_query("SELECT category_child_id FROM portal_vm_category_xref WHERE category_parent_id=$kat");
// if it is a leaf (no data underneath it) then return
if (!mysql_num_rows($parentsql))
{
return;
}
//else append the result, and recurse the function (so to speak)
else
{
while($dataset = mysql_fetch_array($parentsql))
{
  $container[] = $dataset['category_child_id'];
  $kat = $dataset['category_child_id'];
  untreeCat($kat, $container);
}
}
}

3. Then, search for the following snippet;

Code: [Select]
if( $category_id ) {
  $q .= "\n AND `#__{vm}_product_category_xref`.`category_id`='".$category_id."' ";
}

replace it with the following;

Code: [Select]
if( $category_id )
{
$kategoriListesi = array();
$q .= "\n AND `#__{vm}_product_category_xref`.`category_id`='".$category_id."' ";
untreeCat($category_id, $kategoriListesi);

foreach ($kategoriListesi as $kat)
{
$q .= "\n OR `#__{vm}_product_category_xref`.`category_id`='".$kat."' ";
}
}

Then enjoy ;-)

Edit: Of course to add that; the portal_vm phrase should correspond to your Joomla and VM installation DB prefixes.
Title: Re: Displaying all products under sub-categories too
Post by: mknz on September 07, 2006, 03:07:57 am
absolutely amazing!  Very easy to put together, but I need to be able to display what sub-cat each item is in.
-OR-
If it could just display the first category below and then the child items of the items in there, it would work...let me explain.

My setup is for a music site that is laid out like this:
Band->Releases->Album->Tracks
where the album can be bought physically as CD or LP and tracks can be purchased as downloads individually or as the complete album.

also band merchandise is laid out:
Band->Merch->T-Shirts->Item

I've tried parent/child setups for the album/tracks; I've tried this hack to show everything in the band category, but I can't make it display the items displayed in their appropriate category from one page like this:

Band Category

   Picture & Description

Releases - No Description ('cause I didn't add one)

   Album One - Picture & Description

      Track 1 Mp3 | Sample | Add to Cart
      Track 2 Mp3
      Track 3 Mp3
      CD
      LP
      MP3

   Album Two - Picture & Description

      Track 1 Mp3 | Sample | Add to Cart
      Track 2 Mp3 | Sample | Add to Cart
      Track 3 Mp3 | Sample | Add to Cart
      CD | Add to Cart
      LP | Add to Cart
      MP3 | Add to Cart

Very interested to find a solution...I'm just not any good at PHP...THANX A MILLION!

-mknz
Title: Re: Displaying all products under sub-categories too
Post by: MartijnBoeve on November 23, 2006, 15:05:43 pm
I think this is just what I'm looking for but I'm encountering some problems...

I've integrated the code and it does show products in the main category, but it displays all products and not just the ones from the sub-categories, also it should display 4 products in a row, but it displays 3 in a row (i have the right shop_browse page and the # of products in a row is set to 4)...

is it supposed to show just all products or the products it finds in the subcats? Also loading the page takes much longer.

Has anyone encountered these problems ans solved them? I would be eternaly thankfull!
Martijn

Title: Re: Displaying all products under sub-categories too
Post by: Creb on December 20, 2006, 16:29:14 pm
I modified to last Code

Code: [Select]

if( $category_id ) {
  $q .= "\n AND `#__{vm}_product_category_xref`.`category_id`='".$category_id."' ";
}


replace it with the following;

Code: [Select]
if( $category_id )
{
$kategoriListesi = array();
untreeCat($category_id, $kategoriListesi);
$qkat = "\n AND `#__{vm}_product_category_xref`.`category_id` IN(".$category_id . ",";
foreach ($kategoriListesi as $kat)
{
$qkat .= $kat . ',';
}
$qkat .= ")";

$qkat = str_replace(',)', ')', $qkat);
$q .= $qkat;
}

This working OK

Creb
Title: Re: Displaying all products under sub-categories too
Post by: Creb on March 26, 2007, 02:38:18 am
In VM 1.0.10

repleace it for this
Code: [Select]
if( $category_id ) {
//$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
$kategoriListesi = array();
untreeCat($category_id, $kategoriListesi);
$qkat = " `#__{vm}_product_category_xref`.`category_id` IN(".$category_id . ",";
foreach ($kategoriListesi as $kat)
{
$qkat .= $kat . ',';
}
$qkat .= ")";

$qkat = str_replace(',)', ')', $qkat);
$where_clause[] = $qkat;

}

Creb
Title: Re: Displaying all products under sub-categories too
Post by: FritoBandito on June 20, 2007, 08:51:10 am
Thanks Creb!  Worked perfectly!
Title: Re: Displaying all products under sub-categories too
Post by: Martin on June 23, 2007, 13:28:18 pm
It works but it displays all products under the sub-categories too.
I just want the mod to display all products under the parent category.
Basically what i want is a category like this:

Cameras->All Products
           ->Outdoor
           ->Indoor

If that's not possible i want Cameras to display all products.
Is there a way to get this done easily?

Thanks. :)
Title: Re: Displaying all products under sub-categories t
Post by: Francois1 on July 12, 2007, 22:22:31 pm
Thanks Creb and lashae

The 2 snippets of code does not seem to work in version 1.0.12 any more. Is there anything I can do to fix this.
Thanks in advance.
Title: Re: Displaying all products under sub-categories too
Post by: haselnuss on August 01, 2007, 16:25:36 pm
Hi.
Thanks to lashae and Creb for the code snippets.
I've rewritten them a little just to store the "untreeCat" in ps_product_category.php and to use the ps_DB class. I tested on VM 1.0.12 and it works.

1. In administrator/components/com_virtuemart/html/shop_browse_queries.php

replace
Code: [Select]
if( $category_id ) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
}
with
Code: [Select]
if( $category_id ) {
//$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
$kategoriListesi = array();
$ps_product_category->untreeCat($category_id, $kategoriListesi);
$qkat = " `#__{vm}_product_category_xref`.`category_id` IN(".$category_id . ",";
foreach ($kategoriListesi as $kat)
{
$qkat .= $kat . ',';
}
$qkat .= ")";

$qkat = str_replace(',)', ')', $qkat);
$where_clause[] = $qkat;

}

2. In administrator/components/com_virtuemart/classes/ps_product_category.php
add the "untreeCat" function at the end of the class
Code: [Select]
/*
* Returns an array of the categories ids recursively for a given category
* untreeCat © lashae (virtuemart forum http://virtuemart.net/index.php?option=com_smf&Itemid=71&topic=20837.0)
* @param int $kat
* @param int $container
* rewritten by haselnuss (to use ps_DB class and store the function in ps_product_category.php)
*/
function untreeCat($kat, &$container) {
$db = new ps_DB;
$q = "SELECT `category_child_id` FROM `#__{vm}_category_xref` WHERE `category_parent_id`=$kat";
$db->query($q);
// if it is a leaf (no data underneath it) then return
if (!$db->num_rows()) {
return;
}
//else append the result, and recurse the function (so to speak)
else
{
while($db->next_record()) {
  $container[] = $db->f("category_child_id");
  $kat = $db->f("category_child_id");
  $this->untreeCat($kat, $container);
}
}
}

Hope this helps someone.

Cya

Title: Re: Displaying all products under sub-categories t
Post by: Timothy on August 31, 2007, 18:07:34 pm
Thank you!  It works perfectly.  I just wish I would have found this sooner than after searching for this hack for over an hour.  It seems strange that this is not the default behavior or an checkable option in the admin.
Title: Re: Displaying all products under sub-categories t
Post by: Techno-Tronics on August 31, 2007, 18:52:36 pm
Can't find shop_browse_queries.php anywhere, think this isn't in the normal installation ?

Where to download the file ?
Title: Re: Displaying all products under sub-categories too
Post by: emfglobal on October 30, 2007, 16:05:11 pm
I am currently using VM 1.0.12 integrated into Joomla of course.. (What else)

But I can not get this to work for me.
I can get all products to show up under a sub cat, but what I would like is to only show produckts from that particular categorie,
for example,

I sell cat stuff and dog stuff

under Dog stuff I have Food, Toys, and Other

Under Food I have Cokkies  and Other

Here I would like to show all Dog Food..


But I would alos like to show all dog stuff under the Categories when you click on Dogstuff..
The reason is i have many productks and catagoeries and sub categories, but i would like to make it as easy as possible for anyone to shop for the correct item...


I hope you get what I am looking for..
If you know what you are doing, you could also PM me and I will show you in the site what I am talking about...

thanks for any help...
Espen

Title: Re: Displaying all products under sub-categories too
Post by: meehal on March 05, 2008, 13:40:01 pm

I've loaded this up and its a great tool, has anyone figured out have to get the category name in the output to break it up?

Or any ideas which part i might look at to modify and get me in the right direction?

thank you.
Title: Re: Displaying all products under sub-categories too
Post by: FavoriteU on April 01, 2008, 01:22:10 am
I want to thank lashae, Creb and Haselnuss for this.  I have been looking for a way to do this for a while and somehow missed this post.  It works great!

I'm sure there are others out there looking for the same thing.
Title: Re: Displaying all products under sub-categories too
Post by: scha on May 21, 2008, 12:45:51 pm
Hi there, thank you :)

In VM 1.0.15 i had a "Call to a member function on a non-object in shop_browse_queries.php" on that line:
Code: [Select]
$ps_product_category->untreeCat($category_id, $kategoriListesi); when trying to view a product detail (categories, subcats and overview were working perfectly fine!)
i added
Code: [Select]
global $ps_product_category; somewhere before the erronous part and its now working, but my code understandings for oop are somewhat small.. Can anyone tell me if there is a better (or righter) solution for that problem?

regards
Title: Re: Displaying all products under sub-categories too
Post by: aurax on November 19, 2008, 00:00:54 am
any patch for 1.1?

i am getting:
Code: [Select]
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/yifahaz1/public_html/shop/administrator/components/com_virtuemart/html/shop_browse_queries.php on line 25
Title: Re: Displaying all products under sub-categories too
Post by: Colosimo on February 03, 2009, 22:37:16 pm
i need the same for VM 1.1.2, that code is not working.
anyone?

c.
Title: Re: Displaying all products under sub-categories too
Post by: Creb on February 21, 2009, 23:09:35 pm
Helo again, I change this to VM 1.1.3 and Joomla 1.5.8
In administrator/components/com_virtuemart/classes/ps_product_category.php
add the "untreeCat" function at the end of the class, thanx haselnuss

Code: [Select]
/*
* Returns an array of the categories ids recursively for a given category
* untreeCat copy lashae (virtuemart forum http://virtuemart.net/index.php?option=com_smf&Itemid=71&topic=20837.0)
* @param int $kat
* @param int $container
* rewritten by haselnuss (to use ps_DB class and store the function in ps_product_category.php)
*/
function untreeCat($kat, &$container) {
$db = new ps_DB;
$q = "SELECT category_child_id FROM #__{vm}_category_xref WHERE category_parent_id='$kat'";
$db->query($q);
// if it is a leaf (no data underneath it) then return
if (!$db->num_rows()) {
return;
}
//else append the result, and recurse the function (so to speak)
else
{
while($db->next_record()) {
  $container[] = $db->f("category_child_id");
  $kat = $db->f("category_child_id");
  $this->untreeCat($kat, $container);
}
}
}

and in administrator/components/com_virtuemart/html/shop_browse_queries.php I add detect list categories page. I dont know, why can't detect untree function on product details page.
About line 63 change:

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;
}
}

to:

Code: [Select]
// Filter Products by Category
/*
* Returns an array of the categories ids recursively for a given category
* untreeCat copy lashae (virtuemart forum http://virtuemart.net/index.php?option=com_smf&Itemid=71&topic=20837.0)
* rewritten by Creb (to use shop.browse page detection)
*/
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 )) {

if ($_GET["page"]=="shop.browse") {
  //$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
$kategoriListesi = array();
$ps_product_category->untreeCat($category_id, $kategoriListesi);
$qkat = " `#__{vm}_product_category_xref`.`category_id` IN(".$category_id . ",";
foreach ($kategoriListesi as $kat)
{
$qkat .= $kat . ',';
}
$qkat .= ")";

$qkat = str_replace(',)', ')', $qkat);
$where_clause[] = $qkat;
} else {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
}

}
}

If we need hide category thumbnails comment line 106 in administrator/components/com_virtuemart/html/shop.browse.php

Code: [Select]
//$navigation_childlist = $tpl->fetch( 'common/categoryChildlist.tpl.php');
Hope this helps someone.

regards
Creb
Title: Re: Displaying all products under sub-categories too
Post by: sizex on March 10, 2009, 01:14:20 am
wow thanks so much creb just what I was after.  thats great!
Title: Re: Displaying all products under sub-categories too
Post by: jean-mouloud on May 25, 2009, 13:31:10 pm
Thanx a lot Creb!
It was very helpful for me!
Thnx thnx thnx a lot!  :)
Title: Re: Displaying all products under sub-categories too
Post by: CocoDen on September 22, 2009, 13:33:11 pm
Hello! I don't understand how I may to make structure on one page (main page):

category1 (title):
- proguct1;
- product2;
- product3;

category2 (title):
- proguct4;
- product5;
- product6;

category3 (title):
- proguct7;
- product8;
- product9...

Which don't need click to link of categories or without categories.
Example: http://artflowers-sib.ru/

Please describe me this more in detail. I'm not professional.

I use Joomla 1.5.10 and VM 1.1.3
Title: Re: Displaying all products under sub-categories too
Post by: CocoDen on September 23, 2009, 00:38:46 am
Nobody don't know?
Title: Re: Displaying all products under sub-categories too
Post by: baggiesmad on December 02, 2009, 14:37:55 pm
Nobody don't know?

did you find a way of sorting this?
Title: Re: Displaying all products under sub-categories too
Post by: afterimage on June 29, 2010, 16:05:05 pm
Hi all, I'm getting the following error, any idea what I'm doing wrong?

Code: [Select]
Fatal error: Call to undefined method ps_product_category::untreeCat() in (home directory)/administrator/components/com_virtuemart/html/shop_browse_queries.php  on line 148
I'm using 1.5.18 with 1.1.4

Thanks in advance.
Title: Re: Displaying all products under sub-categories too
Post by: Creb on June 29, 2010, 20:21:27 pm
Can You change administrator/components/com_virtuemart/classes/ps_product_category.php ?
You myst add function untreeCat after function sort_alphabetically.
End of teh class vm_ps_product_category.
Work fine for me.
Creb
Title: Re: Displaying all products under sub-categories too
Post by: leonk on July 21, 2010, 09:38:15 am
I am using Virtuemart 1.1.4 with Joomla 1.5.18.
What is the code change in administrator/components/com_virtuemart/html/shop_browse.php?
I was unable to find
// Filter Products by Category

Thanks
Leon
Title: Re: Displaying all products under sub-categories too
Post by: Creb on July 21, 2010, 13:18:07 pm
sorry, this is my comment :)
You must looking for
Code: [Select]
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
Creb
Title: Re: Displaying all products under sub-categories too
Post by: leonk on July 21, 2010, 16:16:07 pm
Thank you, Creb, I managed to change and add the codes in the 2 files

But the shop does not show what I expect to see:
Example:
Categorie A
Sub-categorie A1  2 articles
Sub-categorie A2  3 articles
Sub-categorie A3  5 articles

When I choose Categorie A in the tree I would like to see 10 articles (sorted in Sub-categories) and I see only the links with Sub-categorie A1, Sub-categorie A2 and Sub-categorie A2 and no articles.
When I choose a Sub-categorie in the tree, e.g. A3 I see the correct (5) articles.

How do I proceed?
Thanks
Leon
Title: Re: Displaying all products under sub-categories too
Post by: Creb on July 21, 2010, 16:56:43 pm
you have link to shop?
Creb
Title: Re: Displaying all products under sub-categories too
Post by: leonk on July 21, 2010, 17:17:53 pm
Think I managed it by through a walkaround: I linked a product to both a category and a sub-category
Title: Re: Displaying all products under sub-categories too
Post by: klitoriks on August 11, 2010, 12:59:13 pm
Hello all,

this hack works fine. But how I can do to show not only all products under sub-categories, but also products under sub-sub-categories?

Anybody know?
Title: Re: Displaying all products under sub-categories too
Post by: Creb on August 11, 2010, 13:53:49 pm
this works with sub-sub categpries too
Creb
Title: Re: Displaying all products under sub-categories too
Post by: klitoriks on August 11, 2010, 14:19:20 pm
hmm, not working for my :/

I mean, then I press on Parent category it shows all products from parent and sub-categories. But no from sub-sub categories.

I need that then I press on Parent category it would show all products from sub and sub-sub categories :)
Title: Re: Displaying all products under sub-categories too
Post by: klitoriks on August 11, 2010, 14:27:23 pm
try to see it here:
http://www.e-buitis.lt/index.php?page=shop.browse&category_id=60&option=com_virtuemart&Itemid=2 (http://www.e-buitis.lt/index.php?page=shop.browse&category_id=60&option=com_virtuemart&Itemid=2)


Title: Re: Displaying all products under sub-categories too
Post by: Creb on August 11, 2010, 18:20:24 pm
Works, check next pages.

Sorry, I click for secound cat.
Title: Re: Displaying all products under sub-categories too
Post by: klitoriks on August 13, 2010, 08:07:48 am
So, not working, yes?

Maybe you know what to change in code?
Title: Re: Displaying all products under sub-categories too
Post by: klitoriks on August 15, 2010, 16:26:50 pm
Anybody?
Title: Re: Displaying all products under sub-categories too
Post by: limetree on August 17, 2010, 16:04:46 pm
This is a serous messy thred... It's not easy to know WHAT and WHERE to put the code if you're using ex: JOOMLA 1.5.20 + Virtuemart 1.1.5...

I've tried a lot of combinations and I just different error like "Fatal error: Using $this when not in object context in ... administrator/components/com_virtuemart/classes/ps_product_category.php on line 1479"

How do with J 1.5.20 vm 1.1.4?

Thanks


Title: Re: Displaying all products under sub-categories too
Post by: klitoriks on August 18, 2010, 12:40:30 pm
My shop is under Jommla 1.5.15 and VM 1.1.4

I thought that this hack will work with all sub cats, but it don't.

I need it to work with sub-sub categories. Maybe together we can do it? :)
Title: Re: Displaying all products under sub-categories too
Post by: IntraX on August 29, 2010, 02:07:57 am
Yes, please an update for J1.5.20 / VM 1.1.5, Mr Creb!:) There is some things changed and it does not work like when it was still 1.1.3.

Until 1.1.3 it worked perfectly, but now its messed up and not working correctly anymore with 1.1.5.

Title: Re: Displaying all products under sub-categories too
Post by: supawat on September 07, 2010, 18:51:31 pm
Thank you Creb. It working great with my Joomla 1.5.20 and VM 1.1.5
This is step by step for do it.
1. EDIT : /administrator/components/com_virtuemart/classes/ps_product_category.php
insert the source code from "Creb"(http://forum.virtuemart.net/index.php?topic=20837.15) between "function sort_alphabetically" and "// Check if there is an extended "
Please beware the "}". It might be make you confusing.
2. EDIT : /administrator/components/com_virtuemart/html/shop_browse_queries.php and follow as Creb's post.

That's it!


http://www.thanakim.com/update/ps_product_category.png (http://www.thanakim.com/update/ps_product_category.png)
http://www.thanakim.com/update/shop_browse_queries.png (http://www.thanakim.com/update/shop_browse_queries.png)

 
Title: Re: Displaying all products under sub-categories too
Post by: gcrombach on November 22, 2010, 13:51:30 pm
So with this change of code all products under all sub-categories will show up in the listing. This works fine for me during testing.

I need some extra: I would need the sub-category, name, pic & descr. as well on top of every product listing.

so clicking on a cat the page would look like this:

Name category - pic -descr.
 sub-cat1 name - pic - descr.
  listing of products of sub-cat1
 sub-cat2 name - pic - descr.
  listing of products of sub-cat2
 sub-cat3 name - pic - descr.
  listing of products of sub-cat3

is this easy to adjust with the code listed as above ? ( done by Creb)

Thanks,

Title: Re: Displaying all products under sub-categories too
Post by: karan.gadhavi on January 11, 2011, 13:19:05 pm
Hell Creb & gcrombach,

Its really useful information.  Can you please help me to sort out below issue. I need to show category page like below  how to do this ?

 - Category detail (Name, Image , Description )
    - category product
      - Sub category1 detail (name,image, desc)
       -  Sub category1 products (name, img, desc)
      - Sub category2 detail (name,image, desc)
       -  Sub category2 products (name, img, desc)

Thanks a lot in advance

Gcrombach,  let me know if you found solution of it.

Thanks
Title: Re: Displaying all products under sub-categories too
Post by: madhanponugumati on February 08, 2011, 14:52:25 pm
Hell Creb & gcrombach,

I have gone through your posts. Its very useful. I need the Subcategories products list  to be displayed in the Product Detail Page.Can you plz plz help me out. Waiting for your reply

Product detail Page-> Subcategories products list


Thanks
Title: Re: Displaying all products under sub-categories too
Post by: AndreyUA on February 09, 2011, 00:20:05 am
Hi everyone! Nice modification. I saw one problem - no filtering by manufacturer in the main category. This problem can somehow be solved?
Title: Re: Displaying all products under sub-categories too
Post by: voidkun on March 12, 2011, 00:41:46 am
this doesnt seem to work in 1.1.6, kept giving me "fatal error, call to unidentified function
Title: Re: Displaying all products under sub-categories too
Post by: nickwalks on March 29, 2011, 01:37:46 am
Hello Iashae, Creb, gcrombach, supawat and all other contributors to this thread.

Thanks for all your hard work with this modification. It works really well for me with Joomla 1.5.22 and VM 1.1.5.

Currently this displays all the products - fantastic.

I just have a couple of questions:

1. Does anyone have a solution to display each category with it's title then all the products within that category then a line break or <hr> and the next category and so on. Just to break things up a bit but still group products together.

2. When I am logged in and navigate to "component/virtuemart/?page=shop.registration" it takes me to "products?page=shop.index" which shows the default shop front page which has all the categories as links... Any suggestions here??? If I am not logged in it takes me to the registration page...

Thanks again and any help here would be greatly appreciated.

nickwalks
Title: Re: Displaying all products under sub-categories too
Post by: pelusian on April 26, 2011, 18:05:44 pm
Hi all, tnx for your posts, they helped me a lot! I have a problem again: I need to display sub-category name too, so in the same page I'd have
Category name
 subcategory1 name
    subcat1 product1
    subcat1 product2

 subcategory2 name
    subcat2 product1
    subcat2 product2

Tnx in advance for your help
Title: Re: Displaying all products under sub-categories too
Post by: kimmo on May 23, 2011, 23:12:53 pm
I try to Creb's code, but i get "fatal error" My Virtuemart is 1.1.5 and Joomla is 1.5.21

I saw that Nickwalks this working very well.

It's harm. I just bought Cherry Picker and want to filter product with that. Now the problem is that filter is lookin attributes from child producst also, and they dont come up in browse page.

I'm kind newbie with code, so any help would be great!
Title: Re: Displaying all products under sub-categories too
Post by: sambo on July 28, 2011, 06:34:24 am
@kimmo, check the position of the first code change step and note the extra bracket.

Quote
Posted by: supawat
« on: September 07, 2010, 10:51:31 AM »

    Insert Quote


Thank you Creb. It working great with my Joomla 1.5.20 and VM 1.1.5
This is step by step for do it.
1. EDIT : /administrator/components/com_virtuemart/classes/ps_product_category.php
insert the source code from "Creb"(http://forum.virtuemart.net/index.php?topic=20837.15) between "function sort_alphabetically" and "// Check if there is an extended "
Please beware the "}". It might be make you confusing.
2. EDIT : /administrator/components/com_virtuemart/html/shop_browse_queries.php and follow as Creb's post.

That's it!
Title: Re: Displaying all products under sub-categories too
Post by: potongsaga on July 29, 2011, 20:25:53 pm
hi there, im totally new to VM, and totally lost. i took more than a day to figure out how to show cart on the front end of my site...

now after creating categories for my items, i have also created sub categories.

pardon me if this has been posted before, because im really having trouble trying to figure out the thread and solutions..

I have categories such as Dog, Small Animals, Cat. Under each of these category i have Food, Carrier and Cages as subcategories. i managed to add these sub categories into the list on VM. however i realised that when i select the image, "Dog" category on my front end of the VM, i see no items. i understand that i see no items because i do not have any items listed under the category "Dog" but instead listed all my items under the subcategories.

Is there a way where i can click the category image and the various pictures for the subcategories (Food, Carrier, Cages) for that category (Dog) would appear? help! thanks!
Title: Re: Displaying all products under sub-categories too
Post by: webcalida on July 30, 2011, 01:15:25 am
Please, someone could help:

My joomla is a 1.5.23 with a Virtuemart 1.1.9

Fatal error: Call to undefined method ps_product_category::untreeCat() in /usr/home/gardenola/www/administrator/components/com_virtuemart/html/shop_browse_queries.php on line 83


Helo again, I change this to VM 1.1.3 and Joomla 1.5.8
In administrator/components/com_virtuemart/classes/ps_product_category.php
add the "untreeCat" function at the end of the class, thanx haselnuss

Code: [Select]
/*
* Returns an array of the categories ids recursively for a given category
* untreeCat copy lashae (virtuemart forum http://virtuemart.net/index.php?option=com_smf&Itemid=71&topic=20837.0)
* @param int $kat
* @param int $container
* rewritten by haselnuss (to use ps_DB class and store the function in ps_product_category.php)
*/
function untreeCat($kat, &$container) {
$db = new ps_DB;
$q = "SELECT category_child_id FROM #__{vm}_category_xref WHERE category_parent_id='$kat'";
$db->query($q);
// if it is a leaf (no data underneath it) then return
if (!$db->num_rows()) {
return;
}
//else append the result, and recurse the function (so to speak)
else
{
while($db->next_record()) {
  $container[] = $db->f("category_child_id");
  $kat = $db->f("category_child_id");
  $this->untreeCat($kat, $container);
}
}
}

and in administrator/components/com_virtuemart/html/shop_browse_queries.php I add detect list categories page. I dont know, why can't detect untree function on product details page.
About line 63 change:

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;
}
}

to:

Code: [Select]
// Filter Products by Category
/*
* Returns an array of the categories ids recursively for a given category
* untreeCat copy lashae (virtuemart forum http://virtuemart.net/index.php?option=com_smf&Itemid=71&topic=20837.0)
* rewritten by Creb (to use shop.browse page detection)
*/
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 )) {

if ($_GET["page"]=="shop.browse") {
  //$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
$kategoriListesi = array();
$ps_product_category->untreeCat($category_id, $kategoriListesi);
$qkat = " `#__{vm}_product_category_xref`.`category_id` IN(".$category_id . ",";
foreach ($kategoriListesi as $kat)
{
$qkat .= $kat . ',';
}
$qkat .= ")";

$qkat = str_replace(',)', ')', $qkat);
$where_clause[] = $qkat;
} else {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
}

}
}

If we need hide category thumbnails comment line 106 in administrator/components/com_virtuemart/html/shop.browse.php

Code: [Select]
//$navigation_childlist = $tpl->fetch( 'common/categoryChildlist.tpl.php');
Hope this helps someone.

regards
Creb
Title: Victory!
Post by: Kalen on August 02, 2011, 17:47:52 pm
Creb!

This works great! ;D

I have a large category structure (>275 categories) with 25,000+ products and a very deep category structure.  On the main VM tree, I can now drill down through all the children/grandchildren and display the complete contents of a category.  The Advance search option, which i have hacked to the main vm Page, now can select a top level category and limit a search to that category and all children/grandchildren!!! This is awsome!  I also have hacked the filter options where the categories are displayed and forced the current selected category to be the default selected option.  This allows the user to immediatly enter search terms and search the products that they are seeing rather than having to select the category that they are presently viewing.  With over 275 categories this is very convenient.  If anyone is interested I can post the mod_virtuemart.php hacks that allow easier searching of the now modified category display structure.  Just let me know.

Thanks again!
Title: Re: Displaying all products under sub-categories too
Post by: relco on August 13, 2011, 18:30:54 pm
Any mods for this to work with Virtuemart 1.1.9?

I can display all products from subcategories, but the Category/SubCategory Title will not show..  I need to show each title as a heading so people know under which category the products they see listed are from.

Any help, much appreciated.
Title: Re: Displaying all products under sub-categories too
Post by: Acardenes on August 25, 2011, 11:01:32 am
Hi it doesn't work in Joomla Version 1.5.22 with VirtueMart 1.1.8 stable.

I modified it as in Creb's post but all I get in my categories page is a blank page.

Anyone knows a solution for this?

Thanks
Title: Re: Displaying all products under sub-categories too
Post by: funboy on August 26, 2011, 15:30:58 pm
Hi all, i'm new here, but i think we will hear us a lot ... virtuemart is realy complicated for me :D

then, I've the same problem using crab code on VM 1.1.8  JOOMLA 1.5.23 ( Blank Screen on category click ) - hompage: http://www.bisped.net 5000 article - up to 6 levels sub category. realy need this function, by this hack or somthing elese.

For help to solve this problem i've attached the shop_browse_queries.php of the VM 1.1.8, can Crab inject the code in the correct way, and re-upload ? becouse i'm not sure of doit in the right way.

Some one with some php knowledge will help us ?

or... I know that a product should be imported in more then one category too, to be shown correctly, but when i import database via CSV i use the 'Category_path'  switch then i cant import the producti in master category also.

some one know here is a query command i can do in phpmyadmin to add to every product all the category in the category path ?

... then, ty and sorry form my english.

[attachment cleanup by admin]
Title: Re: Displaying all products under sub-categories too
Post by: funboy on September 07, 2011, 08:22:07 am
after 2 week from my last post, i can say i've tried all the hacks published on internet to add this function without success... in some case my site explode, in some other simpy nothing append. There is really no one can help me with this ? do you think a downgrade to a older virtuemart version copatibile with this hack is the best choice ? or it will create a lot of others problem ...

the virtuemart developer team are working on this function or they think it's unusefull ?

tank you all for the reply ;)
Title: Re: Displaying all products under sub-categories too
Post by: vbkun on September 08, 2011, 05:15:09 am
I've got this working on VM 1.1.9 so it should work under 1.1.8 I guess...

I got confess the instructions can be confusing and require a bit of php understand so I'll clearify stuff for funboy:


1) In ps_product_category.php file insert the code from Crab from this page ( http://forum.virtuemart.net/index.php?topic=20837.15 ).
I guess what was confusing was the place. It's right after the function sort_alphabetically ends (in vm 1.1.9 line 1441), but there's something wrapping that function, so, if you look for the function you will see it ends on three }'s, insert it before the last }:

Code: [Select]
function sort_alphabetically( $category_id=0, $level=0 ) {
static $ibg = 0;
.....lots of codes here...
// Traverse the tree down
$this->sort_alphabetically( $db->f('category_child_id'), $level );

$i++;

}
}
Insert Crab's code HERE.
}

2- Edit the shop_browse_queries as Crab described, that part is pretty clear.

Title: Re: Displaying all products under sub-categories too
Post by: funboy on September 08, 2011, 09:13:23 am
following your easy step the code work very well ! I guess you are right, in my first ten try there will be something I miss in positioning of this code hack...

I'm very glad to you for your help... i hope a day i can solve you a problem also, meanwhile:
TANK YOU.
Title: Re: Displaying all products under sub-categories too
Post by: romero on September 16, 2011, 14:47:05 pm
Thank you vbkun  ;D ;D

your post is relay help me because im new in VM and PHP  :P
Title: Re: Displaying all products under sub-categories too
Post by: Acardenes on September 16, 2011, 15:04:42 pm
I managed to install this hack with sucess. Do check your code in an IDE and see if you find any missing characters or similar trouble. (That was my case, did a copy inside VIM and missed a char)

Thanks a million!
Title: Re: Displaying all products under sub-categories too
Post by: werkin on September 30, 2011, 00:46:19 am
Hi,

Thank you for a great patch! What is the easiest way to insert code to limit the number of items that will show on each category page? We have hundreds of products, so I would like a random, limited number of items displayed (maybe 10).

I tried adding an array_rand() in the function -see below, but it did not work. What would be the correct way to do it?
Code: [Select]
function untreeCat($kat, &$container) {
$db = new ps_DB;
$q = "SELECT category_child_id FROM #__{vm}_category_xref WHERE category_parent_id='$kat'";
$db->query($q);
// if it is a leaf (no data underneath it) then return
if (!$db->num_rows()) {
return;
}
//else append the result, and recurse the function (so to speak)
else
{
//added this line - not working!
                        $db = array_rand($db, 10);
     
      while($db->next_record()) {
  $container[] = $db->f("category_child_id");
  $kat = $db->f("category_child_id");
  $this->untreeCat($kat, $container);
}
}
}
}

MODIFIED: I just studied shop_brows_queries.php and see that the functions is really just creating a SELECT statement for the child category ids, is this correct? In light of that, is there any way for me to limit the display to 10 random products (from these categories and sub categories)?


BTW Your Code works great! I did have to look twice at where I placed the code in ps_product_category.php as I did not understand at first that it has to go within the class vm_ps_product_category extends vmAbstractObject { }

Thank You!
Title: Re: Displaying all products under sub-categories too
Post by: kerman on October 20, 2011, 03:20:43 am
If you want to limit the number, in global configuration, set the items per page, to 10. I have it to 20, so I've changed it to 10 and works.
Title: Re: Displaying all products under sub-categories too
Post by: edu.caetano on October 25, 2011, 22:17:02 pm
Hi people.
This post is very good, it work, but don't is exactly what I want.

In my virtuemart I've it divided like this order:
What I want to do, it's put a link to a new page to show all products of category "2.1 RegionOne" (Magnets, and Decorative Plates). It is possible?

I hope you can help me, I wait for this and I would be very grateful.
Thanks,
   edu.caetano
Title: Re: Displaying all products under sub-categories too
Post by: xtr3m3 on October 25, 2011, 23:57:19 pm
Hi for all!

Thi is a great code working fine in 1.5.23 and 1.1.6 THX.
But i have a question. In my browse page was sorted the products by latest DESC (product_id). After instering this code modifyed to latest ASC. I modifyd in administrator/components/com_virtuemart/html/product.product_list.php and product.product_list.php but nothing changing.
Now the product.product_list.php :

/** Changed search by date - End */
else {
   $list  = "SELECT * FROM #__{vm}_product WHERE ";
   $count = "SELECT COUNT(*) as num_rows FROM #__{vm}_product WHERE ";
   $q = "product_parent_id='0' ";
   if (!$perm->check("admin")) {
      $q  .= "AND #__{vm}_product.vendor_id = '$ps_vendor_id' ";
   }
   elseif( !empty($vendor) ) {
      $q .=  "AND #__{vm}_product.vendor_id='$vendor' ";
   }
   //$q .= "AND #__{vm}_product.product_id=#__{vm}_product_reviews.product_id ";
   //$q .= "AND #__{vm}_category.category_id=#__{vm}_product_category_xref.category_id ";
   $count .= $q;
   $q .= " ORDER BY product_publish DESC,product_id ";
   //$q .= " ORDER BY product_publish DESC,product_name ";
}
$db->query($count);
$db->next_record();
$num_rows = $db->f("num_rows");

pls help how can sort by latest DESC (The product_id and _sku is same and number increasing) Sorry for my english
THX
Title: Re: Displaying all products under sub-categories too
Post by: luanlun on December 23, 2011, 04:53:58 am
Thank for sharing. Great work.
Khách sạn phú quốc (http://longtk.webchuyennghiep.net/khach-san-phu-quoc)
Title: Re: Displaying all products under sub-categories too
Post by: carbon-uk on January 31, 2012, 10:49:18 am
Got this working, great mod thanks guys,

Anybody know how to put a separator in the results? Preferably the category name.

Thanks again. Works great in 1.1.9
Title: Re: Displaying all products under sub-categories too
Post by: ivannk on February 10, 2012, 15:05:12 pm
hello, it is great hack
I have only one problem with hide products. In front page I have hide porducts. How can I solved? 
Title: Re: Displaying all products under sub-categories too
Post by: Alan_Smith on February 22, 2012, 11:17:47 am
There are many types products available in one store and it is necessary to define all products by category. Sometimes, main category requires sub-categories to easily find required product. The given code for sub-category is important to add sub-categories option in the website.
Title: Re: Displaying all products under sub-categories too
Post by: pmkdk on September 07, 2012, 10:18:41 am
Anyone know how to show category titles with this hack/patch?
Title: Re: Displaying all products under sub-categories too
Post by: Mx150 on October 13, 2015, 18:38:55 pm
Has someone a solution for Virtuemart 3?
Title: Re: Displaying all products under sub-categories too
Post by: GJC Web Design on October 13, 2015, 20:12:42 pm
http://forum.virtuemart.net/index.php?topic=131667.msg454316#msg454316