News:

Support the VirtueMart project and become a member

Main Menu

Shows all products from subcategories in parent categories too

Started by mogaka, October 28, 2016, 18:12:14 PM

Previous topic - Next topic

valekichia

@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

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

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

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

Quote from: Abatap 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.
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


heslikk

Quote from: GJC Web Design on December 06, 2016, 19:31:41 PM
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


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

There are ideas how to make a working filter by the manufacturers?

Studio 42

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.

EIF

I am trying to get this to work in Virtuemart 3.8.8 10472.

Displaying all products from the subcategories works, but totally. For example:

Category A
  - Sub A1
       Subsub A11
       Subsub A12
  - Sub A2
  - Sub A3

Category B
Category C

With the current options and conditions, I get it to work when I display Sub a1 category that all items will be displayed there. So all products from subsub A11 and subsub A12 are shown in Sub A1. That works.

But... when I display Category A, I want all products from al the sub categories and the subsub categories (the sub of the sub category). Both in the menu items setting and in the category setting, there is an option to display the products. But it only displays 3 products. It should be hundreds.

What is going wrong?


EDIT: I made a new own topic for this issue --> https://forum.virtuemart.net/index.php?topic=147957.0