Display all products under the sub-categories of the current category too VM2

Started by vanaveno, February 11, 2012, 09:21:41 AM

Previous topic - Next topic

matearts

THANK YOU!! Big help for me! This is worked in Joomla 2.5.7 with VirtueMart 2.

Quote from: Doomas on September 27, 2012, 04:03:42 AM
Quote from: mysaq on June 18, 2012, 23:57:30 PM
So... I'm PHP beginner... but... this works for me... :)

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


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:


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


... and replace it with following:


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. 


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



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


toxedach

great post. And how can I fix this code to show the products not from the child category, and within this category of children categories.
Example directory has http://www.lit-kom.ru/catalog/печи_баные/
there child categories and displayed their findings and their product has child categories.

thank you in advance

capricornio

Great post, the modified product.php works fine for me on J2.5.7 and VM2.0.12b.
Only one downside:
When I'm in the browsepage of a Level A category all products from Level B subcategories are displayed just fine, but the select manufacturer box does not give any values of manufacturers from the subcategory products.
Anyone an idea how to hack this ?

apessoa

Hi

I just saw this thread, maybe you can help me.

I'm setting up a site that has 2 main categories (no products in these) each with subcategories with products. It's a migration from J 1.5 and VM 1.1.19 and I want to keep the underlying logic of categories and "product types"

-) Categories: I want to display the category and subcategories just lik VM does, using the category view. When the user clicks on a subcat, he then sees the corresponding products. This is because we have two main aggregating categories, each with 4+ subcategories and each subcategory with a lot of products.

-) "Product type view": We've moved from product types to custom fields and bought an AJAX filter. So far, so good, when in a subcategory it correctly filters and displays the products according to custom fields. However, I need a view for the products in the subcategories for each of the two main big categories - they are the main aggregators and I want to filter from them.

I followed the steps in this thread and in fact it works, but for the wrong views that I need.
Right now the "category" view displays both subcategories and products from them.

What I need is:

- the "category" view to display just the subcategories when in the main category and the products when in the subcategory - just like the original version.

- And the "categories" view (the one that just displays the subcategories), or some new view, to display the products from subcategories without displaying the category description or its subcategories images.

If anyone can help with some hints....

Thanks in advance and best regards,
Alexandre

MarioP

Hello,
I'm working at J2.5.8 and the newest VM2.0.16. I modified the VM according with the posted solution.
QuoteThanks for this solution, i made the following  changes to make this work in Joomla 2.5.7 and Virtumart 2.0.11d.



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





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

Unfortunately it doesn't work. I'm bad at PHP. I can only state that the code in VM2.0.16 was changed.
Instead of this (Virtumart 2.0.11):
if ($virtuemart_category_id>0){
    $joinCategory = true ;
    $where[] = ' `#__virtuemart_product_categories`.`virtuemart_category_id` = '.$virtuemart_category_id;
}

there is ((Virtumart 2.0.16):

if ($virtuemart_category_id > 0) {
$joinCategory = TRUE;
$where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
}

If someone could help...
Thanks in advance

MarioP

I've tried to do something on one's own. I've changed `#__virtuemart_product_categories` in
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;
}

to  `pc` and it works. Almost works... When it displays product details page, it also displays (at the bottom of the page) all subcategories (images)...
Anybody help?

MarioP

Everybody who want to reach the same results but without manual PHP code modification, you might see the following page:
http://www.kainhofer.com/virtuemart-2-extensions/vm2-auto-categories-plugin.html
Very easy configuration and what is the most important - it works (at least for me...) in Joomla 2.5.8 and Virtumart 2.0.16.

dharmendrarao

Hi,

I am new to virtuemart. I use virtuemart 1.1.x,

Please help me for showing all products on product detail page.

Example: Category tree is:
main-category1 (show all of products)
   -subcategory1 (only products subcategory -1)
        - product 1
        - product 3
        - product 3
   -subcategory2 (only products subcategory -2)

on "product 1" detail page, i want all other products are listed below to "product 1" of "category1"

Help me please

Thanks

jenkinhill

@dharmendrarao VM1.1 is no longer supported.  http://forum.virtuemart.net/index.php?topic=106865.0

There is still a 1.1 section of the forum for those who still have a site with the old versions, so you could try posting there.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

syntalk

Hi All,

This is my first post here and firstly I would like to thank to all who helps on this forum as I found it extremely helpful.

I'm new in Virtuemart and trying to display the products from the category(ies) selected below the category list. I can see the solution presented here is working for some but not for all. My question is has anyone managed to get it working on Joomla! 2.5.8 and Viruemart 2.0.18a?

A bit off-topic question but - is it possible to display subcategories as a list of links (ie. Category1 |  Category2 | Category3 ) no images just text?

I'll appreciate any help.


franci77

Don't know if topic is obsolete, but here is the working code for the latest version of Virtuemart.

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


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


Then search for this:


if ($virtuemart_category_id > 0) {
$joinCategory = TRUE;
$where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
}


... and replace it with following:


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


Best regards,
franci77

MasterDKLB

Thank you franci,

This worked like a charm, i need a little bit change to be exactly what i want.

Is there a way to do the same but instead of talking about subcategory products, i would like to display all products inside each category in the main Categories view.

I try to explain it in a different way, now we display the subcategories product inside the category view. Can i display categories products in the categories view?

Is it possible to do that ? what should i change and in which file then?


master_dk

Okay, at least is there a way to Display the Subcategory name, now i get displayed all the products but i would like to have the subcategory name displayed before its products. For example:

Category 1

  Products of category 1

  Subcategory 1

     Products of subcategory 1

etc.

Anyone have a clue which code i have to change?

franci77

Hi MasterDKLB,

I understand what you need, tried to do it, but I couldn't figure it out.
I am quite a beginner in PHP, maybe someone with more experience will hopefully help you out.


Regards,
franci77

jhoompk

Thank you franci77 for your help, it works for me like a charm.

Thanks again