Commit 30ea8a3591d8b8666869c49a414e873aa23d640d

Authored by Administrator
1 parent 9173c97b

29.06.16

backend/config/main.php
... ... @@ -152,6 +152,13 @@ return [
152 152 'rules' => [
153 153 'slider-image/<action>/<slider_id:[A-Za-z0-9_-]+>/<id:[A-Za-z0-9_-]+>' => 'slider-image/<action>',
154 154 'slider-image/<action>/<slider_id:[A-Za-z0-9_-]+>' => 'slider-image/<action>',
  155 + 'rubrication/tax-group/<level:[0-9]+>' => 'rubrication/tax-group',
  156 + 'rubrication/tax-group/<action>/<level:[0-9]+>/<id:[A-Za-z0-9_-]+>' => 'rubrication/tax-group/<action>',
  157 + 'rubrication/tax-group/<action>/<level:[0-9]+>' => 'rubrication/tax-group/<action>',
  158 + 'product/manage/<action>' => 'product/manage/<action>',
  159 + 'product/<controller>/<action>/<product_id:[A-Za-z0-9_-]+>/' => 'product/<controller>/<action>',
  160 + 'product/<controller>/<action>/<product_id:[A-Za-z0-9_-]+>/<id:[A-Za-z0-9_-]+>' => 'product/<controller>/<action>',
  161 + 'product/<action>/<product_id:[A-Za-z0-9_-]+>' => 'product/<action>',
155 162 'seo-dynamic/<action>/<seo_category_id:[A-Za-z0-9_-]+>/<id:[A-Za-z0-9_-]+>' => 'seo-dynamic/<action>',
156 163 'seo-dynamic/<action>/<seo_category_id:[A-Za-z0-9_-]+>' => 'seo-dynamic/<action>',
157 164  
... ...
backend/views/layouts/main-sidebar.php
1 1 <?php
  2 +use yii\helpers\Url;
2 3 use yii\widgets\Menu;
3 4 ?>
4 5 <aside class="main-sidebar">
... ... @@ -33,11 +34,11 @@ use yii\widgets\Menu;
33 34 'url' => ['/product/manage'],
34 35 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide']
35 36 ],
36   - [
37   - 'label' => 'Модификации',
38   - 'url' => ['/product/variant'],
39   - 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide']
40   - ],
  37 +// [
  38 +// 'label' => 'Модификации',
  39 +// 'url' => ['/product/variant'],
  40 +// 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide']
  41 +// ],
41 42 [
42 43 'label' => 'Категории',
43 44 'url' => ['/category'],
... ... @@ -65,8 +66,13 @@ use yii\widgets\Menu;
65 66 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'],
66 67 ],
67 68 [
68   - 'label' => 'Характеристики',
69   - 'url' => ['/rubrication/tax-group'],
  69 + 'label' => 'Характеристики Товаров',
  70 + 'url' => Url::toRoute(['/rubrication/tax-group', 'level'=> '0']),
  71 + 'options' => ['class'=>\Yii::$app->user->can('rubrication') ? '' :'hide'],
  72 + ],
  73 + [
  74 + 'label' => 'Характеристики Модификаций',
  75 + 'url' => Url::toRoute(['/rubrication/tax-group', 'level'=> '1']),
70 76 'options' => ['class'=>\Yii::$app->user->can('rubrication') ? '' :'hide'],
71 77 ],
72 78 [
... ...
common/config/main.php
... ... @@ -43,8 +43,8 @@ return [
43 43 'artboximage' => [
44 44 'class' => 'common\components\artboximage\ArtboxImage',
45 45 'driver' => 'GD', //GD or Imagick
46   - 'rootPath' => Yii::getAlias('@frontend/web/images'),
47   - 'rootUrl' => Yii::getAlias('/images'),
  46 + 'rootPath' => Yii::getAlias('@storage'),
  47 + 'rootUrl' => Yii::getAlias('/storage'),
48 48 'presets' => [
49 49 'product' => [
50 50 'resize' => [
... ...
common/modules/product/controllers/VariantController.php
... ... @@ -3,8 +3,9 @@
3 3 namespace common\modules\product\controllers;
4 4  
5 5 use common\modules\product\models\Product;
  6 +use common\modules\product\models\ProductImage;
6 7 use common\modules\product\models\ProductVariant;
7   -use common\modules\product\models\ProductVariantSearch;
  8 +use common\modules\product\models\ProductVariantListSearch;
8 9 use Yii;
9 10 use yii\web\Controller;
10 11 use yii\web\NotFoundHttpException;
... ... @@ -35,10 +36,10 @@ class VariantController extends Controller
35 36 * Lists all ProductVariant models.
36 37 * @return mixed
37 38 */
38   - public function actionIndex()
  39 + public function actionIndex($product_id)
39 40 {
40   - $searchModel = new ProductVariantSearch();
41   - $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  41 + $searchModel = new ProductVariantListSearch();
  42 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams,$product_id);
42 43  
43 44 if ( ($product = Yii::$app->request->get('product_id')) !== null) {
44 45 $product = Product::findOne($product);
... ... @@ -48,6 +49,7 @@ class VariantController extends Controller
48 49 'searchModel' => $searchModel,
49 50 'dataProvider' => $dataProvider,
50 51 'product' => $product,
  52 + 'product_id' => $product_id,
51 53 ]);
52 54 }
53 55  
... ... @@ -68,14 +70,17 @@ class VariantController extends Controller
68 70 * If creation is successful, the browser will be redirected to the 'view' page.
69 71 * @return mixed
70 72 */
71   - public function actionCreate()
  73 + public function actionCreate($product_id)
72 74 {
73 75 $model = new ProductVariant();
74   -
  76 + $model->product_id = $product_id;
75 77 if ($model->load(Yii::$app->request->post())) {
  78 +
76 79 $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload');
  80 + $model->validate();
  81 +
  82 + if ($model->save()) {
77 83  
78   - if ($model->save() && $model->imagesUpload) {
79 84 if ( ($images = $model->imagesUpload()) !== FALSE) {
80 85 foreach ($images as $image) {
81 86 $imageModel = new ProductImage();
... ... @@ -86,7 +91,7 @@ class VariantController extends Controller
86 91 }
87 92 }
88 93  
89   - return $this->redirect(['view', 'id' => $model->product_variant_id]);
  94 + return $this->redirect(['index', 'product_id' => $product_id]);
90 95 }
91 96 } else {
92 97 return $this->render('create', [
... ... @@ -98,29 +103,71 @@ class VariantController extends Controller
98 103 /**
99 104 * Updates an existing ProductVariant model.
100 105 * If update is successful, the browser will be redirected to the 'view' page.
  106 + * @param integer $product_id
101 107 * @param integer $id
102 108 * @return mixed
103 109 */
104   - public function actionUpdate($id)
  110 + public function actionUpdate($product_id, $id)
105 111 {
106 112 $model = $this->findModel($id);
107 113 if ($model->load(Yii::$app->request->post())) {
108   - $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload');
  114 +
  115 +
  116 +
  117 +
  118 +
  119 +
  120 +
109 121 if ($model->save()) {
110   - if ( ($images = $model->imagesUpload()) !== FALSE) {
111   - foreach ($images as $image) {
  122 +
  123 + if ( ($image = UploadedFile::getInstance($model, 'image')) ) {
  124 + $imageModel = ProductImage::find()->where(['product_variant_id' => $model->product_variant_id])->one();
  125 +
  126 + if($imageModel instanceof ProductImage) {
  127 + $imageModel->product_id = $model->product_id;
  128 + $imageModel->product_variant_id = $model->product_variant_id;
  129 + $imageModel->image = $image->name;
  130 + $imageModel->save();
  131 + } else {
112 132 $imageModel = new ProductImage();
113 133 $imageModel->product_id = $model->product_id;
114 134 $imageModel->product_variant_id = $model->product_variant_id;
115   - $imageModel->image = $image;
  135 + $imageModel->image = $image->name;
116 136 $imageModel->save();
117 137 }
  138 +
  139 +
  140 + $imgDir = Yii::getAlias('@storage/products/');
  141 +
  142 + if(!is_dir($imgDir)) {
  143 + mkdir($imgDir, 0755, true);
  144 + }
  145 +
  146 + $image->saveAs(Yii::getAlias('@storage/products/' . $image->name));
118 147 }
119 148  
120   - return $this->redirect(['view', 'id' => $model->product_variant_id]);
121 149 }
  150 + return $this->redirect(['index', 'product_id'=>$product_id]);
  151 +
  152 +
  153 +
  154 +
  155 +// $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload');
  156 +// if ($model->save()) {
  157 +// if ( ($images = $model->imagesUpload()) !== FALSE) {
  158 +// foreach ($images as $image) {
  159 +// $imageModel = new ProductImage();
  160 +// $imageModel->product_id = $model->product_id;
  161 +// $imageModel->product_variant_id = $model->product_variant_id;
  162 +// $imageModel->image = $image;
  163 +// $imageModel->save();
  164 +// }
  165 +// }
  166 +//
  167 +// return $this->redirect(['index', 'product_id' => $product_id]);
  168 +// }
122 169 } else {
123   - $groups = $model->category->getTaxGroups();
  170 + $groups = $model->category-> getTaxGroupsByLevel(1);
124 171  
125 172 return $this->render('update', [
126 173 'model' => $model,
... ...
common/modules/product/models/Category.php
... ... @@ -7,6 +7,7 @@ use common\components\artboxtree\ArtboxTreeBehavior;
7 7 use common\components\artboxtree\ArtboxTreeHelper;
8 8 use common\modules\relation\relationBehavior;
9 9 use common\modules\rubrication\behaviors\ArtboxSynonymBehavior;
  10 +use common\modules\rubrication\models\TaxGroup;
10 11 use Yii;
11 12 use yii\base\ErrorException;
12 13  
... ... @@ -164,6 +165,14 @@ class Category extends \yii\db\ActiveRecord
164 165 return $this->getRelations('tax_group_to_category');
165 166 }
166 167  
  168 +// public function getTaxGroupsByLevel($level)
  169 +// {
  170 +// return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ])
  171 +// ->viaTable('portfolio_specialization', [ 'portfolio_id' => 'portfolio_id' ]);
  172 +//
  173 +// return $this->hasMany(ProductCategory::className(), ['category_id' => 'category_id'])->with(TaxGroup::tableName())->where(['level' => $level]);
  174 +// }
  175 +
167 176 public function getRemote_category()
168 177 {
169 178 return ArtboxTreeHelper::getArrayField($this->remote_id);
... ...
common/modules/product/models/ProductImage.php
... ... @@ -97,7 +97,7 @@ class ProductImage extends \yii\db\ActiveRecord
97 97 */
98 98 public function getImageFile()
99 99 {
100   - return isset($this->image) ? '/images/products/' . $this->image : null;
  100 + return isset($this->image) ? '/storage/products/' . $this->image : null;
101 101 }
102 102  
103 103 /**
... ... @@ -107,7 +107,7 @@ class ProductImage extends \yii\db\ActiveRecord
107 107 public function getImageUrl()
108 108 {
109 109 // return a default image placeholder if your source image is not found
110   - return isset($this->image) ? '/images/products/'. $this->image : '/images/no_photo.png';
  110 + return isset($this->image) ? '/storage/products/'. $this->image : '/storage/no_photo.png';
111 111 }
112 112  
113 113 /**
... ...
common/modules/product/models/ProductVariantListSearch.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\product\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\data\ActiveDataProvider;
  8 +
  9 +/**
  10 + * ProductVariantSearch represents the model behind the search form about `backend\models\ProductVariant`.
  11 + */
  12 +class ProductVariantListSearch extends ProductVariant
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public function rules()
  18 + {
  19 + return [
  20 + [['product_variant_id', 'product_id', 'product_unit_id', 'product_variant_type_id'], 'integer'],
  21 + [['name', 'sku', 'remote_id'], 'safe'],
  22 + [['price', 'price_old', 'stock'], 'number'],
  23 + ];
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function scenarios()
  30 + {
  31 + // bypass scenarios() implementation in the parent class
  32 + return Model::scenarios();
  33 + }
  34 +
  35 + /**
  36 + * Creates data provider instance with search query applied
  37 + *
  38 + * @param array $params
  39 + *
  40 + * @return ActiveDataProvider
  41 + */
  42 + public function search($params, $product_id = false)
  43 + {
  44 + $query = ProductVariant::find();
  45 +
  46 + // add conditions that should always apply here
  47 +
  48 + $dataProvider = new ActiveDataProvider([
  49 + 'query' => $query,
  50 + ]);
  51 +
  52 + $this->load($params);
  53 +
  54 + if (!$this->validate()) {
  55 + // uncomment the following line if you do not want to return any records when validation fails
  56 + // $query->where('0=1');
  57 + return $dataProvider;
  58 + }
  59 +
  60 + if($product_id){
  61 + $query->andFilterWhere([
  62 + 'product_id' => $product_id,
  63 + ]);
  64 + }
  65 +
  66 + // grid filtering conditions
  67 + $query->andFilterWhere([
  68 + 'product_variant_id' => $this->product_variant_id,
  69 + 'price' => $this->price,
  70 + 'price_old' => $this->price_old,
  71 + 'stock' => $this->stock,
  72 + 'product_unit_id' => $this->product_unit_id,
  73 + 'product_variant_type_id' => $this->product_variant_type_id,
  74 + ]);
  75 +
  76 + $query->andFilterWhere(['like', 'name', $this->name])
  77 + ->andFilterWhere(['like', 'sku', $this->sku])
  78 + ->andFilterWhere(['like', 'remote_id', $this->remote_id]);
  79 +
  80 + return $dataProvider;
  81 + }
  82 +}
... ...
common/modules/product/views/variant/_form.php
... ... @@ -23,82 +23,33 @@ use kartik\select2\Select2;
23 23  
24 24 <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
25 25  
26   - <?= $form->field($model, 'product_id')->hiddenInput()->label(''); ?>
  26 + <?= $form->field($model, 'product_id')->hiddenInput()->label(false); ?>
27 27  
28 28 <?= $form->field($model, 'sku')->textarea(); ?>
29 29 <?= $form->field($model, 'price')->textarea(); ?>
30 30 <?= $form->field($model, 'price_old')->textarea(); ?>
31   -
32   - <?= $form->field($model, 'imagesUpload[]')->widget(\kartik\file\FileInput::classname(), [
33   - 'language' => 'ru',
  31 + <?php var_dump($model->imageUrl)?>
  32 + <?= $form->field($model, 'image')->widget(\kartik\file\FileInput::classname(), [
  33 + 'model' => $model,
  34 + 'attribute' => 'image',
34 35 'options' => [
35 36 'accept' => 'image/*',
36   - 'multiple' => true,
  37 + 'multiple' => true
37 38 ],
38 39 'pluginOptions' => [
39   - 'allowedFileExtensions' => ['jpg', 'gif', 'png'],
40   - 'initialPreview' => !empty($model->imagesHTML) ? $model->imagesHTML : [],
41   - 'initialPreviewConfig' => $model->imagesConfig,
42   - 'overwriteInitial' => false,
43   - 'showRemove' => false,
  40 + 'allowedFileExtensions' => ['jpg','gif','png'],
  41 + 'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'products') : '',
  42 + 'overwriteInitial' => true,
  43 + 'showRemove' => true,
44 44 'showUpload' => false,
45   -// 'uploadUrl' => empty($model->product_id) ? null : \yii\helpers\Url::to(['/product/manage/uploadImage']),
46   - 'uploadAsync' => !empty($model->product_id),
47   - 'previewFileType' => 'image',
48 45 ],
49 46 ]); ?>
50 47  
51   - <?php /*= $form->field($model, 'variants')->widget(MultipleInput::className(), [
52   - 'columns' => [
53   - [
54   - 'name' => 'product_variant_id',
55   - 'type' => MultipleInputColumn::TYPE_HIDDEN_INPUT,
56   - ],
57   - [
58   - 'name' => 'name',
59   - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT,
60   - 'title' => Yii::t('product', 'Name'),
61   - ],
62   - [
63   - 'name' => 'sku',
64   - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT,
65   - 'title' => Yii::t('product', 'SKU'),
66   - ],
67   - [
68   - 'name' => 'price',
69   - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT,
70   - 'title' => Yii::t('product', 'Price'),
71   - ],
72   - [
73   - 'name' => 'price_old',
74   - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT,
75   - 'title' => Yii::t('product', 'Old Price'),
76   - ],
77   - [
78   - 'name' => 'product_unit_id',
79   - 'type' => MultipleInputColumn::TYPE_DROPDOWN,
80   - 'title' => Yii::t('product', 'Unit'),
81   - 'items' => ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'),
82   - ],
83   - [
84   - 'name' => 'stock',
85   - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT,
86   - 'title' => Yii::t('product', 'Stock'),
87   - 'options' => [
88   - 'placeholder' => '∞'
89   - ],
90   - ],
91   - [
92   - 'name' => 'image',
93   - 'type' => 'fileInput',
94   - 'title' => Yii::t('product', 'Image'),
95   - 'options' => [
96   - 'multiple' => false
97   - ],
98   - ],
99   - ],
100   - ]);
101   - */ ?>
  48 + <?= $form->field($model, 'product_unit_id')->dropDownList(
  49 + ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'),
  50 + [
  51 + 'prompt' => Yii::t('product', 'Unit'),
  52 + ])->label(Yii::t('product', 'Unit')) ?>
102 53  
103 54 <?php if(isset($groups)) :?>
104 55 <?php foreach($groups->all() as $group) :?>
... ...
common/modules/product/views/variant/index.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 use yii\helpers\Html;
4 4 use yii\grid\GridView;
  5 +use yii\helpers\Url;
5 6  
6 7 /* @var $this yii\web\View */
7 8 /* @var $searchModel common\modules\product\models\ProductVariantSearch */
... ... @@ -24,7 +25,7 @@ if (!empty($product)) {
24 25 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
25 26  
26 27 <p>
27   - <?= Html::a(Yii::t('product', 'Create Variant'), ['create'], ['class' => 'btn btn-success']) ?>
  28 + <?= Html::a(Yii::t('product', 'Create Variant'), Url::toRoute(['create','product_id'=> $product_id]), ['class' => 'btn btn-success']) ?>
28 29 </p>
29 30 <?= GridView::widget([
30 31 'dataProvider' => $dataProvider,
... ... @@ -55,7 +56,41 @@ if (!empty($product)) {
55 56 'price_old',
56 57 'stock',
57 58  
58   - ['class' => 'yii\grid\ActionColumn'],
  59 + [
  60 + 'class' => 'yii\grid\ActionColumn',
  61 + 'buttons' => [
  62 + 'view' => function ($url, $model)
  63 + {
  64 + return Html::a (
  65 + '<span class="glyphicon glyphicon-eye-open"></span>',
  66 + Url::to(['view','product_id'=> $model->product_id, 'id' => $model->product_variant_id]),
  67 + [
  68 + 'title' => "Просмотр",
  69 + ]
  70 + );
  71 + },
  72 + 'update' => function ($url, $model)
  73 + {
  74 + return Html::a (
  75 + '<span class="glyphicon glyphicon-pencil"></span>',
  76 + Url::to(['update','product_id'=> $model->product_id, 'id' => $model->product_variant_id]),
  77 + [
  78 + 'title' => "Редактировать",
  79 + ]
  80 + );
  81 + },
  82 + 'delete' => function ($url, $model)
  83 + {
  84 +
  85 + return Html::a('<span class="glyphicon glyphicon-trash"></span>', Url::to(['delete','product_id'=> $model->product_id, 'id' => $model->product_variant_id]), [
  86 + 'title' => Yii::t('yii', 'Delete'),
  87 + 'data-confirm' => Yii::t('yii', 'Are you sure to delete this item?'),
  88 + 'data-method' => 'post',
  89 + ]);
  90 +
  91 + },
  92 + ],
  93 + ],
59 94 ],
60 95 ]); ?>
61 96 </div>
... ...
common/modules/product/views/variant/update.php
1 1 <?php
2 2  
3 3 use yii\helpers\Html;
  4 +use yii\helpers\Url;
4 5  
5 6 /* @var $this yii\web\View */
6 7 /* @var $model common\modules\product\models\Product */
... ... @@ -10,8 +11,7 @@ $this-&gt;title = Yii::t(&#39;product&#39;, &#39;Update {modelClass}: &#39;, [
10 11 ]) . ' ' . $model->name;
11 12 $this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Products'), 'url' => ['index']];
12 13 $this->params['breadcrumbs'][] = ['label' => $model->product->name, 'url' => ['view', 'id' => $model->product->product_id]];
13   -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Variants'), 'url' => ['/product/variant?product_id='. $model->product->product_id]];
14   -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->product_variant_id]];
  14 +$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Variants'), 'url' => Url::to(['/product/variant', 'product_id' => $model->product->product_id])];
15 15 $this->params['breadcrumbs'][] = Yii::t('product', 'Update');
16 16 ?>
17 17 <div class="product-update">
... ...
common/modules/rubrication/controllers/TaxGroupController.php
... ... @@ -32,16 +32,18 @@ class TaxGroupController extends Controller
32 32  
33 33 /**
34 34 * Lists all TaxGroup models.
  35 + * @param $level integer
35 36 * @return mixed
36 37 */
37   - public function actionIndex()
  38 + public function actionIndex($level)
38 39 {
39 40 $dataProvider = new ActiveDataProvider([
40   - 'query' => TaxGroup::find(),
  41 + 'query' => TaxGroup::find()->where(['level' => $level]),
41 42 ]);
42 43  
43 44 return $this->render('index', [
44 45 'dataProvider' => $dataProvider,
  46 + 'level' => $level
45 47 ]);
46 48 }
47 49  
... ... @@ -50,7 +52,7 @@ class TaxGroupController extends Controller
50 52 * @param integer $id
51 53 * @return mixed
52 54 */
53   - public function actionView($id)
  55 + public function actionView($level,$id)
54 56 {
55 57 return $this->render('view', [
56 58 'model' => $this->findModel($id),
... ... @@ -60,14 +62,17 @@ class TaxGroupController extends Controller
60 62 /**
61 63 * Creates a new TaxGroup model.
62 64 * If creation is successful, the browser will be redirected to the 'view' page.
  65 + * @param $level integer
63 66 * @return mixed
64 67 */
65   - public function actionCreate()
  68 + public function actionCreate($level)
66 69 {
67 70 $model = new TaxGroup();
68 71  
69   - if ($model->load(Yii::$app->request->post()) && $model->save()) {
70   - return $this->redirect(['view', 'id' => $model->tax_group_id]);
  72 + if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  73 + $model->level = $level;
  74 + $model->save();
  75 + return $this->redirect(['index', 'level' => $level]);
71 76 } else {
72 77 return $this->render('create', [
73 78 'model' => $model,
... ... @@ -78,15 +83,16 @@ class TaxGroupController extends Controller
78 83 /**
79 84 * Updates an existing TaxGroup model.
80 85 * If update is successful, the browser will be redirected to the 'view' page.
  86 + * @param $level integer
81 87 * @param integer $id
82 88 * @return mixed
83 89 */
84   - public function actionUpdate($id)
  90 + public function actionUpdate($level,$id)
85 91 {
86 92 $model = $this->findModel($id);
87 93  
88 94 if ($model->load(Yii::$app->request->post()) && $model->save()) {
89   - return $this->redirect(['view', 'id' => $model->tax_group_id]);
  95 + return $this->redirect(['index', 'level' => $level]);
90 96 } else {
91 97 return $this->render('update', [
92 98 'model' => $model,
... ... @@ -97,14 +103,14 @@ class TaxGroupController extends Controller
97 103 /**
98 104 * Deletes an existing TaxGroup model.
99 105 * If deletion is successful, the browser will be redirected to the 'index' page.
  106 + * @param $level integer
100 107 * @param integer $id
101 108 * @return mixed
102 109 */
103   - public function actionDelete($id)
  110 + public function actionDelete($level,$id)
104 111 {
105 112 $this->findModel($id)->delete();
106   -
107   - return $this->redirect(['index']);
  113 + return $this->redirect(['index', 'level' => $level]);
108 114 }
109 115  
110 116 /*
... ...
common/modules/rubrication/models/TaxGroup.php
... ... @@ -16,7 +16,7 @@ use Yii;
16 16 * @property boolean $hierarchical
17 17 * @property string $settings
18 18 * @property boolean $is_filter
19   - *
  19 + * @property integer $level
20 20 * @property TaxGroupToGroup[] $taxGroupToGroups
21 21 * @property TaxGroupToGroup[] $taxGroupToGroups0
22 22 * @property TaxOption[] $taxOptions
... ... @@ -63,6 +63,7 @@ class TaxGroup extends \yii\db\ActiveRecord
63 63 [['name', 'module'], 'required'],
64 64 [['description', 'settings'], 'string'],
65 65 [['hierarchical', 'is_filter'], 'boolean'],
  66 + [['level'], 'integer'],
66 67 [['alias', 'module'], 'string', 'max' => 50],
67 68 [['name'], 'string', 'max' => 255],
68 69 [['group_to_category'], 'safe']
... ...
common/modules/rubrication/models/TaxOption.php
... ... @@ -69,7 +69,7 @@ class TaxOption extends \yii\db\ActiveRecord
69 69 {
70 70 return [
71 71 [['tax_group_id'], 'required'],
72   - [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'],
  72 + [['tax_group_id', 'level', 'parent_id', 'sort', 'default_value'], 'integer'],
73 73 [['alias'], 'string', 'max' => 50],
74 74 [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']],
75 75 // [['parent_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxOption::className(), 'targetAttribute' => ['parent_id' => 'tax_option_id']],
... ...
common/modules/rubrication/views/tax-group/index.php
1 1 <?php
2 2 use yii\helpers\Html;
3 3 use yii\grid\GridView;
  4 +use yii\helpers\Url;
  5 +
4 6 /* @var $this yii\web\View */
  7 +/* @var $level integer
5 8 /* @var $dataProvider yii\data\ActiveDataProvider */
6 9  
7 10 $this->title = Yii::t('rubrication', 'Groups');
... ... @@ -12,7 +15,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
12 15  
13 16 <h1><?= Html::encode($this->title) ?></h1>
14 17 <p>
15   - <?= Html::a(Yii::t('rubrication', 'Create Group'), ['create'], ['class' => 'btn btn-success']) ?>
  18 + <?= Html::a(Yii::t('rubrication', 'Create Group'), Url::to(['/rubrication/tax-group/create', 'level'=> $level]), ['class' => 'btn btn-success']) ?>
16 19 </p>
17 20  
18 21 <?= GridView::widget([
... ... @@ -48,7 +51,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
48 51 ]);
49 52 }
50 53 ],
51   - 'urlCreator' => function ($action, $model, $key, $index) {
  54 + 'urlCreator' => function ($action, $model, $key, $index) use ($level) {
52 55 if ($action === 'options') {
53 56 $url ='/admin/rubrication/tax-option?group='.$model->tax_group_id;
54 57 return $url;
... ... @@ -56,10 +59,10 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
56 59 $url ='/admin/rubrication/tax-group/relation&id='.$model->tax_group_id;
57 60 return $url;
58 61 } elseif ($action === 'update') {
59   - $url ='/admin/rubrication/tax-group/update?id='.$model->tax_group_id;
  62 + $url =Url::to(['/rubrication/tax-group/update', 'level'=> $level,'id' =>$model->tax_group_id]);
60 63 return $url;
61 64 } elseif ($action === 'delete') {
62   - $url ='/admin/rubrication/tax-group/delete?id='.$model->tax_group_id;
  65 + $url =Url::to(['/rubrication/tax-group/delete', 'level'=> $level,'id' =>$model->tax_group_id]);
63 66 return $url;
64 67 } elseif ($action === 'rebuild') {
65 68 $url ='/admin/rubrication/tax-group/rebuild?id='.$model->tax_group_id;
... ...
console/migrations/m160414_214746_add_level_to_tax_group.php 0 → 100755
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Handles adding the columns `key`
  7 + * for table `seo_dynamic`.
  8 + */
  9 +class m160414_214746_add_level_to_tax_group extends Migration
  10 +{
  11 + /**
  12 + * @inheritdoc
  13 + */
  14 + public function up()
  15 + {
  16 + $this->addColumn('tax_group', 'level', $this->integer());
  17 + }
  18 +
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function down()
  23 + {
  24 + $this->dropColumn('tax_group', 'level');
  25 + }
  26 +}
... ...