Display subcategory products, full depth - VM 3.2.2

Started by bcohen0, August 17, 2017, 22:24:02 PM

Previous topic - Next topic

Milbo

no, I asked for clearification and thanked for the answer.

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

#16
Quote from: Milbo on August 18, 2017, 10:27:38 AM
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.

Quote from: Milbo on August 19, 2017, 08:43:04 AMDid you test?

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

Quote from: Milbo on August 20, 2017, 08:14:56 AMehrm, 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.

Quote from: Milbo on August 24, 2017, 20:17:59 PMAnd 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!

Quote from: Milbo on August 24, 2017, 20:17:59 PM
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

#17
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:
    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:
         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

Quote from: Rune Rasmussen on August 24, 2017, 20:52:30 PM
Quote from: Milbo on August 18, 2017, 10:27:38 AM
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.

Quote from: Rune Rasmussen on August 24, 2017, 20:52:30 PM
Quote from: Milbo on August 19, 2017, 08:43:04 AMDid 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.

Quote from: Rune Rasmussen on August 24, 2017, 20:52:30 PM
Quote from: Milbo on August 20, 2017, 08:14:56 AMehrm, 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.

Quote from: Rune Rasmussen on August 24, 2017, 20:52:30 PM
Quote from: Milbo on August 24, 2017, 20:17:59 PMAnd 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!)

Quote from: Rune Rasmussen on August 24, 2017, 20:52:30 PM
Quote from: Milbo on August 24, 2017, 20:17:59 PM
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.

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

Quote from: Milbo on August 20, 2017, 00:25:40 AM
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

Quote from: Rune Rasmussen on August 24, 2017, 21:26:07 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

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

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

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

   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

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
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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

Hello,

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

Rune Rasmussen

Quote from: el02154 on November 27, 2020, 15:05:39 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


Rune Rasmussen

Quote from: Rune Rasmussen on November 28, 2020, 15:55:11 PM
Quote from: el02154 on November 27, 2020, 15:05:39 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

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

Norwegian Translation Team

GJC Web Design

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
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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

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

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
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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