Commit 599302f3475f5ba48eaf5cfdb921792018f1cbfb

Authored by Alexey Boroda
1 parent 66510176

-Made sort by brand

backend/views/brand/_form.php
... ... @@ -84,6 +84,8 @@
84 84  
85 85 <?= $form->field($model, 'in_menu')
86 86 ->checkbox() ?>
  87 +
  88 + <?= $form->field($model, 'sort') ?>
87 89  
88 90 <div class="form-group">
89 91 <?= Html::submitButton(
... ...
common/modules/product/models/Brand.php
... ... @@ -19,6 +19,7 @@
19 19 * @property string $seo_text
20 20 * @property string $name
21 21 * @property string $description
  22 + * @property integer $sort
22 23 * @property Product[] $products
23 24 */
24 25 class Brand extends ActiveRecord
... ... @@ -74,7 +75,10 @@
74 75 'string',
75 76 ],
76 77 [
77   - [ 'brand_name_id' ],
  78 + [
  79 + 'brand_name_id',
  80 + 'sort',
  81 + ],
78 82 'integer',
79 83 ],
80 84 [
... ... @@ -139,6 +143,7 @@
139 143 'seo_text' => Yii::t('product', 'Seo Text'),
140 144 'in_menu' => Yii::t('product', 'Выводить в меню'),
141 145 'description' => Yii::t('product', 'Описание'),
  146 + 'sort' => Yii::t('product', 'Порядок'),
142 147 ];
143 148 }
144 149  
... ... @@ -152,12 +157,12 @@
152 157  
153 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 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 119 );
120 120  
121 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 126 ProductHelper::_setQueryParams($query, $params);
124 127 if ($in_stock) {
125 128 $query->andWhere(
... ...