Author Topic: Display subcategory products, full depth - VM 3.2.2  (Read 837 times)

bcohen0

  • Beginner
  • *
  • Posts: 33
Display subcategory products, full depth - VM 3.2.2
« on: August 17, 2017, 22:24:02 pm »
Here is what I did for my own website to get a full depth display of just products, under a given category. Would this be useful to incorporate in Virtuemart somehow? I hate having mods to a core file.

in administrator/components/com_virtuemart/models/product.php

On or around line 398, where it checks the config value for show_subcat_products, I call my own function in my own class called UserFunctions to do the recursion.

      if ($virtuemart_category_id > 0) {
         $joinCategory = TRUE;
         if(VmConfig::get('show_subcat_products',false)){
            $cats = $virtuemart_category_id;
            UserFunctions::categoryFlatList($cats, $virtuemart_category_id);
            $this->filter_order = "";
            $orderBy="";

            /*GJC add subcat products*/
            /* replaced for full depth search, BC

            $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 {
            $where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
         }




Then in Helpers I put my own class UserFunctions:

class UserFunctions {

   /**
    * Contructor
    */
   public function __construct () {

   }



   static public function categoryFlatList(&$cats, $category_id)
   {
      $catmodel  = VmModel::getModel('category');
      $childcats = $catmodel->getChildCategoryList(1, $category_id, null, null, true);
      foreach ($childcats as $childcat)
      {
         $cats .= ',' . $childcat->virtuemart_category_id;
         self::categoryFlatList($cats, $childcat->virtuemart_category_id);
      }
   }


}



Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9415
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth
« Reply #1 on: August 18, 2017, 10:27:38 am »

         if(VmConfig::get('show_subcat_products',false)){


Thank you for sharing. Seemed to be a lot of work. But when you check the code, you see this config line. It is at the moment a hidden config and enables exactly the behaviour you want, imho. And written with one sql. https://docs.virtuemart.net/manual/general-concepts/206-hidden-configurations.html
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bcohen0

  • Beginner
  • *
  • Posts: 33
Re: Display subcategory products, full depth
« Reply #2 on: August 19, 2017, 03:10:04 am »
No, I don't think it does the same thing. Unless the code behind it has changed, it only descends one level I think.  I have a few more levels deep than that.  I had to enable the hidden config in order to get this block of code to execute for my modification, as well. Am I wrong?  If it WILL do this, I'll certainly use it.

I actually didn't think it was alot of work. The essence is changing

  $childcats = $catmodel->getChildCategoryList(1, $virtuemart_category_id,null, null, true);

to this:

   UserFunctions::categoryFlatList($cats, $virtuemart_category_id);


And making the recursion function.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9415
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth
« Reply #3 on: August 19, 2017, 08:43:04 am »
It is a lot more work, than just setting an hidden config. Furthermore, it is our style to reuse functions and the recursion already exists.

"Unless the code behind it has changed, it only descends one level I think."
Did you test?
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bcohen0

  • Beginner
  • *
  • Posts: 33
Re: Display subcategory products, full depth
« Reply #4 on: August 19, 2017, 22:12:08 pm »
Yes. You'll notice that I would have had to set that config in order to even get the code I wrote to work. That was the first thing I did, because it did seem obvious that just changing the config would work.  My actual experience was that it only descended to a single level of children. IE; if the category had a category, it would descend into that category and get its children, but if there were deeper levels of categories it didn't descend.

It seems that what you are saying is that this code should have descended full depth- IS that what you are saying?  If so, then I may simply have encountered a condition under which it failed to do so.

Please tell me specifically, if you believe the code that is already here should do full depth, because then I will attempt to reproduce the problem for you. That might be more useful.


Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9415
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth
« Reply #5 on: August 20, 2017, 00:25:40 am »
Good, nice. We had often people in the forum, directly writing something which already existed. But I wonder that there no function already exists in the category model. We could extend the hidden config.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bcohen0

  • Beginner
  • *
  • Posts: 33
Re: Display subcategory products, full depth
« Reply #6 on: August 20, 2017, 03:46:29 am »
I have re-verified my initial results - on the original code, I get the following list of categories:

17,25,26,27,28,29,43,44

And on the recursive function, I will get the following list of categories:

17,25,26,27,45,46,47,48,49,50,51,52,53,28,29,43,44


The first result is only the first descent level of categories.  The second result is all categories in a depth first search underneath the user-selected category.

I am using VirtueMart 3.2.2

I don't really care if my own method of accomplishing this full depth search is used. I'm certain the virtuemart team can do it better. I'll use whatever the virtuemart team thinks is best, but for my client I needed a full depth return of all products.


Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9415
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #7 on: August 20, 2017, 08:14:56 am »
ehrm, you should care, because we could add it as hidden option, so you have no problem updating.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 157
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #8 on: August 24, 2017, 16:14:06 pm »
It's true that not all sub category products is displayed using the core code/setting.

T.ex. if you have this structure bellow, it's only products from the first (alphabetically sorted) sub category being displayed in VM 3.2.2:

First category (level one)
 - Sub category 1 (level 2)
 - Sub category 2 (level 2)
 - Sub category 3 (level 2)


PS! Mentioned before here: http://forum.virtuemart.net/index.php?topic=131667.msg466962#msg466962
And also here: http://forum.virtuemart.net/index.php?topic=131667.msg479994#msg479994
Rune Rasmussen - http://www.syntaxerror.no
Norske nettløsninger og integrasjoner, CONSIGNOR EDI, Mamut ordreimport og produkteksport, kortbetaling og faktura m.m.

Norsk Joomla! - Norwegian Translation Team - http://www.norskjoomla.no

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9415
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #9 on: August 24, 2017, 17:04:55 pm »
Rune, this is known, there is an hidden config, which loads the first LEVEL !

Please read again
"Unless the code behind it has changed, it only descends one level I think."
Did you test?

So we talk about another option "load all children, of all levels"
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 157
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #10 on: August 24, 2017, 18:12:38 pm »
Hm, nice reply.

First level in first sub category only then, it doesn't even load all on first level ...

Anyhow as it is, it doesn't make much sense, when there is other solutions doing what people expect this setting to do, and I don't think they read all the forum to try to find a «hidden» comment about it. So sorry if we don't get the logic in this ...
Rune Rasmussen - http://www.syntaxerror.no
Norske nettløsninger og integrasjoner, CONSIGNOR EDI, Mamut ordreimport og produkteksport, kortbetaling og faktura m.m.

Norsk Joomla! - Norwegian Translation Team - http://www.norskjoomla.no

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9415
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #11 on: August 24, 2017, 18:35:22 pm »
lol, useless, you do not read, you do not listen.

The standard was all the time, that we list only the products of the category, not the also the products of the children categories. And this behaviour is sometimes expected and sometimes not.

So GJC added a new function, which was before just enabled by changing one line in the core. That I added a hidden config show_subcat_products is also listed here as new feature http://virtuemart.net/news/latest-news/479-virtuemart-3-2-cached-and-optimized

and here we talk first time about it http://forum.virtuemart.net/index.php?topic=131667.msg454613#msg454613

It was always handled as function, which loads also the products of the childrenchildren categories. So when it does not, it just means some want
- to load only the products of the selected category
- to load the products of the selected and one level down
- to load the products of the selected and all levels down

or GJC and the others want the also all products. When things seem easy, take more fantasy and you get the real problem ;-)
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 157
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #12 on: August 24, 2017, 18:48:13 pm »
Same can be said about you Max, so thanks for reminding us why people don't bother or care. Don't know why you have to be like that when you don't understand other peoples opinion, or are able to read and understand what is written.

You remember that the setting isn't hidden anymore right?
http://dev.virtuemart.net/projects/virtuemart/repository/entry/branches/com_virtuemart.3.0.12.4/administrator/components/com_virtuemart/models/product.php#L426

And you see what the setting actually says to the user?
 - It actually says: "Display all products from all subcategories", so that is what people expect it to do then.

Again, in our tests and on live sites, it ONLY loads products from ONE subcategory (the first), when there is more than one (several first level sub cats). Take a look at the pictures above please. And if this is the behaviour you want to have in VM, consider changing the text on the setting, and also add a help text to it.
Rune Rasmussen - http://www.syntaxerror.no
Norske nettløsninger og integrasjoner, CONSIGNOR EDI, Mamut ordreimport og produkteksport, kortbetaling og faktura m.m.

Norsk Joomla! - Norwegian Translation Team - http://www.norskjoomla.no

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9415
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #13 on: August 24, 2017, 20:17:59 pm »
But I wonder that there no function already exists in the category model. We could extend the hidden config.

You can answer the question yourself. And instead of using the time and implementing it, I am disusssing with you competly nonsense. Because you come here and blame around, instead of constructive work.

While I talk already how to implement it. you do this

It's true that not all sub category products is displayed using the core code/setting.

Why you write this? Did I say that I do not believe bcohen0? So there is no reason to repeat, what he already wrote.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 157
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #14 on: August 24, 2017, 20:21:47 pm »
Yes, you actually did. :)
Rune Rasmussen - http://www.syntaxerror.no
Norske nettløsninger og integrasjoner, CONSIGNOR EDI, Mamut ordreimport og produkteksport, kortbetaling og faktura m.m.

Norsk Joomla! - Norwegian Translation Team - http://www.norskjoomla.no