News:

Support the VirtueMart project and become a member

Main Menu

Limit of 2 sublevels in mod_categories

Started by soublov, February 17, 2016, 11:28:02 AM

Previous topic - Next topic

soublov

Hello,

I read a lot of articles about this subject these last days, I tried to install some 3rd party modules but I haven't found a satisfying solution to the problem of the limitation of 2 sublevel-categories in Virtuemart categories module...

Is there a working and efficient solution ?

Thank you very much for your answer.

Ghost

If you know a little PHP, create a template override and add another foreach loop inside here:

foreach ($category->childs as $child) {...}

soublov

Thanks for your answer but if I just planned to code a solution, I wouldn't have asked if one already existed ;-)

The problem with coding a workaround for this issue, is that apparently several people already tried and they all experienced other problems... :
http://forum.virtuemart.net/index.php?topic=96816.0
http://forum.virtuemart.net/index.php?topic=100995.0
...

So I was wondering if anyone had an efficient solution for this very common issue.


Ghost

Which problems are you referring to?

This module is not bad https://www.joomshaper.com/downloads/extension/sp-virtuemart-category-megamenu. Although personally I prefer a customized VM module.

soublov

I'm referring to these problems for example : http://forum.virtuemart.net/index.php?PHPSESSID=j4lepaogrsks02tmflt51jqsl4&topic=96816.msg322575#msg322575
Or to the fact that every thread (that I found) that deals with this issue ends up without any efficient solution...

I took a look at the module that you suggested, but as every other that I tried it doesn't fix the problem for me :
- only 3 levels depth (I need 4)
- not responsive, it breaks my template on smartphone...

I prefer as well a customized VM module than a third party module. But once again if I just planned to code a solution, I wouldn't spend time here to search for a workaround, I would be coding :-)
And regarding all the threads that I found about this problem, I'm not the only one looking for a fix to this issue...

By the way, I don't really get the point of your answers... If you have developped a workaround, why don't you want to share it with the community ? If you want money, I can off course pay you for an efficient solution. I have very few time in the upcoming weeks and i'd rather spend (a reasonnable amount of) dollars than (maybe a lot of) hours, knowing that apparently a lot of people who tried had several issues trying to code a workaround (cf first line of my post)...



soublov

Hello,

I tried to code a solution, but... there is a problem:

In a template override, I added (in the correct loop):

    <?php if ($child->childs) { 
[
opening ul...]
foreach (
$child->childs as $grandchild) {
[
$caturl$cattextli ...]
}
}
?>



It works perfectly for a 3rd level.


Then I tried to add the 4th level (of course "in the loop in the loop"):

    <?php if ($grandchild->childs) { 
[
opening ul...]
foreach (
$grandchild->childs as $ggrandchild) {
[
$caturl$cattextli ...]
}
}
?>



=> Not working for the 4th level :-(

I "print_r" the $grandchild and discovered that they have no "[childs] => Array" in their properties, even if the $grandchild category DO HAVE subcategories... I checked in the [...]virtuemart_category_categories table in the database, the parent/children relationship is correctly stored for the $granchild and $ggrandchild !

Would anyone have any idea of why this workaround works for 3rd level but not for 4th level (why the $grandchild has no "[childs] => Array" even if it HAS children)  ??


Note : regarding this issue : http://forum.virtuemart.net/index.php?topic=96816.msg344766#msg344766

It should maybe rather be done with:

if (in_array( $child->virtuemart_category_id, $parentCategories)) {

Thank you for your help !

Ghost

#6
For 4th level you'd need to add a foreach loop inside mod_virtuemart_category.php as well (create this as a new extension so VM updates don't overwrite it!):

if($level>1){
foreach ($categories as $i => $category) {
$categories[$i]->childs = $categoryModel->getChildCategoryList($vendorId, $category->virtuemart_category_id) ;
// No image used here
//$categoryModel->addImages($category->childs);
//Yehyeh, very cheap done.
if($level>2){
foreach ($categories[$i]->childs as $j => $cat) {
$categories[$i]->childs[$j]->childs = $categoryModel->getChildCategoryList( $vendorId, $cat->virtuemart_category_id );
if($level>3){
foreach ($categories[$i]->childs[$j]->childs as $k => $cat2) {
$categories[$i]->childs[$j]->childs[$k]->childs = $categoryModel->getChildCategoryList( $vendorId, $cat2->virtuemart_category_id );
}
}
}
}
}
}
Of course this is impractical, a recursive function would be better. VM uses category caching by default, but module could still render slowly if you have many categories. You can add module specific cache (see mod_virtuemart_product for example) to help with performance.

There's also this module http://extensions.joomla.org/extension/openglobal-categories-menu-for-virtuemart

soublov


balai