Author Topic: Display all products under the sub-categories of the current category too VM2  (Read 55355 times)

vanaveno

  • Beginner
  • *
  • Posts: 10
  • vanaveno
    • Fotoblog Vanaveno
I need to display all products under the sub-categories of the current category too.
Example: Category tree is:
main-category1 (show all of products)
   -subcategory1 (only products subcategory -1)
   -subcategory2 (only products subcategory -2)
....
Now I get only menu of subcategories I not see products. Is it possible to change this I want to see products not menu subcategory.
I thing there is similar solution of this problem, but it is at VM 1.
http://forum.virtuemart.net/index.php?topic=20837.0
But I need it for VM2. Thanks for respond.

gamecat2300

  • Jr. Member
  • **
  • Posts: 52
Hi,

I as well would love a solution for this. I was able to get this to work very well with"
http://extensions.joomla.org/extensions/extension-specific/virtuemart-extensions/virtuemart-navigation/6775

But now that I've moved the site to VM 2 this is no longer an option. Any clues or tips on this?

=-s-=

chillmen

  • Beginner
  • *
  • Posts: 1
Same problem here, if someone could help
Thanks

luke67

  • Beginner
  • *
  • Posts: 11
Same issue here. Nobody a solution for this?  :-\

renevm

  • Beginner
  • *
  • Posts: 7
  • Gouda Webdesign
    • Gouda Webdesign
I don't have a solution either. Anyone????  :-\

mysaq

  • Beginner
  • *
  • Posts: 2
So... I'm PHP beginner... but... this works for me... :)

After the setKeyWord function in \administrator\components\com_virtuemart\models\product.php place:

Code: [Select]
function untreeCat($vm_catid, &$ccont){
   $dbx = JFactory::getDBO();
   $q = 'SELECT `category_child_id` FROM `#__virtuemart_category_categories` WHERE `category_parent_id`="'.$vm_catid.'"';
   $dbx->setQuery($q);
   $dby = $dbx->query();       
   if (!$dby->num_rows) {
      return;
   } else {   
        while($tt = $dby->fetch_row()) {
           array_push($ccont, $tt[0]);
           $kat = $tt[0];
           $this->untreeCat($kat, $ccont);
   }
    }
}

Then search for this:

Code: [Select]
if ($virtuemart_category_id>0){
    $joinCategory = true ;
    $where[] = ' `#__virtuemart_product_categories`.`virtuemart_category_id` = '.$virtuemart_category_id;
}

... and replace it with following:

Code: [Select]
if ($virtuemart_category_id>0){
   $joinCategory = true ;
   $catscont = array();
   $this->untreeCat($virtuemart_category_id, $catscont);
   $qkat = ' `#__virtuemart_product_categories`.`virtuemart_category_id` IN('.$virtuemart_category_id;
    foreach ($catscont as &$kat){
       $qkat .= ', '.$kat;
    }
    $qkat .= ')';
    $where[] = $qkat;
}

EDIT: There was one missing row in the code here. So I replaced the last part by the Piszi's version. (tested and works)

Piszi

  • Jr. Member
  • **
  • Posts: 58
Actually I think you could make your code more compact if you concat your category id-s, than your query will result only one line or nothing.
So you could do a query like this:
Code: [Select]
$query = 'SELECT GROUP_CONCAT(`category_child_id` SEPARATOR ", ") FROM `#__virtuemart_category_categories` WHERE `category_parent_id`="'.$vm_catid.'"';This will return something like this: 1, 2, 3, ...

Oh and your $where[] mod has a syntax error
If you put a comma in the query and you doesn't have a child category than you will get a MySQL error because of that comma.
So you should make your code like this:
Code: [Select]
$catscont = array();
       $this->untreeCat($virtuemart_category_id, $catscont);
       $qkat = ' `#__virtuemart_product_categories`.`virtuemart_category_id` IN('.$virtuemart_category_id;
       foreach ($catscont as &$kat){
           $qkat .= ', '.$kat;
       }
       $qkat .= ')';
       $where[] = $qkat;


Otherwise great work!

mysaq

  • Beginner
  • *
  • Posts: 2
I modified the VM1 version only. The syntax error is caused by one missing row in the code here. ( $qkat = str_replace(',)', ')', $qkat); ) Don't know why it diappeared...  ???

I replaced that part of code by your version. Thanks.

rupesh

  • Jr. Member
  • **
  • Posts: 113

Can you please send me product.php

on my site i'm getting
Notice: Trying to get property of non-object in E:\xampp\htdocs\elifeaftercheckout\administrator\components\com_virtuemart\models\product.php on line 172

its not working :'(
Thank you
Rupesh
Actually I think you could make your code more compact if you concat your category id-s, than your query will result only one line or nothing.
So you could do a query like this:
Code: [Select]
$query = 'SELECT GROUP_CONCAT(`category_child_id` SEPARATOR ", ") FROM `#__virtuemart_category_categories` WHERE `category_parent_id`="'.$vm_catid.'"';This will return something like this: 1, 2, 3, ...

Oh and your $where[] mod has a syntax error
If you put a comma in the query and you doesn't have a child category than you will get a MySQL error because of that comma.
So you should make your code like this:
Code: [Select]
$catscont = array();
       $this->untreeCat($virtuemart_category_id, $catscont);
       $qkat = ' `#__virtuemart_product_categories`.`virtuemart_category_id` IN('.$virtuemart_category_id;
       foreach ($catscont as &$kat){
           $qkat .= ', '.$kat;
       }
       $qkat .= ')';
       $where[] = $qkat;


Otherwise great work!

rupesh

  • Jr. Member
  • **
  • Posts: 113

perlarenee

  • Beginner
  • *
  • Posts: 25
i tried this fix as well and could see now change. I'm in vm 2.8 and joomla 2.5.6.

ThomasR

  • Beginner
  • *
  • Posts: 4
Still looking for this solution.. Does someone have found a way to get this done?

Robert V.

  • Beginner
  • *
  • Posts: 19
Re: Display all products under the sub-categories of the current category too VM2
« Reply #12 on: September 17, 2012, 01:43:52 am »
I need to display all products under the sub-categories of the current category too.
Example: Category tree is:
main-category1 (show all of products)
   -subcategory1 (only products subcategory -1)
   -subcategory2 (only products subcategory -2)
....
Now I get only menu of subcategories I not see products. Is it possible to change this I want to see products not menu subcategory.
I thing there is similar solution of this problem, but it is at VM 1.
http://forum.virtuemart.net/index.php?topic=20837.0
But I need it for VM2. Thanks for respond.

Tested this under joomla 2.5.7 with VM 2.0.10.

Within Joomla if you create a menu item that will show every subcategory with the products choose VirtueMart Categories Layout as a link from that menu
for every subcategory make a submenu item that links to every single category layout.


Hence:  main-category1 (show all of the products) - link this one to VirtueMart Categories Layout -> This will display all the products of all categories.
                -subcategory1 (only products subcategory -1) - Link this one to VirtueMart » Category Layout (subcategory 1)
                -subcategory2 (only products subcategory -2) - Link this one to VirtueMart » Category Layout (subcategory 2)

Now depending on the amount of products you'll get a set of pages (default 10 products per page). Just enhance this number to display more products per page.

hope this helped.
                     

rupesh

  • Jr. Member
  • **
  • Posts: 113
Re: Display all products under the sub-categories of the current category too VM2
« Reply #13 on: September 22, 2012, 04:14:07 am »
I need to display all products under the sub-categories of the current category too.
Example: Category tree is:
main-category1 (show all of products)
   -subcategory1 (only products subcategory -1)
   -subcategory2 (only products subcategory -2)
....
Now I get only menu of subcategories I not see products. Is it possible to change this I want to see products not menu subcategory.
I thing there is similar solution of this problem, but it is at VM 1.
http://forum.virtuemart.net/index.php?topic=20837.0
But I need it for VM2. Thanks for respond.

Tested this under joomla 2.5.7 with VM 2.0.10.

Within Joomla if you create a menu item that will show every subcategory with the products choose VirtueMart Categories Layout as a link from that menu
for every subcategory make a submenu item that links to every single category layout.


Hence:  main-category1 (show all of the products) - link this one to VirtueMart Categories Layout -> This will display all the products of all categories.
                -subcategory1 (only products subcategory -1) - Link this one to VirtueMart » Category Layout (subcategory 1)
                -subcategory2 (only products subcategory -2) - Link this one to VirtueMart » Category Layout (subcategory 2)

Now depending on the amount of products you'll get a set of pages (default 10 products per page). Just enhance this number to display more products per page.

hope this helped.
                     

I know this solution! just ping me i will help you!

Doomas

  • Beginner
  • *
  • Posts: 11
Re: Display all products under the sub-categories of the current category too VM2
« Reply #14 on: September 27, 2012, 04:03:42 am »
So... I'm PHP beginner... but... this works for me... :)

After the setKeyWord function in \administrator\components\com_virtuemart\models\product.php place:

Code: [Select]
function untreeCat($vm_catid, &$ccont){
   $dbx = JFactory::getDBO();
   $q = 'SELECT `category_child_id` FROM `#__virtuemart_category_categories` WHERE `category_parent_id`="'.$vm_catid.'"';
   $dbx->setQuery($q);
   $dby = $dbx->query();       
   if (!$dby->num_rows) {
      return;
   } else {   
        while($tt = $dby->fetch_row()) {
           array_push($ccont, $tt[0]);
           $kat = $tt[0];
           $this->untreeCat($kat, $ccont);
   }
    }
}

Then search for this:

Code: [Select]
if ($virtuemart_category_id>0){
    $joinCategory = true ;
    $where[] = ' `#__virtuemart_product_categories`.`virtuemart_category_id` = '.$virtuemart_category_id;
}

... and replace it with following:

Code: [Select]
if ($virtuemart_category_id>0){
   $joinCategory = true ;
   $catscont = array();
   $this->untreeCat($virtuemart_category_id, $catscont);
   $qkat = ' `#__virtuemart_product_categories`.`virtuemart_category_id` IN('.$virtuemart_category_id;
    foreach ($catscont as &$kat){
       $qkat .= ', '.$kat;
    }
    $qkat .= ')';
    $where[] = $qkat;
}

EDIT: There was one missing row in the code here. So I replaced the last part by the Piszi's version. (tested and works)

Thanks for this solution, i made the following  changes to make this work in Joomla 2.5.7 and Virtumart 2.0.11d. 

Code: [Select]
function untreeCat($vm_catid, &$ccont){
$db = JFactory::getDBO();
$query = 'SELECT `category_child_id` FROM `#__virtuemart_category_categories` WHERE `category_parent_id`="'.$vm_catid.'"';
$db->setQuery($query);
$db->query();

$rows = $db->loadRowList();
if (empty($rows)) {
return;
} else {
foreach($rows as $row) {
array_push($ccont, $row[0]);
$kat = $row[0];
$this->untreeCat($kat, $ccont);
}
}
}

Code: [Select]
if ($virtuemart_category_id > 0){
   $joinCategory = TRUE ;
   $catscont = array();
   $this->untreeCat($virtuemart_category_id, $catscont);
   $qkat = ' `#__virtuemart_product_categories`.`virtuemart_category_id` IN('.$virtuemart_category_id;
    foreach ($catscont as &$kat){
       $qkat .= ', '.$kat;
    }
    $qkat .= ')';
    $where[] = $qkat;
}