Commit 4a7f93fbc953493cf56039d34b545c054704d1ac

Authored by Yarik
1 parent 4e55ce81

Another one admin fix

backend/controllers/BrandController.php
... ... @@ -163,7 +163,7 @@
163 163 */
164 164 protected function findModel($id)
165 165 {
166   - if(( $model = Brand::findOne($id) ) !== NULL) {
  166 + if(( $model = Brand::find()->with('lang')->where(['brand_id' => $id])->one() ) !== NULL) {
167 167 return $model;
168 168 } else {
169 169 throw new NotFoundHttpException('The requested page does not exist.');
... ...
backend/controllers/CategoryController.php
... ... @@ -54,7 +54,6 @@
54 54 {
55 55 $searchModel = new CategorySearch();
56 56 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
57   -
58 57 return $this->render('index', [
59 58 'searchModel' => $searchModel,
60 59 'dataProvider' => $dataProvider,
... ... @@ -70,8 +69,13 @@
70 69 */
71 70 public function actionView($id)
72 71 {
  72 + $model = $this->findModel($id);
  73 + $tree = $model->getParents()
  74 + ->with('lang')
  75 + ->all();
73 76 return $this->render('view', [
74   - 'model' => $this->findModel($id),
  77 + 'model' => $model,
  78 + 'tree' => $tree,
75 79 ]);
76 80 }
77 81  
... ... @@ -160,7 +164,11 @@
160 164 */
161 165 protected function findModel($id)
162 166 {
163   - if(( $model = Category::findOne($id) ) !== NULL) {
  167 + if(( $model = Category::find()
  168 + ->where([ 'category_id' => $id ])
  169 + ->with('lang')
  170 + ->one() ) !== NULL
  171 + ) {
164 172 return $model;
165 173 } else {
166 174 throw new NotFoundHttpException('The requested page does not exist.');
... ...
backend/views/brand/_form.php
... ... @@ -43,6 +43,8 @@
43 43 ],
44 44 ]); ?>
45 45  
  46 + <?= $form->field($model, 'in_menu')->dropDownList([\Yii::t('product', 'No'), \Yii::t('product', 'Yes')]); ?>
  47 +
46 48 <?= LanguageForm::widget([
47 49 'model_langs' => $model_langs,
48 50 'formView' => '@backend/views/brand/_form_language',
... ...
backend/views/brand/index.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\grid\GridView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $searchModel common\modules\product\models\BrandSearch */
8   -/* @var $dataProvider yii\data\ActiveDataProvider */
9   -
10   -$this->title = Yii::t('product', 'Brands');
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\product\models\Brand;
  4 + use common\modules\product\models\BrandSearch;
  5 + use yii\data\ActiveDataProvider;
  6 + use yii\helpers\Html;
  7 + use yii\grid\GridView;
  8 + use yii\web\View;
  9 +
  10 + /**
  11 + * @var View $this
  12 + * @var BrandSearch $searchModel
  13 + * @var ActiveDataProvider $dataProvider
  14 + */
  15 +
  16 + $this->title = Yii::t('product', 'Brands');
  17 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 18 ?>
13 19 <div class="brand-index">
14   -
  20 +
15 21 <h1><?= Html::encode($this->title) ?></h1>
16   -
  22 +
17 23 <p>
18   - <?= Html::a(Yii::t('product', 'Create Brand'), ['create'], ['class' => 'btn btn-success']) ?>
  24 + <?= Html::a(Yii::t('product', 'Create Brand'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
19 25 </p>
20 26 <?= GridView::widget([
21 27 'dataProvider' => $dataProvider,
22   - 'columns' => [
23   - ['class' => 'yii\grid\SerialColumn'],
  28 + 'filterModel' => $searchModel,
  29 + 'columns' => [
24 30 'brand_id',
  31 + [
  32 + 'attribute' => 'brand_name',
  33 + 'value' => 'lang.name',
  34 + ],
25 35 'imageUrl:image',
26   - ['class' => 'yii\grid\ActionColumn'],
  36 + [
  37 + 'attribute' => 'in_menu',
  38 + 'content' => function($model) {
  39 + /**
  40 + * @var Brand $model
  41 + */
  42 + return Html::tag('span', '', [
  43 + 'class' => 'glyphicon glyphicon-'.($model->in_menu?'ok':'remove'),
  44 + ]);
  45 + },
  46 + ],
  47 + [ 'class' => 'yii\grid\ActionColumn',
27 48 ],
  49 + ],
28 50 ]); ?>
29 51 </div>
... ...
backend/views/brand/update.php
... ... @@ -13,13 +13,13 @@
13 13  
14 14 $this->title = Yii::t('product', 'Update {modelClass}: ', [
15 15 'modelClass' => 'Brand',
16   - ]) . ' ' . $model->brand_id;
  16 + ]) . ' ' . $model->lang->name;
17 17 $this->params[ 'breadcrumbs' ][] = [
18 18 'label' => Yii::t('product', 'Brands'),
19 19 'url' => [ 'index' ],
20 20 ];
21 21 $this->params[ 'breadcrumbs' ][] = [
22   - 'label' => $model->brand_id,
  22 + 'label' => $model->lang->name,
23 23 'url' => [
24 24 'view',
25 25 'id' => $model->brand_id,
... ...
backend/views/brand/view.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\widgets\DetailView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $model common\modules\product\models\Brand */
8   -
9   -$this->title = $model->brand_id;
10   -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Brands'), 'url' => ['index']];
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\product\models\Brand;
  4 + use yii\helpers\Html;
  5 + use yii\web\View;
  6 + use yii\widgets\DetailView;
  7 +
  8 + /**
  9 + * @var View $this
  10 + * @var Brand $model
  11 + */
  12 +
  13 + $this->title = $model->lang->name;
  14 + $this->params[ 'breadcrumbs' ][] = [
  15 + 'label' => Yii::t('product', 'Brands'),
  16 + 'url' => [ 'index' ],
  17 + ];
  18 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 19 ?>
13 20 <div class="brand-view">
14   -
  21 +
15 22 <h1><?= Html::encode($this->title) ?></h1>
16   -
  23 +
17 24 <p>
18   - <?= Html::a(Yii::t('product', 'Update'), ['update', 'id' => $model->brand_id], ['class' => 'btn btn-primary']) ?>
19   - <?= Html::a(Yii::t('product', 'Delete'), ['delete', 'id' => $model->brand_id], [
  25 + <?= Html::a(Yii::t('product', 'Update'), [
  26 + 'update',
  27 + 'id' => $model->brand_id,
  28 + ], [ 'class' => 'btn btn-primary' ]) ?>
  29 + <?= Html::a(Yii::t('product', 'Delete'), [
  30 + 'delete',
  31 + 'id' => $model->brand_id,
  32 + ], [
20 33 'class' => 'btn btn-danger',
21   - 'data' => [
  34 + 'data' => [
22 35 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'),
23   - 'method' => 'post',
  36 + 'method' => 'post',
24 37 ],
25 38 ]) ?>
26 39 </p>
27   -
  40 +
28 41 <?= DetailView::widget([
29   - 'model' => $model,
  42 + 'model' => $model,
30 43 'attributes' => [
31 44 'brand_id',
  45 + 'lang.name',
  46 + 'lang.alias',
  47 + [
  48 + 'attribute' => 'in_menu',
  49 + 'value' => Html::tag('span', '', [
  50 + 'class' => 'glyphicon glyphicon-' . ( $model->in_menu ? 'ok' : 'remove' ),
  51 + ]),
  52 + 'format' => 'html',
  53 + ],
32 54 'imageUrl:image',
  55 + 'lang.meta_title',
  56 + 'lang.meta_robots',
  57 + 'lang.meta_desc',
  58 + 'lang.seo_text',
33 59 ],
34 60 ]) ?>
35 61  
... ...
backend/views/category/index.php
... ... @@ -40,6 +40,7 @@
40 40 return implode('&nbsp;&rarr;&nbsp;', $op);
41 41 },
42 42 ],
  43 + 'imageUrl:image',
43 44 [
44 45 'class' => 'yii\grid\ActionColumn',
45 46 ],
... ...
backend/views/category/update.php
... ... @@ -14,13 +14,13 @@
14 14  
15 15 $this->title = Yii::t('product', 'Update {modelClass}: ', [
16 16 'modelClass' => 'Category',
17   - ]) . ' ' . $model->category_id;
  17 + ]) . ' ' . $model->lang->name;
18 18 $this->params[ 'breadcrumbs' ][] = [
19 19 'label' => Yii::t('product', 'Categories'),
20 20 'url' => [ 'index' ],
21 21 ];
22 22 $this->params[ 'breadcrumbs' ][] = [
23   - 'label' => $model->category_id,
  23 + 'label' => $model->lang->name,
24 24 'url' => [
25 25 'view',
26 26 'id' => $model->category_id,
... ...
backend/views/category/view.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\widgets\DetailView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $model common\modules\product\models\Category */
8   -
9   -$this->title = $model->category_id;
10   -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Categories'), 'url' => ['index']];
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\product\models\Category;
  4 + use yii\helpers\Html;
  5 + use yii\web\View;
  6 + use yii\widgets\DetailView;
  7 +
  8 + /**
  9 + * @var View $this
  10 + * @var Category $model
  11 + * @var Category[] $tree
  12 + */
  13 +
  14 + $this->title = $model->lang->name;
  15 + $this->params[ 'breadcrumbs' ][] = [
  16 + 'label' => Yii::t('product', 'Categories'),
  17 + 'url' => [ 'index' ],
  18 + ];
  19 + $this->params[ 'breadcrumbs' ][] = $this->title;
  20 + $tree_links = [];
  21 + foreach($tree as $item) {
  22 + $tree_links[] = Html::a($item->lang->name, [
  23 + 'view',
  24 + 'id' => $item->category_id,
  25 + ]);
  26 + }
  27 + if(empty($tree_links)) {
  28 + $tree_string = \Yii::t('product', 'No parent categories');
  29 + } else {
  30 + $tree_string = implode('&nbsp;&rarr;&nbsp;', $tree_links);
  31 + }
12 32 ?>
13 33 <div class="category-view">
14   -
  34 +
15 35 <h1><?= Html::encode($this->title) ?></h1>
16   -
  36 +
17 37 <p>
18   - <?= Html::a(Yii::t('product', 'Update'), ['update', 'id' => $model->category_id], ['class' => 'btn btn-primary']) ?>
19   - <?= Html::a(Yii::t('product', 'Delete'), ['delete', 'id' => $model->category_id], [
  38 + <?= Html::a(Yii::t('product', 'Update'), [
  39 + 'update',
  40 + 'id' => $model->category_id,
  41 + ], [ 'class' => 'btn btn-primary' ]) ?>
  42 + <?= Html::a(Yii::t('product', 'Delete'), [
  43 + 'delete',
  44 + 'id' => $model->category_id,
  45 + ], [
20 46 'class' => 'btn btn-danger',
21   - 'data' => [
  47 + 'data' => [
22 48 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'),
23   - 'method' => 'post',
  49 + 'method' => 'post',
24 50 ],
25 51 ]) ?>
26   - <?= Html::a(Yii::t('product', 'Create Category'), ['category/create'], ['class' => 'btn btn-success']) ?>
27   - <?php if (!empty($model->parent_id)) :?>
28   - <?= Html::a(Yii::t('product', 'Create category By {name}', ['name' => $model->parent->category_id]), ['category/create?parent='. $model->parent->category_id], ['class' => 'btn btn-success']) ?>
29   - <?php endif?>
  52 + <?= Html::a(Yii::t('product', 'Create Category'), [ 'category/create' ], [ 'class' => 'btn btn-success' ]) ?>
  53 + <?php
  54 + if(!empty( $model->parent_id )) {
  55 + echo Html::a(Yii::t('product', 'Create category By {name}', [ 'name' => $model->parent->lang->name ]), [ 'category/create?parent=' . $model->parent->category_id ], [ 'class' => 'btn btn-success' ]);
  56 + }
  57 + ?>
30 58 </p>
31   -
  59 +
32 60 <?= DetailView::widget([
33   - 'model' => $model,
  61 + 'model' => $model,
34 62 'attributes' => [
35 63 'category_id',
36   - 'parent_id',
37   - 'path',
38   - 'depth',
  64 + [
  65 + 'label' => \Yii::t('product', 'Category tree'),
  66 + 'value' => $tree_string,
  67 + 'format' => 'html',
  68 + ],
39 69 'imageUrl:image',
40   - 'product_unit_id',
  70 + 'lang.alias',
  71 + 'lang.meta_title',
  72 + 'lang.meta_robots',
  73 + 'lang.meta_desc',
  74 + 'lang.seo_text',
  75 + 'lang.h1',
41 76 ],
42 77 ]) ?>
43 78  
... ...
common/modules/product/models/BrandSearch.php
1 1 <?php
2   -
3   -namespace common\modules\product\models;
4   -
5   -use yii\base\Model;
6   -use yii\data\ActiveDataProvider;
7   -use yii\db\ActiveQuery;
8   -
9   -/**
10   - * BrandSearch represents the model behind the search form about `common\modules\product\models\Brand`.
11   - */
12   -class BrandSearch extends Brand
13   -{
14   - public $brand_name;
15   - /**
16   - * @inheritdoc
17   - */
18   - public function rules()
19   - {
20   - return [
21   - [['brand_id'], 'integer'],
22   - ];
23   - }
24 2  
25   - public function behaviors()
26   - {
27   - return [];
28   - }
  3 + namespace common\modules\product\models;
29 4  
30   - /**
31   - * @inheritdoc
32   - */
33   - public function scenarios()
34   - {
35   - // bypass scenarios() implementation in the parent class
36   - return Model::scenarios();
37   - }
38   -
39   - /**
40   - * Creates data provider instance with search query applied
41   - *
42   - * @param array $params
43   - *
44   - * @return ActiveDataProvider
45   - */
46   - public function search($params)
47   - {
48   - $query = Brand::find();
49   -
50   - // add conditions that should always apply here
51   -
52   - $dataProvider = new ActiveDataProvider([
53   - 'query' => $query,
54   - ]);
55   -
56   - $this->load($params);
57   -
58   - /*if (!$this->validate()) {
59   - // uncomment the following line if you do not want to return any records when validation fails
60   - // $query->where('0=1');
61   - return $dataProvider;
62   - }*/
63   -
64   - $dataProvider->setSort([
65   - 'attributes' => [
66   - 'brand_name',
67   - ],
68   - ]);
69   -
70   - // grid filtering conditions
71   - $query->andFilterWhere([
72   - 'brand_id' => $this->brand_id,
73   - ]);
74   -
75   - $query->orderBy(['brand_id' => SORT_ASC]);
76   -
77   - return $dataProvider;
78   - }
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
  7 + use yii\db\ActiveQuery;
79 8  
80 9 /**
81   - * @param null|Category $category
82   - * @param array $params
83   - * @param null|ActiveQuery $productQuery
84   - *
85   - * @return ActiveQuery
  10 + * BrandSearch represents the model behind the search form about
  11 + * `common\modules\product\models\Brand`.
86 12 */
87   - public function getBrands($category = null, $params = [], $productQuery = null) {
88   -
89   - $query = Brand::find()
90   - ->select([
91   - Brand::tableName() .'.*'
  13 + class BrandSearch extends Brand
  14 + {
  15 +
  16 + public $brand_name;
  17 +
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function rules()
  22 + {
  23 + return [
  24 + [
  25 + [ 'brand_name' ],
  26 + 'safe',
  27 + ],
  28 + [
  29 + [ 'brand_id' ],
  30 + 'integer',
  31 + ],
  32 + ];
  33 + }
  34 +
  35 + public function behaviors()
  36 + {
  37 + return [];
  38 + }
  39 +
  40 + /**
  41 + * @inheritdoc
  42 + */
  43 + public function scenarios()
  44 + {
  45 + // bypass scenarios() implementation in the parent class
  46 + return Model::scenarios();
  47 + }
  48 +
  49 + /**
  50 + * Creates data provider instance with search query applied
  51 + *
  52 + * @param array $params
  53 + *
  54 + * @return ActiveDataProvider
  55 + */
  56 + public function search($params)
  57 + {
  58 + $query = Brand::find()
  59 + ->joinWith('lang');
  60 +
  61 + // add conditions that should always apply here
  62 +
  63 + $dataProvider = new ActiveDataProvider([
  64 + 'query' => $query,
  65 + ]);
  66 +
  67 + $this->load($params);
  68 +
  69 + /*if (!$this->validate()) {
  70 + // uncomment the following line if you do not want to return any records when validation fails
  71 + // $query->where('0=1');
  72 + return $dataProvider;
  73 + }*/
  74 +
  75 + $dataProvider->setSort([
  76 + 'attributes' => [
  77 + 'brand_id',
  78 + 'brand_name' => [
  79 + 'asc' => [ 'brand_lang.name' => SORT_ASC ],
  80 + 'desc' => [ 'brand_lang.name' => SORT_DESC ],
  81 + ],
  82 + ],
  83 + ]);
  84 +
  85 + // grid filtering conditions
  86 + $query->andFilterWhere([
  87 + 'brand.brand_id' => $this->brand_id,
92 88 ])
93   - ->innerJoin(Product::tableName(), Product::tableName() .'.brand_id='. Brand::tableName() .'.brand_id')
94   - ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. Product::tableName() .'.product_id');
  89 + ->andFilterWhere([
  90 + 'ilike',
  91 + 'brand_lang.name',
  92 + $this->brand_name,
  93 + ]);
  94 +
  95 + return $dataProvider;
  96 + }
95 97  
96   - $query->innerJoin('product_variant', 'product_variant.product_id = '. Product::tableName() .'.product_id');
97   - $query->where(['!=', 'product_variant.stock', 0]);
98   - $query->groupBy(Product::tableName() .'.product_id');
99   - if (!empty($category)) {
100   - $query->andWhere([
101   - ProductCategory::tableName() .'.category_id' => $category->category_id
  98 + /**
  99 + * @param null|Category $category
  100 + * @param array $params
  101 + * @param null|ActiveQuery $productQuery
  102 + *
  103 + * @return ActiveQuery
  104 + */
  105 + public function getBrands($category = NULL, $params = [], $productQuery = NULL)
  106 + {
  107 +
  108 + $query = Brand::find()
  109 + ->select([
  110 + Brand::tableName() . '.*',
  111 + ])
  112 + ->innerJoin(Product::tableName(), Product::tableName() . '.brand_id=' . Brand::tableName() . '.brand_id')
  113 + ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() . '.product_id=' . Product::tableName() . '.product_id');
  114 +
  115 + $query->innerJoin('product_variant', 'product_variant.product_id = ' . Product::tableName() . '.product_id');
  116 + $query->where([
  117 + '!=',
  118 + 'product_variant.stock',
  119 + 0,
102 120 ]);
  121 + $query->groupBy(Product::tableName() . '.product_id');
  122 + if(!empty( $category )) {
  123 + $query->andWhere([
  124 + ProductCategory::tableName() . '.category_id' => $category->category_id,
  125 + ]);
  126 + }
  127 + $query->groupBy(Brand::tableName() . '.brand_id');
  128 +
  129 + return $query;
103 130 }
104   - $query->groupBy(Brand::tableName() .'.brand_id');
105   -
106   - return $query;
107 131 }
108   -}
... ...
common/modules/product/models/Category.php
... ... @@ -14,6 +14,9 @@
14 14  
15 15 /**
16 16 * This is the model class for table "category".
  17 + *
  18 + * @todo Write doc for ArtboxTreeBehavior
  19 + *
17 20 * @property integer $category_id
18 21 * @property integer $remote_id
19 22 * @property integer $parent_id
... ... @@ -64,7 +67,7 @@
64 67 'fields' => [
65 68 [
66 69 'name' => 'image',
67   - 'directory' => 'brand',
  70 + 'directory' => 'categories',
68 71 ],
69 72 ],
70 73 ],
... ...
common/modules/product/models/CategorySearch.php
... ... @@ -2,7 +2,6 @@
2 2  
3 3 namespace common\modules\product\models;
4 4  
5   - use common\components\artboxtree\ArtboxTreeHelper;
6 5 use yii\base\Model;
7 6 use yii\data\ActiveDataProvider;
8 7  
... ... @@ -31,7 +30,7 @@
31 30 'safe',
32 31 ],
33 32 [
34   - [],
  33 + [ 'category_id' ],
35 34 'integer',
36 35 ],
37 36 ];
... ... @@ -58,11 +57,9 @@
58 57 $query = Category::find()
59 58 ->joinWith('lang');
60 59  
61   - // add conditions that should always apply here
62   -
63 60 $dataProvider = new ActiveDataProvider([
64 61 'query' => $query,
65   - 'sort' => false,
  62 + 'sort' => false,
66 63 ]);
67 64  
68 65 $this->load($params);
... ... @@ -75,6 +72,8 @@
75 72  
76 73 // grid filtering conditions
77 74 $query->andFilterWhere([
  75 + 'category.category_id' => $this->category_id,
  76 + ])->andFilterWhere([
78 77 'ilike',
79 78 'category_lang.name',
80 79 $this->category_name,
... ...