Commit 55371b6cb506f378abeb5c255b3fb2cbaea09027
1 parent
391c98b4
-Get all children fix
Showing
4 changed files
with
18 additions
and
6 deletions
Show diff stats
common/components/artboxtree/ArtboxTreeBehavior.php
| @@ -7,6 +7,7 @@ use yii\base\Exception; | @@ -7,6 +7,7 @@ use yii\base\Exception; | ||
| 7 | use yii\base\NotSupportedException; | 7 | use yii\base\NotSupportedException; |
| 8 | use yii\db\ActiveRecord; | 8 | use yii\db\ActiveRecord; |
| 9 | use yii\db\Expression; | 9 | use yii\db\Expression; |
| 10 | +use yii\helpers\VarDumper; | ||
| 10 | 11 | ||
| 11 | class ArtboxTreeBehavior extends Behavior { | 12 | class ArtboxTreeBehavior extends Behavior { |
| 12 | 13 |
common/modules/product/models/Category.php
| @@ -297,9 +297,21 @@ class Category extends \yii\db\ActiveRecord | @@ -297,9 +297,21 @@ class Category extends \yii\db\ActiveRecord | ||
| 297 | 297 | ||
| 298 | public function getChildrenByDepth($depth) | 298 | public function getChildrenByDepth($depth) |
| 299 | { | 299 | { |
| 300 | - return $this->getAllChildren($depth)->where([ | ||
| 301 | - 'depth' => $depth, | ||
| 302 | - ])->asArray()->select(['category_id']); | 300 | +// VarDumper::dump($this->getAllChildren($depth) |
| 301 | +// | ||
| 302 | +// ->where([ | ||
| 303 | +// 'depth' => $depth, | ||
| 304 | +// 'parent_id' => $this->getChildrenAL() | ||
| 305 | +// ])->asArray()->select(['category_id'])->createCommand()->rawSql, 10, true); | ||
| 306 | +// | ||
| 307 | + | ||
| 308 | + | ||
| 309 | + return $this->getAllChildren($depth) | ||
| 310 | + | ||
| 311 | + ->where([ | ||
| 312 | + 'depth' => $depth, | ||
| 313 | + 'parent_id' => $this->getChildrenAL()->select('category_id')->column() | ||
| 314 | + ])->asArray()->select(['category_id']); | ||
| 303 | } | 315 | } |
| 304 | 316 | ||
| 305 | public function setTaxGroup($value) | 317 | public function setTaxGroup($value) |
frontend/controllers/CatalogController.php
| @@ -141,7 +141,6 @@ class CatalogController extends \yii\web\Controller | @@ -141,7 +141,6 @@ class CatalogController extends \yii\web\Controller | ||
| 141 | ], | 141 | ], |
| 142 | ]); | 142 | ]); |
| 143 | 143 | ||
| 144 | - | ||
| 145 | $products = Product::find()->joinWith('categories') | 144 | $products = Product::find()->joinWith('categories') |
| 146 | ->where([ | 145 | ->where([ |
| 147 | 'category.category_id' => $category->getChildrenByDepth(2)->column(), | 146 | 'category.category_id' => $category->getChildrenByDepth(2)->column(), |
frontend/views/layouts/main.php
| @@ -86,8 +86,8 @@ $brands = Category::find() | @@ -86,8 +86,8 @@ $brands = Category::find() | ||
| 86 | </div> | 86 | </div> |
| 87 | </li> | 87 | </li> |
| 88 | <li><a href="<?php echo Url::to([ | 88 | <li><a href="<?php echo Url::to([ |
| 89 | - 'product/index', | ||
| 90 | - 'id' => 19, | 89 | + 'catalog/category', |
| 90 | + 'category' => 'brendy-oboev', | ||
| 91 | ]); ?>">Обои</a></li> | 91 | ]); ?>">Обои</a></li> |
| 92 | <li><a href=" <?= Url::to(['catalog/category','category' => 'brendy-tekstilya']) ?>">Текстиль</a></li> | 92 | <li><a href=" <?= Url::to(['catalog/category','category' => 'brendy-tekstilya']) ?>">Текстиль</a></li> |
| 93 | <?php foreach ($main_menu as $page) { ?> | 93 | <?php foreach ($main_menu as $page) { ?> |