Jump to content
  • 0

Prestashop 1.7 podświetlanie aktywnej kategorii w module "Łącza drzewa kategorii"


rzusto

Question

Witam.

Od jakiegoś czasu próbuję postawić sklep na Prestashop 1.7 (obecnie używam 1.6),

 

Czy może mi ktoś udzielić wskazówki co zrobić aby moduł "Łącza drzewa kategorii" podświetlał aktywną kategorię?

 

W wersji 1.6 moduł mam włączony po lewej stronie layoutu na każdej stronie dot. kategorii oraz produktu. Bardzo dobrze się to sprawdza pod względem użyteczności, klient ma podgląd w jakiej kategorii się znajduje i może dowolnie przełączać się miedzy kategoriami (w moim asortymencie sklepu jest to bardzo ważne, ponieważ produkty są ze sobą mocno powiązane tematycznie a są w różnych kategoriach).

 

Nie wiedzieć czemu w nowej wersji modułu ograniczono jego funkcjonalność - drzewo kategorii wyświetlane jest bez klasy css "selected" przez co moduł pojawia się statycznie bez podświetlenia i rozwinięcia drzewa kategorii.

 

 

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

do pliku ps_categorytree.php tuż przed:

        return [
            'categories' => $this->getCategories($category),
            'currentCategory' => $category->id,
        ];

w funkcji getWidgetVariables() dodajemy:

$this->smarty->assign(array('currentCategory' => $category, 'currentCategoryId' => $category->id));

a w pliku ps_categorytree.tpl zmieniamy:

<a href="{$node.link}">{$node.name}</a>

na:

<a href="{$node.link}" {if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if}>{$node.name}</a>

oraz

<a class="category-sub-link" href="{$node.link}">{$node.name}</a> 

na

<a {if isset($currentCategoryId) && $node.id == $currentCategoryId} class="category-sub-link selected"{else}class="category-sub-link"{/if} href="{$node.link}">{$node.name}</a>

nie testowane ale powinno działać

Link to comment
Share on other sites

  • 0

Dziękuję za odpowiedź, jednak coś nie działa :)

Dla pewności pokaże zawartość moich plików:

 

ps_categorytree.php:

public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        $category = new Category((int)Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);

        if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) {
            $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id);
            if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 2 && !$category->is_root_category && $category->id_parent) {
                $category = new Category($category->id_parent, $this->context->language->id);
            } elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 3 && !$category->is_root_category && !$category->getSubCategories($category->id, true)) {
                $category = new Category($category->id_parent, $this->context->language->id);
            }
        }
        $this->smarty->assign(array('currentCategory' => $category, 'currentCategoryId' => $category->id));
        return [
            'categories' => $this->getCategories($category),
            'currentCategory' => $category->id,
        ];
    }

ps_categorytree.tpl:

{function name="categories" nodes=[] depth=0}
  {strip}
    {if $nodes|count}
      <ul class="category-sub-menu">
        {foreach from=$nodes item=node}
          <li data-depth="{$depth}">
            {if $depth===0}
              <a href="{$node.link}" {if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if}>{$node.name}</a>
              {if $node.children}
                <div class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}">
                  <i class="material-icons add"></i>
                  <i class="material-icons remove"></i>
                </div>
                <div class="collapse" id="exCollapsingNavbar{$node.id}">
                  {categories nodes=$node.children depth=$depth+1}
                </div>
              {/if}
            {else}
              <a {if isset($currentCategoryId) && $node.id == $currentCategoryId} class="category-sub-link selected"{else}class="category-sub-link"{/if} href="{$node.link}">{$node.name}</a>
              {if $node.children}
                <span class="arrows" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}">
                  <i class="material-icons arrow-right"></i>
                  <i class="material-icons arrow-down"></i>
                </span>
                <div class="collapse" id="exCollapsingNavbar{$node.id}">
                  {categories nodes=$node.children depth=$depth+1}
                </div>
              {/if}
            {/if}
          </li>
        {/foreach}
      </ul>
    {/if}
  {/strip}
{/function}

<div class="block-categories hidden-sm-down">
  <ul class="category-top-menu">
    <li><a class="text-uppercase h6" href="{$categories.link nofilter}">{$categories.name}</a></li>
    <li>{categories nodes=$categories.children}</li>
  </ul>
</div>

Adres testowego sklepu: http://beta.venoshop.de/

 

Podgląd produktu z lewym panelem categorytree:

http://beta.venoshop.de/drahtseil-verzinkt-10mm/9-46-drahtseil-10mm-6x37fc-5-bis-50m.html#/38-lange-5m

Edited by rzusto (see edit history)
Link to comment
Share on other sites

  • 0

Hej,

$category->id to można pobrać bez tej machiny kodu... tylko, że tam siedzi id kategorii głównej, a nie tej z adresu. Trzeba pisać własną metodę czy jest inne rozwiązanie na pobranie właściwego id?

 

Dzięki za wszelkie sugestie :)

 

No dobra, ja poradziłem sobie tak. W pliku ps_categorytree.php nie zrobiłem tak jak kolega wyżej opisał tylko dopisałem trzecią linijkę w return, czyli:

return [
            'categories' => $this->getCategories($category),
            'currentCategory' => $category->id,
            'currentCategoryId' => Tools::getValue('id_category'),
        ];

I reszta tak jak już vekia wyżej opisał :)

 

 

Dalej się z tym męczę. Na podstronach kategorii to działa, ale jak wejdę na produkt to już nie mam tego id skąd pobrać. Pomoże ktoś jak zrobić aby w produkcie podświetlona była kategoria tego produktu?

Edited by panoramix (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...