From 599302f3475f5ba48eaf5cfdb921792018f1cbfb Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 12 Jun 2017 18:53:55 +0300 Subject: [PATCH] -Made sort by brand --- backend/views/brand/_form.php | 2 ++ common/modules/product/models/Brand.php | 11 ++++++++--- console/migrations/m170612_153331_add_sort_column_to_brand_table.php | 25 +++++++++++++++++++++++++ frontend/models/ProductFrontendSearch.php | 5 ++++- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 console/migrations/m170612_153331_add_sort_column_to_brand_table.php diff --git a/backend/views/brand/_form.php b/backend/views/brand/_form.php index 6f59b82..7b5804d 100755 --- a/backend/views/brand/_form.php +++ b/backend/views/brand/_form.php @@ -84,6 +84,8 @@ field($model, 'in_menu') ->checkbox() ?> + + field($model, 'sort') ?>
Yii::t('product', 'Seo Text'), 'in_menu' => Yii::t('product', 'Выводить в меню'), 'description' => Yii::t('product', 'Описание'), + 'sort' => Yii::t('product', 'Порядок'), ]; } @@ -152,12 +157,12 @@ public function getImageFile() { - return empty($this->image) ? NULL : '/storage/brands/' . $this->image; + return empty($this->image) ? null : '/storage/brands/' . $this->image; } public function getImageUrl() { - return empty($this->image) ? NULL : '/storage/brands/' . $this->image; + return empty($this->image) ? null : '/storage/brands/' . $this->image; } } diff --git a/console/migrations/m170612_153331_add_sort_column_to_brand_table.php b/console/migrations/m170612_153331_add_sort_column_to_brand_table.php new file mode 100644 index 0000000..94c2e89 --- /dev/null +++ b/console/migrations/m170612_153331_add_sort_column_to_brand_table.php @@ -0,0 +1,25 @@ +addColumn('brand', 'sort', $this->integer()); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropColumn('brand', 'sort'); + } + } diff --git a/frontend/models/ProductFrontendSearch.php b/frontend/models/ProductFrontendSearch.php index 7241c58..c5a07f0 100755 --- a/frontend/models/ProductFrontendSearch.php +++ b/frontend/models/ProductFrontendSearch.php @@ -119,7 +119,10 @@ ); // $query->groupBy(['product.product_id', 'product_variant.price', 'product_variant.stock']); - $query->orderBy([ 'product_variant.stock' => SORT_DESC ]); + $query->orderBy([ + 'brand.sort' => SORT_ASC, + 'product_variant.stock' => SORT_DESC, + ]); ProductHelper::_setQueryParams($query, $params); if ($in_stock) { $query->andWhere( -- libgit2 0.21.4