Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Recommended Posts

Намагаюсь в меню категорій додати третій рівнь квкладення

в файлі контрола додав

if (isset($parts[2])) {
    $data['child_id2'] = $parts[2];
   } else {
    $data['child_id2'] = 0;
   }

і додав код для масиву третьго рівня вкладення те що дипив виділено мітками "//new"

 $data['categories'] = array();
  $categories = $this->model_catalog_category->getCategories(0);
  foreach ($categories as $category) {
   $children_data = array();
   if ($category['category_id'] == $data['category_id']) {
    $children = $this->model_catalog_category->getCategories($category['category_id']);
    foreach($children as $child) {

     //new
       $children_data2 = array();
      if ($child['category_id'] == $data['category_id']) {
       $children2 = $this->model_catalog_category->getCategories($child['category_id']);
       foreach($children2 as $child2) {
        $filter_data2 = array('filter_category_id' => $child2['category_id'], 'filter_sub_category' => true);
        $children_data2[] = array(
         'category_id' => $child2['category_id'],
         'name' => $child2['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data2) . ')' : ''),
         'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $child2['category_id'])
        );
       }
      }
     //new

     $filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
     $children_data[] = array(
      'category_id' => $child['category_id'],
      'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
      'children' => $children_data2, //new
      'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
     );
    }
   }
   $filter_data = array(
    'filter_category_id'  => $category['category_id'],
    'filter_sub_category' => true
   );
   $data['categories'][] = array(
    'category_id' => $category['category_id'],
    'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
    'children'    => $children_data,
    'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
   );
  }

 також вніс зміни до файлу twig

<div class="list-group">
  {% for category in categories %}
     {% if category.category_id == category_id %} 
      <a href="{{ category.href }}" class="list-group-item active">{{ category.name }}</a> 
      {% if category.children %}
        {% for child in category.children %}
          {% if child.category_id == child_id %}
            <a href="{{ child.href }}" class="list-group-item active">&nbsp;&nbsp;&nbsp;- {{ child.name }}</a>

            
            

            {% if child.children %}
              {% for child2 in child.children %}
                {% if child2.category_id == child_id2 %}
                  <a href="{{ child2.href }}" class="list-group-item active">&nbsp;&nbsp;&nbsp;- {{ child2.name }}</a> 
                {% else %} 
                  <a href="{{ child2.href }}" class="list-group-item">&nbsp;&nbsp;&nbsp;- {{ child2.name }}</a>
                {% endif %}
              {% endfor %}
            {% endif %}
             
          

          {% else %} 
            <a href="{{ child.href }}" class="list-group-item">&nbsp;&nbsp;&nbsp;- {{ child.name }}</a>
          {% endif %}
        {% endfor %}
      {% endif %}  
    {% else %}
      <a href="{{ category.href }}" class="list-group-item">{{ category.name }}</a>
    {% endif %}
  {% endfor %}
</div>

Результат: нічого не змінилося. Прошу допомогти знайти помилку. Звісно не безкоштовно. Додатковим плюсом в карму буде відразу адаптувати не у файл category.twig, а menu.twig.

Link to comment
Share on other sites


Навішо ти робиш 
 

if ($category['category_id'] == $data['category_id']) {

А також

if ($child['category_id'] == $data['category_id']) {

це перша помилка. 

також краще скласти у підкатегорії 


 

Link to comment
Share on other sites


$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
	$children_data = array();
	$children = $this->model_catalog_category->getCategories($category['category_id']);
	foreach($children as $child) {
		//new
		$children_data2 = array();
		$children2 = $this->model_catalog_category->getCategories($child['category_id']);
		foreach($children2 as $child2) {
			$filter_data2 = array('filter_category_id' => $child2['category_id'], 'filter_sub_category' => true);
			$children_data2[] = array(
				'category_id' => $child2['category_id'],
				'name' => $child2['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data2) . ')' : ''),
				'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $child2['category_id'])
			);
		}
		
		//new

		$filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
		$children_data[] = array(
			'category_id' => $child['category_id'],
			'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
			'children' => $children_data2, //new
			'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
		);
	}
	
	$filter_data = array(
		'filter_category_id'  => $category['category_id'],
		'filter_sub_category' => true
	);
	$data['categories'][] = array(
		'category_id' => $category['category_id'],
		'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
		'children'    => $children_data,
		'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
	);
}

 

Ну и вывод тоже пересмотрите 

 

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
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.