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

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10544
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #15 on: August 24, 2017, 20:27:48 pm »
no, I asked for clearification and thanked for the answer.

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.
Should I 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: 195
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth
« Reply #16 on: August 24, 2017, 20:52:30 pm »
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.

You didn't read or understand what was written, or/and you didn't look at his code. Else that reply doesn't make any sense.

Did you test?

Here you state that you don't know if it work or not, imho.

ehrm, you should care, because we could add it as hidden option, so you have no problem updating.

Here you misunderstood what he wrote. What he tried to tell you is that you can do it your way, if that is better, if only the function is improved to work as the configuration setting implies. He/We only wants it to work as the config text tells us it should work, if you use his solution or comes up with something else is less important.

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.

First of I didn't see that you intended to do anything about it, only that «we could». Second, I don't see any blaming in this, before you started. Third, so translations isn't constructive work, even if your system wouldn't be so popular without it? Thank you!

Why you write this? Did I say that I do not believe bcohen0? So there is no reason to repeat, what he already wrote.

To confirm there is a issue, because you once again seemed to not understand it, or care about it. There was no "I understand. You are right, it doesn't work as expected, I will look at it" or similar expected replies.

Sorry for caring! Have a nice evening!

PS! Look at this image I'm adding once more, it's not a hidden config anymore:
Rune Rasmussen - https://www.syntaxerror.no/

Norwegian Translation Team

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 195
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #17 on: August 24, 2017, 21:26:07 pm »
Anyhow, I also looked at it while having this nice chat ...

And by adding the new function posted by 'bcohen0' to the category model, in bottom of administrator/components/com_virtuemart/models/category.php:
Code: [Select]
    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);
      }
   }

And then modify the code in the product model (administrator/components/com_virtuemart/models/product.php) to something like:
Code: [Select]
         if (VmConfig::get('show_subcat_products',false) and !VmConfig::get('show_all_subcat_products',false)){
            /*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 (VmConfig::get('show_all_subcat_products',false)) {
            $cats = $virtuemart_category_id;
            VmModel::getModel('category')->categoryFlatList($cats, $virtuemart_category_id);
            $this->filter_order = "";
            $orderBy="";
            $joinCategory = TRUE;
            $where[] = ' `pc`.`virtuemart_category_id` IN ('.$cats.') ';
         } else {
            $where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
         }

It could work for those wanting only first sublevel, and those wanting all sublevels.

Sure it should also be added to the visible config, but that should be doable. And sure the code could be better, this is just a quick working proposal based on the existing code and proposal. ;)
Rune Rasmussen - https://www.syntaxerror.no/

Norwegian Translation Team

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10544
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #18 on: August 24, 2017, 21:36:18 pm »
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.

You didn't read or understand what was written, or/and you didn't look at his code. Else that reply doesn't make any sense.
simple, I just forgot myself, that I added that 6 months ago. Read the feature list for vm3.2 and you can see how much I implemented. I also explained, why I asked for that, because we had often people who started to code, just because they did not find the option to enable the wanted behaviour.

Did you test?

Here you state that you don't know if it work or not, imho.
LoL. There is enough room for questions. Maybe it worked before that way and the function got broken. or we also had this often, also with skilled members, that they did a wrong test. False positiv, and so on.

ehrm, you should care, because we could add it as hidden option, so you have no problem updating.

Here you misunderstood what he wrote. What he tried to tell you is that you can do it your way, if that is better, if only the function is improved to work as the configuration setting implies. He/We only wants it to work as the config text tells us it should work, if you use his solution or comes up with something else is less important.

I understood that. But as mentioned before, a lot people use it that way and I want to ask first if some got used to this behaviour and want it that way. We had this often enough, that we "fix" something and others scream that their misuse of the function got broken. A funny example was preventing "minus costs" for payments, which is used as skonto. So i have to add another option for it.

Furthermore I write the code mainly so I hoped that he got my point with the "Already existing functions in the category model". Hoping that he takes another look, if it can be done with an already existing function.

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.

First of I didn't see that you intended to do anything about it, only that «we could». Second, I don't see any blaming in this, before you started. Third, so translations isn't constructive work, even if your system wouldn't be so popular without it? Thank you!
I expressed clearly, that it is in his interest, that we take the work. But we had also a release going on and it was delayed for too long time, so I just had no time todo it directly.
I told you, what I felt as blaming. Directly repeating that it does not work, while I am already on solving it.
That you did the translation does not give you the right to jump into a thread and play the troll. (be aware, I said "play" not that you are!)

Why you write this? Did I say that I do not believe bcohen0? So there is no reason to repeat, what he already wrote.

To confirm there is a issue, because you once again seemed to not understand it, or care about it. There was no "I understand. You are right, it doesn't work as expected, I will look at it" or similar expected replies.

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.
The "Good, nice" was that.

PS! Look at this image I'm adding once more, it's not a hidden config anymore:
Hehe, yes, thanks for clarification. :-)
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10544
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #19 on: August 24, 2017, 21:39:11 pm »
Anyhow, I also looked at it while having this nice chat ...

.....
Sure it should also be added to the visible config, but that should be doable. And sure the code could be better, this is just a quick working proposal based on the existing code and proposal. ;)

Thank you. Yes, it is almost what I have in mind. I would use the same config value, just as dropdown, because the options exclude each other. And it really looks like, that the function is not already in the category model. I checked that already some hours ago.
Should I 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: 195
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #20 on: August 24, 2017, 21:55:46 pm »
I hardly see how confirming an issue is trolling, but enough about it, thanks for your clarifications on your views. I can live with it.

And yes, I didn't find any existing function to use either. And adding the config as a dropdown sounds like a good idea. Great, thanks.
Rune Rasmussen - https://www.syntaxerror.no/

Norwegian Translation Team

el02154

  • Beginner
  • *
  • Posts: 23
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #21 on: November 26, 2020, 22:47:05 pm »
Sorry for reviving this topic but is there any way to show all children products of all subcategories? I use the option in the backend but I am getting only the first level.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10739
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #22 on: November 26, 2020, 22:58:08 pm »
correct -- that is all it is coded for i.e. one level

but this post explains how to return all children from all subcats

http://forum.virtuemart.net/index.php?topic=138193.msg484777#msg484777

add the function

Code: [Select]
   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);
      }
   }

to the category model

and then alter the product model to

Code: [Select]
if (VmConfig::get('show_subcat_products',false) and !VmConfig::get('show_all_subcat_products',false)){
            /*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 (VmConfig::get('show_all_subcat_products',false)) {
            $cats = $virtuemart_category_id;
            VmModel::getModel('category')->categoryFlatList($cats, $virtuemart_category_id);
            $this->filter_order = "";
            $orderBy="";
            $joinCategory = TRUE;
            $where[] = ' `pc`.`virtuemart_category_id` IN ('.$cats.') ';
         } else {
            $where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
         }

and add in the congig

show_all_subcat_products=1

this has not been tested by me but the author says it works
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

el02154

  • Beginner
  • *
  • Posts: 23
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #23 on: November 27, 2020, 15:05:39 pm »
Hello,

thank you for replying. Unfortunately, I tested but still getting only one level childs.

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 195
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #24 on: November 28, 2020, 15:55:11 pm »
Unfortunately, I tested but still getting only one level childs.

What exactly did you test, step by step? I just tested it myself on latest VM, and it still works for me. :)

Note! In administrator/components/com_virtuemart/models/category.php you should add the code before the last }, not exactly at the bottom. Also remember to add the config for it, as mentioned by GJC - in administrator/components/com_virtuemart/virtuemart.cfg
Rune Rasmussen - https://www.syntaxerror.no/

Norwegian Translation Team

el02154

  • Beginner
  • *
  • Posts: 23
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #25 on: November 28, 2020, 20:47:01 pm »
I test it again with no result,. Check this page:
http://webaholics.gr/ddc2/index.php/el/grafeio-spiti

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 195
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #26 on: November 29, 2020, 11:01:09 am »
Unfortunately, I tested but still getting only one level childs.

What exactly did you test, step by step? I just tested it myself on latest VM, and it still works for me. :)

Note! In administrator/components/com_virtuemart/models/category.php you should add the code before the last }, not exactly at the bottom. Also remember to add the config for it, as mentioned by GJC - in administrator/components/com_virtuemart/virtuemart.cfg

It works for sure if done correctly.
Rune Rasmussen - https://www.syntaxerror.no/

Norwegian Translation Team

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10739
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #27 on: November 29, 2020, 11:41:28 am »
test what u get after

VmModel::getModel('category')->categoryFlatList($cats, $virtuemart_category_id);

print 'Debug Line '.__LINE__.' $cats <pre>'; print_r ($cats); print "</pre><br />\n";
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

el02154

  • Beginner
  • *
  • Posts: 23
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #28 on: November 29, 2020, 17:18:38 pm »
First of all, thanks for helping.

When I put the print commend and leave the php code as is I get nothing.

It seems that this if statement is never executed. Are you sure that the conditions inside if statements on the code provided above are correct?


GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10739
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: Display subcategory products, full depth - VM 3.2.2
« Reply #29 on: November 29, 2020, 19:03:43 pm »
what's the value of your


print 'Debug Line '.__LINE__.' show_all_subcat_products <pre>'; print_r (VmConfig::get('show_all_subcat_products',false)); print "</pre><br />\n";
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation