Commit 599302f3475f5ba48eaf5cfdb921792018f1cbfb
1 parent
66510176
-Made sort by brand
Showing
4 changed files
with
39 additions
and
4 deletions
Show diff stats
backend/views/brand/_form.php
| @@ -84,6 +84,8 @@ | @@ -84,6 +84,8 @@ | ||
| 84 | 84 | ||
| 85 | <?= $form->field($model, 'in_menu') | 85 | <?= $form->field($model, 'in_menu') |
| 86 | ->checkbox() ?> | 86 | ->checkbox() ?> |
| 87 | + | ||
| 88 | + <?= $form->field($model, 'sort') ?> | ||
| 87 | 89 | ||
| 88 | <div class="form-group"> | 90 | <div class="form-group"> |
| 89 | <?= Html::submitButton( | 91 | <?= Html::submitButton( |
common/modules/product/models/Brand.php
| @@ -19,6 +19,7 @@ | @@ -19,6 +19,7 @@ | ||
| 19 | * @property string $seo_text | 19 | * @property string $seo_text |
| 20 | * @property string $name | 20 | * @property string $name |
| 21 | * @property string $description | 21 | * @property string $description |
| 22 | + * @property integer $sort | ||
| 22 | * @property Product[] $products | 23 | * @property Product[] $products |
| 23 | */ | 24 | */ |
| 24 | class Brand extends ActiveRecord | 25 | class Brand extends ActiveRecord |
| @@ -74,7 +75,10 @@ | @@ -74,7 +75,10 @@ | ||
| 74 | 'string', | 75 | 'string', |
| 75 | ], | 76 | ], |
| 76 | [ | 77 | [ |
| 77 | - [ 'brand_name_id' ], | 78 | + [ |
| 79 | + 'brand_name_id', | ||
| 80 | + 'sort', | ||
| 81 | + ], | ||
| 78 | 'integer', | 82 | 'integer', |
| 79 | ], | 83 | ], |
| 80 | [ | 84 | [ |
| @@ -139,6 +143,7 @@ | @@ -139,6 +143,7 @@ | ||
| 139 | 'seo_text' => Yii::t('product', 'Seo Text'), | 143 | 'seo_text' => Yii::t('product', 'Seo Text'), |
| 140 | 'in_menu' => Yii::t('product', 'Выводить в меню'), | 144 | 'in_menu' => Yii::t('product', 'Выводить в меню'), |
| 141 | 'description' => Yii::t('product', 'Описание'), | 145 | 'description' => Yii::t('product', 'Описание'), |
| 146 | + 'sort' => Yii::t('product', 'Порядок'), | ||
| 142 | ]; | 147 | ]; |
| 143 | } | 148 | } |
| 144 | 149 | ||
| @@ -152,12 +157,12 @@ | @@ -152,12 +157,12 @@ | ||
| 152 | 157 | ||
| 153 | public function getImageFile() | 158 | public function getImageFile() |
| 154 | { | 159 | { |
| 155 | - return empty($this->image) ? NULL : '/storage/brands/' . $this->image; | 160 | + return empty($this->image) ? null : '/storage/brands/' . $this->image; |
| 156 | } | 161 | } |
| 157 | 162 | ||
| 158 | public function getImageUrl() | 163 | public function getImageUrl() |
| 159 | { | 164 | { |
| 160 | - return empty($this->image) ? NULL : '/storage/brands/' . $this->image; | 165 | + return empty($this->image) ? null : '/storage/brands/' . $this->image; |
| 161 | } | 166 | } |
| 162 | 167 | ||
| 163 | } | 168 | } |
console/migrations/m170612_153331_add_sort_column_to_brand_table.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use yii\db\Migration; | ||
| 4 | + | ||
| 5 | + /** | ||
| 6 | + * Handles adding sort to table `brand`. | ||
| 7 | + */ | ||
| 8 | + class m170612_153331_add_sort_column_to_brand_table extends Migration | ||
| 9 | + { | ||
| 10 | + /** | ||
| 11 | + * @inheritdoc | ||
| 12 | + */ | ||
| 13 | + public function up() | ||
| 14 | + { | ||
| 15 | + $this->addColumn('brand', 'sort', $this->integer()); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * @inheritdoc | ||
| 20 | + */ | ||
| 21 | + public function down() | ||
| 22 | + { | ||
| 23 | + $this->dropColumn('brand', 'sort'); | ||
| 24 | + } | ||
| 25 | + } |
frontend/models/ProductFrontendSearch.php
| @@ -119,7 +119,10 @@ | @@ -119,7 +119,10 @@ | ||
| 119 | ); | 119 | ); |
| 120 | 120 | ||
| 121 | // $query->groupBy(['product.product_id', 'product_variant.price', 'product_variant.stock']); | 121 | // $query->groupBy(['product.product_id', 'product_variant.price', 'product_variant.stock']); |
| 122 | - $query->orderBy([ 'product_variant.stock' => SORT_DESC ]); | 122 | + $query->orderBy([ |
| 123 | + 'brand.sort' => SORT_ASC, | ||
| 124 | + 'product_variant.stock' => SORT_DESC, | ||
| 125 | + ]); | ||
| 123 | ProductHelper::_setQueryParams($query, $params); | 126 | ProductHelper::_setQueryParams($query, $params); |
| 124 | if ($in_stock) { | 127 | if ($in_stock) { |
| 125 | $query->andWhere( | 128 | $query->andWhere( |