Jump to content
daYmo

[solved] Blockcategory : display only from level1

Recommended Posts

Hi,

 

Just sharing in case it's usefull ...

 

The actual menu displays alla category from home.

Here is a "fix" (from PS version 1.4) so as to display category tree on the left column only if we are currently browsing a category.

 

This is usefull when having many many categories and sub-cat

 

Let's say :

 

CAT A

- SUB CAT A-1

- SUB CAT A-2

- SUB CAT A-3

CAT B

- SUB CAT B-1

- SUB CAT B-2

- SUB CAT B-2-a

- SUB CAT B-2-b

- SUB CAT B-3

CAT C

- SUB CAT C-1

- SUB CAT C-2

- SUB CAT C-3

[etc.]

 

it won't display on index the category on the left.

If I'm in SUB CAT C-2 the blockcategory will display only :

CAT C

- SUB CAT C-1

- SUB CAT C-2

- SUB CAT C-3

 

if I'm on a product page, product belonging to SUB CAT B-2-a

the menu will look :

CAT B

- SUB CAT B-1

- SUB CAT B-2

- SUB CAT B-2-a

- SUB CAT B-2-b

- SUB CAT B-3

 

fix replace the file /modules/blockcategories/blockcategories.php

 

Bye

blockcategories.zip

  • Like 3

Share this post


Link to post
Share on other sites

Does this work on 1.4.6.2 ? I've uploaded the php file to my test environment - force compile is enabled and caching is disabled. Now i get a blank page if I connect to the shop ...

 

Could anyone help me?

Share this post


Link to post
Share on other sites

I've made some tests now and i ran into a new problem. Since I'm using this blockcategories.php I get a blank page when I click on a featured product on my homepage. Does anyone have the same problem or know how to fix this?

Share this post


Link to post
Share on other sites

Excellent! I tried it on a version 1.4 shop and it works great! But is there a way to update the code for Prestashop version 1.5?

 

Thanks very much and again excellent work!

Share this post


Link to post
Share on other sites

Hi!,

I've the same problem: unfortunately it doesn't work in 1.5.3.1... I tried to edit the code and compare it to the new 1.5 php but with no luck...

 

I was planning to update my site and this is the only modification holding me back from 1.5 :(

Share this post


Link to post
Share on other sites

I tried to implement the provided solution into 1.5.2 but unfortunately it doesn't work. If anyone else has any suggestions it would be great to hear them. Thanks!!

Share this post


Link to post
Share on other sites

How can I implement this funcionality into 1.5.3? I guess this is the part where the magic happens:

// Get the level1 parent category of $main_category :
  $main_category=1;
  if(!isset($cookie->last_visited_category))
  {
   if($id_product!=0)
   {
 $product = new Product($id_product);
 $main_category=(int)($product->id_category_default);
   }
   elseif($id_category!=0)
 $main_category=$id_category;
   else 
 return;
  }
  else
   $main_category=(int)($cookie->last_visited_category);

  $cat=new Category($main_category);
  $parent=$cat->id_parent;
  while($parent!=1)
  {
   $main_category=$parent;
   $cat=new Category($parent);
   $parent=$cat->id_parent;   
  }

  // Add main category to the call to getTree so as to get only the current "main" category and not all root category to the block
  //$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
  $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'),$main_category);

 

What lines need to be adjusted for 1.5.3 to work?

Edited by scott_parker (see edit history)

Share this post


Link to post
Share on other sites

successfully installed on 1.4.8 but I noticed that now a deleted category stopped to redirect to 404 not found page. It seems a that categories stopped to redirect at all. For example if you add a wrong URL for a category it stopped to redirect to the right one (the right ID). do you have any fix for this?

Share this post


Link to post
Share on other sites

I found a solution for 1.5. Edit the file "category-tree-branch.tpl", and change the first line "<li>" tag to this:

<li {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{else}class="hidden"{/if}>

With this, all <li> tags except the current one will have the class "hidden" (keeping the "selected" class for the current one)

But all the child levels of the current one, will have the "hidden" class too, and we only need it for the first level. So in the CSS:

.block ul.tree li.hidden{display:none}

.block ul.tree li ul li.hidden{display:block}

In the module config, we set Max Level to 0 and Dynamic to false.

Share this post


Link to post
Share on other sites

Great work kudeiro!  Could you tell us which CSS the .block code would go in?

 

I edited the category-tree-branch-tpl and the site now only displays the one main category in which you clicked on (which is correct) but it is not showing the sub-categories under that main category.  I must have the wrong CSS file.

 

Thanks very much!

Share this post


Link to post
Share on other sites

it's been a while, any proper fix for 1.5? the css way of doing it is kind of a band-aid fix and doesn't really work exactly right.

 

i'm wanting to show a sub-category tree in blockcategory and nothing else, as shown in this picture -

post-711233-0-93576200-1386877782_thumb.png

Edited by tdc666 (see edit history)

Share this post


Link to post
Share on other sites

Hi,

 

Just sharing in case it's usefull ...

 

The actual menu displays alla category from home.

Here is a "fix" (from PS version 1.4) so as to display category tree on the left column only if we are currently browsing a category.

 

This is usefull when having many many categories and sub-cat

 

Let's say :

 

CAT A

- SUB CAT A-1

- SUB CAT A-2

- SUB CAT A-3

CAT B

- SUB CAT B-1

- SUB CAT B-2

- SUB CAT B-2-a

- SUB CAT B-2-b

- SUB CAT B-3

CAT C

- SUB CAT C-1

- SUB CAT C-2

- SUB CAT C-3

[etc.]

 

it won't display on index the category on the left.

If I'm in SUB CAT C-2 the blockcategory will display only :

CAT C

- SUB CAT C-1

- SUB CAT C-2

- SUB CAT C-3

 

if I'm on a product page, product belonging to SUB CAT B-2-a

the menu will look :

CAT B

- SUB CAT B-1

- SUB CAT B-2

- SUB CAT B-2-a

- SUB CAT B-2-b

- SUB CAT B-3

 

fix replace the file /modules/blockcategories/blockcategories.php

 

Bye

 

 

Ca fonctionne en 1.5 également ?

Est-ce que ça améliore les perfs ? je souhaite cacher toutes les autres catégories lorsque je suis dans la catégorie courant ;)

Share this post


Link to post
Share on other sites

Salut à tous, si ça peut aider je viens de me faire ch... 3 plombs avec ce bout de code haut comme trois pommes. Au cas où vous souhaitez faire la même chose avec une 1.5.6.2 ça fonctionne avec les deux modifs ci dessous listées :

 

Ajouter ce bout de code dans blockcategories.php, juste avant l'appel à la fct gettree (ligne 187) :

            // Get the level1 parent category of $main_category :
            $main_category=1;
            if(!isset($this->context->cookie->last_visited_category))
            {
                if($id_product!=0)
                {
                    $product = new Product($id_product);
                    $main_category=(int)($product->id_category_default);                   
                }
                elseif($id_category!=0)
                    $main_category=$id_category;
                else     
                    return;
            }
            else

               $main_category=(int)Tools::getValue('id_category');
         
            $cat=new Category($main_category);
            $parent=$cat->id_parent;
            while($parent!=1)
            {
                $main_category=$parent;
                $cat=new Category($parent);
                $parent=$cat->id_parent;                
            }  

 

Puis modifier l'appel comme dit un peu plus haut dans ce fil :

   $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'),$main_category);

 

Au cas ou vous souhaitez, comme ça a été le cas pour moi, récupérer le niveau courant de chaque catégorie modifier également le code suivant dans la fonction GetTree

 

   $return = array('id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
   'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
                     'level_depth'=> $resultIds[$id_category]['level_depth'],
                     'children' => $children);

 

Sans oublier de modifier la requete SQL servant d'entrée à la fonction (hook left et footer) :

SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite, c.level_depth

 

 

Si c'est pas clair, n'hésitez pas.

 

Gab.

Edited by Gabriel42 (see edit history)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More