Author Topic: Shows all products from subcategories in parent categories too  (Read 4850 times)

valekichia

  • Beginner
  • *
  • Posts: 26
Re: Shows all products from subcategories in parent categories too
« Reply #15 on: December 13, 2016, 14:11:33 pm »
@Studio 42 Thank you for the explanation!

Yesterday I felt I was missing something because, even though I had cleared both browser and joomla cache after the change, the module wasn't working properly.
Today I opened it and there it is, working as you and GJC Web Design explained.  :o

May I ask something else related to the categories and subcategories behavior?

This is my current situation:
- I have several main categories, which one has multiple subcategories
- my products are only assigned to subcategories
- I have an extra main category called "Discounted products", to which I assign the products on sale (in addiction to the original subcategory)

Now, when I click on a discounted product (both from VM comp and VM prods mod) it will open under the "Discounted products" category.
I'd prefer it to open under its subcategory instead.
I read in the forum that the "Discounted products" category is a suggested way to gather the products on sale, but maybe there are other solutions.
I think that a "Discounted products" should act like a filter instead of being an actual category.
I don't know if it's clear enough.

Please, could you give me your opinions/suggestions about this?

Thank you as always for your patience!

Abatap

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Shows all products from subcategories in parent categories too
« Reply #16 on: December 15, 2016, 16:12:44 pm »
Hello, everyone. First of all, thank you guys for providing the easiest solution solve this problem. And now I have a small question: Is there a way to make VM category pages show child category products separated by child category titles they belong to?

What I need should look something like this:

Child category title 1
--------------------
Child product | Child product | Child product
...
Child product | Child product | Child product


Child category title 2
--------------------
Child product | Child product | Child product
...
Child product | Child product | Child product

...

Child category title n
--------------------
Child product | Child product | Child product
...
Child product | Child product | Child product

I don't really expect someone here to write out a fully working solution, just give me a hint where to look at in the VM code. I'm not that good with it's architecture at the moment, so a hint would be nice.

Studio 42

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2355
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Shows all products from subcategories in parent categories too
« Reply #17 on: December 15, 2016, 16:44:48 pm »
Abatap,
 for your case the proposed code do not work, because this use a global request for all your shop view and modules.
If you want this, you have to not change the code, but change your layout and get products from child categories only, someone in the forum(perhaps me) sended the code, of you search a little, i think you find it.

Abatap

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Shows all products from subcategories in parent categories too
« Reply #18 on: December 15, 2016, 17:04:33 pm »
Uh, the provided solution solves my problem exactly, it's just that in my exact case it would be a lot nicer if all the child products weren't just glued into a single list but separated in blocks by their respective category name with the category name being displayed on top of each block. I do understand though that the solution for my case might require some non-trivial changes to existing views.

Studio 42

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2355
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Shows all products from subcategories in parent categories too
« Reply #19 on: December 15, 2016, 23:43:43 pm »
Uh, the provided solution solves my problem exactly, it's just that in my exact case it would be a lot nicer if all the child products weren't just glued into a single list but separated in blocks by their respective category name with the category name being displayed on top of each block. I do understand though that the solution for my case might require some non-trivial changes to existing views.
The querie do not check for the sub categories Levels, because it get all subcategories in one query.
If you know a little mysql the query is a IN and this not group the product in the categories correctly.
So the real working solution, is to add each product in the parent categories so you can then us a request by child level category and order all properly. If you want group it.
You can use the proposed code changes but this can be very slower if you have many caetgories, but in all case you need to use a sub query for product in child cateogries.


Abatap

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Shows all products from subcategories in parent categories too
« Reply #20 on: December 16, 2016, 06:22:17 am »
Thanks for all the details.

heslikk

  • Beginner
  • *
  • Posts: 8
  • VirtueMart Version: 3
Re: Shows all products from subcategories in parent categories too
« Reply #21 on: May 29, 2017, 10:30:57 am »
this has been available in VM3 since I think 3.0.9 but it requires a small code change.. I think the intention was to make a config for it

but look around line 370 of  \administrator\components\com_virtuemart\models\product.php


Code: [Select]
if ($virtuemart_category_id > 0) {
$joinCategory = TRUE;
if(true){
$where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
} else {
/*GJC add subcat products*/
$catmodel = VmModel::getModel ('category');
$childcats = $catmodel->getChildCategoryList(1, $virtuemart_category_id,null, null, true);
$cats = $virtuemart_category_id;
foreach($childcats as $childcat){
$cats .= ','.$childcat->virtuemart_category_id;
}
$joinCategory = TRUE;
$where[] = ' `pc`.`virtuemart_category_id` IN ('.$cats.') ';
}
} else

if u change   

if(true){

to

if(false){

then all the products in the parent and subcats will be returned
Everything works, but does not work filter by manufacturer...

heslikk

  • Beginner
  • *
  • Posts: 8
  • VirtueMart Version: 3
Re: Shows all products from subcategories in parent categories too
« Reply #22 on: May 29, 2017, 14:59:08 pm »
There are ideas how to make a working filter by the manufacturers?

Studio 42

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2355
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Shows all products from subcategories in parent categories too
« Reply #23 on: May 29, 2017, 21:30:33 pm »
You can use custom filter pro component or you can develop your own module.
For eg. This use Virtuemart https://ongallery.com/en/themes and a self made filter module.