From 4a7f93fbc953493cf56039d34b545c054704d1ac Mon Sep 17 00:00:00 2001 From: yarik Date: Wed, 19 Oct 2016 00:30:44 +0300 Subject: [PATCH] Another one admin fix --- backend/controllers/BrandController.php | 2 +- backend/controllers/CategoryController.php | 14 +++++++++++--- backend/views/brand/_form.php | 2 ++ backend/views/brand/index.php | 54 ++++++++++++++++++++++++++++++++++++++---------------- backend/views/brand/update.php | 4 ++-- backend/views/brand/view.php | 62 ++++++++++++++++++++++++++++++++++++++++++++------------------ backend/views/category/index.php | 1 + backend/views/category/update.php | 4 ++-- backend/views/category/view.php | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- common/modules/product/models/BrandSearch.php | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------- common/modules/product/models/Category.php | 5 ++++- common/modules/product/models/CategorySearch.php | 9 ++++----- 12 files changed, 290 insertions(+), 171 deletions(-) diff --git a/backend/controllers/BrandController.php b/backend/controllers/BrandController.php index 8f76829..c68ab4f 100755 --- a/backend/controllers/BrandController.php +++ b/backend/controllers/BrandController.php @@ -163,7 +163,7 @@ */ protected function findModel($id) { - if(( $model = Brand::findOne($id) ) !== NULL) { + if(( $model = Brand::find()->with('lang')->where(['brand_id' => $id])->one() ) !== NULL) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); diff --git a/backend/controllers/CategoryController.php b/backend/controllers/CategoryController.php index f347685..a52ff2c 100755 --- a/backend/controllers/CategoryController.php +++ b/backend/controllers/CategoryController.php @@ -54,7 +54,6 @@ { $searchModel = new CategorySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, @@ -70,8 +69,13 @@ */ public function actionView($id) { + $model = $this->findModel($id); + $tree = $model->getParents() + ->with('lang') + ->all(); return $this->render('view', [ - 'model' => $this->findModel($id), + 'model' => $model, + 'tree' => $tree, ]); } @@ -160,7 +164,11 @@ */ protected function findModel($id) { - if(( $model = Category::findOne($id) ) !== NULL) { + if(( $model = Category::find() + ->where([ 'category_id' => $id ]) + ->with('lang') + ->one() ) !== NULL + ) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); diff --git a/backend/views/brand/_form.php b/backend/views/brand/_form.php index d41f39d..9b16822 100755 --- a/backend/views/brand/_form.php +++ b/backend/views/brand/_form.php @@ -43,6 +43,8 @@ ], ]); ?> + field($model, 'in_menu')->dropDownList([\Yii::t('product', 'No'), \Yii::t('product', 'Yes')]); ?> + $model_langs, 'formView' => '@backend/views/brand/_form_language', diff --git a/backend/views/brand/index.php b/backend/views/brand/index.php index fa911f5..29a43c8 100755 --- a/backend/views/brand/index.php +++ b/backend/views/brand/index.php @@ -1,29 +1,51 @@ title = Yii::t('product', 'Brands'); -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\product\models\Brand; + use common\modules\product\models\BrandSearch; + use yii\data\ActiveDataProvider; + use yii\helpers\Html; + use yii\grid\GridView; + use yii\web\View; + + /** + * @var View $this + * @var BrandSearch $searchModel + * @var ActiveDataProvider $dataProvider + */ + + $this->title = Yii::t('product', 'Brands'); + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- +

- 'btn btn-success']) ?> + 'btn btn-success' ]) ?>

$dataProvider, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], + 'filterModel' => $searchModel, + 'columns' => [ 'brand_id', + [ + 'attribute' => 'brand_name', + 'value' => 'lang.name', + ], 'imageUrl:image', - ['class' => 'yii\grid\ActionColumn'], + [ + 'attribute' => 'in_menu', + 'content' => function($model) { + /** + * @var Brand $model + */ + return Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-'.($model->in_menu?'ok':'remove'), + ]); + }, + ], + [ 'class' => 'yii\grid\ActionColumn', ], + ], ]); ?>
diff --git a/backend/views/brand/update.php b/backend/views/brand/update.php index 838d859..ee2ae53 100755 --- a/backend/views/brand/update.php +++ b/backend/views/brand/update.php @@ -13,13 +13,13 @@ $this->title = Yii::t('product', 'Update {modelClass}: ', [ 'modelClass' => 'Brand', - ]) . ' ' . $model->brand_id; + ]) . ' ' . $model->lang->name; $this->params[ 'breadcrumbs' ][] = [ 'label' => Yii::t('product', 'Brands'), 'url' => [ 'index' ], ]; $this->params[ 'breadcrumbs' ][] = [ - 'label' => $model->brand_id, + 'label' => $model->lang->name, 'url' => [ 'view', 'id' => $model->brand_id, diff --git a/backend/views/brand/view.php b/backend/views/brand/view.php index e73e094..f65bcdc 100755 --- a/backend/views/brand/view.php +++ b/backend/views/brand/view.php @@ -1,35 +1,61 @@ title = $model->brand_id; -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Brands'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\product\models\Brand; + use yii\helpers\Html; + use yii\web\View; + use yii\widgets\DetailView; + + /** + * @var View $this + * @var Brand $model + */ + + $this->title = $model->lang->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Brands'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- +

- $model->brand_id], ['class' => 'btn btn-primary']) ?> - $model->brand_id], [ + $model->brand_id, + ], [ 'class' => 'btn btn-primary' ]) ?> + $model->brand_id, + ], [ 'class' => 'btn btn-danger', - 'data' => [ + 'data' => [ 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), - 'method' => 'post', + 'method' => 'post', ], ]) ?>

- + $model, + 'model' => $model, 'attributes' => [ 'brand_id', + 'lang.name', + 'lang.alias', + [ + 'attribute' => 'in_menu', + 'value' => Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-' . ( $model->in_menu ? 'ok' : 'remove' ), + ]), + 'format' => 'html', + ], 'imageUrl:image', + 'lang.meta_title', + 'lang.meta_robots', + 'lang.meta_desc', + 'lang.seo_text', ], ]) ?> diff --git a/backend/views/category/index.php b/backend/views/category/index.php index 5f203b6..3ffaf6f 100755 --- a/backend/views/category/index.php +++ b/backend/views/category/index.php @@ -40,6 +40,7 @@ return implode(' → ', $op); }, ], + 'imageUrl:image', [ 'class' => 'yii\grid\ActionColumn', ], diff --git a/backend/views/category/update.php b/backend/views/category/update.php index f0a8b77..0094434 100755 --- a/backend/views/category/update.php +++ b/backend/views/category/update.php @@ -14,13 +14,13 @@ $this->title = Yii::t('product', 'Update {modelClass}: ', [ 'modelClass' => 'Category', - ]) . ' ' . $model->category_id; + ]) . ' ' . $model->lang->name; $this->params[ 'breadcrumbs' ][] = [ 'label' => Yii::t('product', 'Categories'), 'url' => [ 'index' ], ]; $this->params[ 'breadcrumbs' ][] = [ - 'label' => $model->category_id, + 'label' => $model->lang->name, 'url' => [ 'view', 'id' => $model->category_id, diff --git a/backend/views/category/view.php b/backend/views/category/view.php index cf76c6b..00c95a5 100755 --- a/backend/views/category/view.php +++ b/backend/views/category/view.php @@ -1,43 +1,78 @@ title = $model->category_id; -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Categories'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\product\models\Category; + use yii\helpers\Html; + use yii\web\View; + use yii\widgets\DetailView; + + /** + * @var View $this + * @var Category $model + * @var Category[] $tree + */ + + $this->title = $model->lang->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Categories'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; + $tree_links = []; + foreach($tree as $item) { + $tree_links[] = Html::a($item->lang->name, [ + 'view', + 'id' => $item->category_id, + ]); + } + if(empty($tree_links)) { + $tree_string = \Yii::t('product', 'No parent categories'); + } else { + $tree_string = implode(' → ', $tree_links); + } ?>
- +

title) ?>

- +

- $model->category_id], ['class' => 'btn btn-primary']) ?> - $model->category_id], [ + $model->category_id, + ], [ 'class' => 'btn btn-primary' ]) ?> + $model->category_id, + ], [ 'class' => 'btn btn-danger', - 'data' => [ + 'data' => [ 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), - 'method' => 'post', + 'method' => 'post', ], ]) ?> - 'btn btn-success']) ?> - parent_id)) :?> - $model->parent->category_id]), ['category/create?parent='. $model->parent->category_id], ['class' => 'btn btn-success']) ?> - + 'btn btn-success' ]) ?> + parent_id )) { + 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' ]); + } + ?>

- + $model, + 'model' => $model, 'attributes' => [ 'category_id', - 'parent_id', - 'path', - 'depth', + [ + 'label' => \Yii::t('product', 'Category tree'), + 'value' => $tree_string, + 'format' => 'html', + ], 'imageUrl:image', - 'product_unit_id', + 'lang.alias', + 'lang.meta_title', + 'lang.meta_robots', + 'lang.meta_desc', + 'lang.seo_text', + 'lang.h1', ], ]) ?> diff --git a/common/modules/product/models/BrandSearch.php b/common/modules/product/models/BrandSearch.php index c5f9974..c945a66 100755 --- a/common/modules/product/models/BrandSearch.php +++ b/common/modules/product/models/BrandSearch.php @@ -1,108 +1,131 @@ $query, - ]); - - $this->load($params); - - /*if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); - return $dataProvider; - }*/ - - $dataProvider->setSort([ - 'attributes' => [ - 'brand_name', - ], - ]); - - // grid filtering conditions - $query->andFilterWhere([ - 'brand_id' => $this->brand_id, - ]); - - $query->orderBy(['brand_id' => SORT_ASC]); - - return $dataProvider; - } + use yii\base\Model; + use yii\data\ActiveDataProvider; + use yii\db\ActiveQuery; /** - * @param null|Category $category - * @param array $params - * @param null|ActiveQuery $productQuery - * - * @return ActiveQuery + * BrandSearch represents the model behind the search form about + * `common\modules\product\models\Brand`. */ - public function getBrands($category = null, $params = [], $productQuery = null) { - - $query = Brand::find() - ->select([ - Brand::tableName() .'.*' + class BrandSearch extends Brand + { + + public $brand_name; + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'brand_name' ], + 'safe', + ], + [ + [ 'brand_id' ], + 'integer', + ], + ]; + } + + public function behaviors() + { + return []; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Brand::find() + ->joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + /*if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + }*/ + + $dataProvider->setSort([ + 'attributes' => [ + 'brand_id', + 'brand_name' => [ + 'asc' => [ 'brand_lang.name' => SORT_ASC ], + 'desc' => [ 'brand_lang.name' => SORT_DESC ], + ], + ], + ]); + + // grid filtering conditions + $query->andFilterWhere([ + 'brand.brand_id' => $this->brand_id, ]) - ->innerJoin(Product::tableName(), Product::tableName() .'.brand_id='. Brand::tableName() .'.brand_id') - ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. Product::tableName() .'.product_id'); + ->andFilterWhere([ + 'ilike', + 'brand_lang.name', + $this->brand_name, + ]); + + return $dataProvider; + } - $query->innerJoin('product_variant', 'product_variant.product_id = '. Product::tableName() .'.product_id'); - $query->where(['!=', 'product_variant.stock', 0]); - $query->groupBy(Product::tableName() .'.product_id'); - if (!empty($category)) { - $query->andWhere([ - ProductCategory::tableName() .'.category_id' => $category->category_id + /** + * @param null|Category $category + * @param array $params + * @param null|ActiveQuery $productQuery + * + * @return ActiveQuery + */ + public function getBrands($category = NULL, $params = [], $productQuery = NULL) + { + + $query = Brand::find() + ->select([ + Brand::tableName() . '.*', + ]) + ->innerJoin(Product::tableName(), Product::tableName() . '.brand_id=' . Brand::tableName() . '.brand_id') + ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() . '.product_id=' . Product::tableName() . '.product_id'); + + $query->innerJoin('product_variant', 'product_variant.product_id = ' . Product::tableName() . '.product_id'); + $query->where([ + '!=', + 'product_variant.stock', + 0, ]); + $query->groupBy(Product::tableName() . '.product_id'); + if(!empty( $category )) { + $query->andWhere([ + ProductCategory::tableName() . '.category_id' => $category->category_id, + ]); + } + $query->groupBy(Brand::tableName() . '.brand_id'); + + return $query; } - $query->groupBy(Brand::tableName() .'.brand_id'); - - return $query; } -} diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index a01d9fb..9a1c239 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -14,6 +14,9 @@ /** * This is the model class for table "category". + * + * @todo Write doc for ArtboxTreeBehavior + * * @property integer $category_id * @property integer $remote_id * @property integer $parent_id @@ -64,7 +67,7 @@ 'fields' => [ [ 'name' => 'image', - 'directory' => 'brand', + 'directory' => 'categories', ], ], ], diff --git a/common/modules/product/models/CategorySearch.php b/common/modules/product/models/CategorySearch.php index 082a9c4..c08b430 100755 --- a/common/modules/product/models/CategorySearch.php +++ b/common/modules/product/models/CategorySearch.php @@ -2,7 +2,6 @@ namespace common\modules\product\models; - use common\components\artboxtree\ArtboxTreeHelper; use yii\base\Model; use yii\data\ActiveDataProvider; @@ -31,7 +30,7 @@ 'safe', ], [ - [], + [ 'category_id' ], 'integer', ], ]; @@ -58,11 +57,9 @@ $query = Category::find() ->joinWith('lang'); - // add conditions that should always apply here - $dataProvider = new ActiveDataProvider([ 'query' => $query, - 'sort' => false, + 'sort' => false, ]); $this->load($params); @@ -75,6 +72,8 @@ // grid filtering conditions $query->andFilterWhere([ + 'category.category_id' => $this->category_id, + ])->andFilterWhere([ 'ilike', 'category_lang.name', $this->category_name, -- libgit2 0.21.4