Commit a96895442e2227093989f5bac09709848d133f4a

Authored by Alexey Boroda
1 parent 886cf4d7

-Sort in categories

backend/views/category/_form.php
@@ -69,6 +69,8 @@ use kartik\select2\Select2; @@ -69,6 +69,8 @@ use kartik\select2\Select2;
69 69
70 <?= $form->field($model, 'h1')->textInput(['maxlength' => true]) ?> 70 <?= $form->field($model, 'h1')->textInput(['maxlength' => true]) ?>
71 71
  72 + <?= $form->field($model, 'sort') ?>
  73 +
72 <?= $form->field($model, 'seo_text')->widget(CKEditor::className(), 74 <?= $form->field($model, 'seo_text')->widget(CKEditor::className(),
73 [ 75 [
74 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ 76 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[
common/modules/product/models/Category.php
@@ -18,6 +18,7 @@ use common\behaviors\Slug; @@ -18,6 +18,7 @@ use common\behaviors\Slug;
18 * @property integer $category_id 18 * @property integer $category_id
19 * @property string $remote_id 19 * @property string $remote_id
20 * @property integer $parent_id 20 * @property integer $parent_id
  21 + * @property integer $sort
21 * @property string $path 22 * @property string $path
22 * @property integer $depth 23 * @property integer $depth
23 * @property string $image 24 * @property string $image
@@ -76,7 +77,7 @@ class Category extends \yii\db\ActiveRecord @@ -76,7 +77,7 @@ class Category extends \yii\db\ActiveRecord
76 { 77 {
77 return [ 78 return [
78 [['name'], 'string'], 79 [['name'], 'string'],
79 - [['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'], 80 + [['parent_id', 'depth', 'category_name_id', 'product_unit_id', 'sort'], 'integer'],
80 [['path', 'meta_desc', 'h1', 'seo_text'], 'string'], 81 [['path', 'meta_desc', 'h1', 'seo_text'], 'string'],
81 [['meta_title', 'image', 'synonym'], 'string', 'max' => 255], 82 [['meta_title', 'image', 'synonym'], 'string', 'max' => 255],
82 [['meta_robots'], 'string', 'max' => 50], 83 [['meta_robots'], 'string', 'max' => 50],
@@ -110,6 +111,7 @@ class Category extends \yii\db\ActiveRecord @@ -110,6 +111,7 @@ class Category extends \yii\db\ActiveRecord
110 'name' => Yii::t('product', 'Name'), 111 'name' => Yii::t('product', 'Name'),
111 'remote_id' => Yii::t('product', 'Remote ID'), 112 'remote_id' => Yii::t('product', 'Remote ID'),
112 'synonym' => Yii::t('product', 'Синоним'), 113 'synonym' => Yii::t('product', 'Синоним'),
  114 + 'sort' => Yii::t('product', 'Порядок')
113 ]; 115 ];
114 } 116 }
115 117
console/migrations/m170608_122754_add_sort_column_to_category_table.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles adding sort to table `category`.
  7 + */
  8 + class m170608_122754_add_sort_column_to_category_table extends Migration
  9 + {
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->addColumn('category', 'sort', $this->integer());
  16 + }
  17 +
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function down()
  22 + {
  23 + $this->dropColumn('category', 'sort');
  24 + }
  25 + }
frontend/views/layouts/main-menu.php
@@ -4,7 +4,7 @@ use common\modules\product\models\Category; @@ -4,7 +4,7 @@ use common\modules\product\models\Category;
4 use yii\helpers\Html; 4 use yii\helpers\Html;
5 use yii\helpers\Url; 5 use yii\helpers\Url;
6 6
7 -$models = Category::find()->all(); 7 +$models = Category::find()->orderBy(['sort' => SORT_ASC])->all();
8 8
9 9
10 ?> 10 ?>