Blame view

common/modules/product/widgets/catalogSubmenuWidget.php 977 Bytes
85261b14   Karnovsky A   not fixed commite
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  <?php
  
  namespace common\modules\product\widgets;
  
  use common\modules\product\models\Category;
  use yii\base\Widget;
  
  class catalogSubmenuWidget extends Widget {
      public $root_id;
      public $rootClass = '';
  
      public function init()
      {
          parent::init(); // TODO: Change the autogenerated stub
      }
  
      public function run() {
14eadb86   Karnovsky A   Eager loading for...
18
          /** @var Category $rootCategory */
85261b14   Karnovsky A   not fixed commite
19
          $rootCategory = Category::findOne($this->root_id);
14eadb86   Karnovsky A   Eager loading for...
20
21
22
23
24
25
26
27
28
  
          $categories = $rootCategory->getAllChildren(2, [], 'categoryName')->all();
          $populary = [];
          foreach($categories as $category) {
              if ($category->populary) {
                  $populary[] = $category;
              }
          }
  
85261b14   Karnovsky A   not fixed commite
29
30
31
          return $this->render('submenu', [
              'rootCategory' => $rootCategory,
              'rootClass' => $this->rootClass,
14eadb86   Karnovsky A   Eager loading for...
32
33
              'populary' => $populary,
              'items' => $rootCategory->buildTree($categories, $rootCategory->category_id)
85261b14   Karnovsky A   not fixed commite
34
35
36
          ]);
      }
  }