Commit 8f02e664a73e5ebe4ff634f6f6ccabbf8565a4a1
1 parent
b13c67c3
add multisort functional in goods controller
Showing
8 changed files
with
95 additions
and
74 deletions
Show diff stats
common/models/GoodsViewSearch.php
@@ -38,7 +38,7 @@ class GoodsViewSearch extends GoodsView | @@ -38,7 +38,7 @@ class GoodsViewSearch extends GoodsView | ||
38 | * | 38 | * |
39 | * @return ActiveDataProvider | 39 | * @return ActiveDataProvider |
40 | */ | 40 | */ |
41 | - public function search($params) | 41 | + public function search( $params, $sort ) |
42 | { | 42 | { |
43 | $query = GoodsView::find(); | 43 | $query = GoodsView::find(); |
44 | 44 | ||
@@ -53,7 +53,8 @@ class GoodsViewSearch extends GoodsView | @@ -53,7 +53,8 @@ class GoodsViewSearch extends GoodsView | ||
53 | 'brand' => $this->brand, | 53 | 'brand' => $this->brand, |
54 | ]); | 54 | ]); |
55 | 55 | ||
56 | - $query->andWhere(['or', 'box > 0', 'add_box > 0'])->orderBy(['price' => SORT_DESC]); | 56 | + |
57 | + $query->andWhere(['or', 'box > 0', 'add_box > 0'])->orderBy( $sort ); | ||
57 | 58 | ||
58 | $dataProvider = new ActiveDataProvider([ | 59 | $dataProvider = new ActiveDataProvider([ |
59 | 'query' => $query, | 60 | 'query' => $query, |
@@ -62,7 +63,7 @@ class GoodsViewSearch extends GoodsView | @@ -62,7 +63,7 @@ class GoodsViewSearch extends GoodsView | ||
62 | 63 | ||
63 | return $dataProvider; | 64 | return $dataProvider; |
64 | } | 65 | } |
65 | - public function searchCrosses($params) | 66 | + public function searchCrosses( $params, $sort ) |
66 | { | 67 | { |
67 | $query = GoodsView::find()->innerJoin('w_details_crosses', '`w_details_crosses`.`ARTICLE` = `name` and `w_details_crosses`.`BRAND` = w_goods_view.`brand`')->select('w_goods_view.*, w_details_crosses.CROSS_BRAND as crosses' ); | 68 | $query = GoodsView::find()->innerJoin('w_details_crosses', '`w_details_crosses`.`ARTICLE` = `name` and `w_details_crosses`.`BRAND` = w_goods_view.`brand`')->select('w_goods_view.*, w_details_crosses.CROSS_BRAND as crosses' ); |
68 | 69 | ||
@@ -77,7 +78,7 @@ class GoodsViewSearch extends GoodsView | @@ -77,7 +78,7 @@ class GoodsViewSearch extends GoodsView | ||
77 | 'w_details_crosses.CROSS_BRAND' => $this->brand, | 78 | 'w_details_crosses.CROSS_BRAND' => $this->brand, |
78 | ]); | 79 | ]); |
79 | 80 | ||
80 | - $query->andWhere(['or', 'box > 0', 'add_box > 0'])->orderBy(['price' => SORT_DESC]); | 81 | + $query->andWhere(['or', 'box > 0', 'add_box > 0'])->orderBy( $sort ); |
81 | 82 | ||
82 | $dataProvider = new ActiveDataProvider([ | 83 | $dataProvider = new ActiveDataProvider([ |
83 | 'query' => $query, | 84 | 'query' => $query, |
console/migrations/m151219_103804_goods_view.php
@@ -40,9 +40,9 @@ class m151219_103804_goods_view extends Migration | @@ -40,9 +40,9 @@ class m151219_103804_goods_view extends Migration | ||
40 | if (`w_details_description`.`image` = '', | 40 | if (`w_details_description`.`image` = '', |
41 | if (`w_details_description`.`tecdoc_image` = '', | 41 | if (`w_details_description`.`tecdoc_image` = '', |
42 | '', | 42 | '', |
43 | - concat('ital_origin/images/tecdoc/big/',`w_details_description`.`tecdoc_image`) | 43 | + concat('/storage/images/tecdoc/big/',`w_details_description`.`tecdoc_image`) |
44 | ), | 44 | ), |
45 | - concat('ital_origin/images/goods/big/',`w_details_description`.`image`) | 45 | + concat('/storage/images/goods/big/',`w_details_description`.`image`) |
46 | ) as `image`, | 46 | ) as `image`, |
47 | `w_details_description`.`tecdoc_id`, | 47 | `w_details_description`.`tecdoc_id`, |
48 | 48 |
frontend/controllers/GoodsController.php
@@ -16,49 +16,91 @@ use Yii; | @@ -16,49 +16,91 @@ use Yii; | ||
16 | use yii\web\Controller; | 16 | use yii\web\Controller; |
17 | use common\models\Details; | 17 | use common\models\Details; |
18 | 18 | ||
19 | -class GoodsController extends Controller { | 19 | +class GoodsController extends Controller |
20 | +{ | ||
20 | public $layout = '/internal'; | 21 | public $layout = '/internal'; |
21 | 22 | ||
22 | - public function actionIndex( $name , $id ) | 23 | + public function actionIndex($name, $id) |
23 | { | 24 | { |
24 | 25 | ||
25 | - | ||
26 | - $arr_name = explode('_',$name); | 26 | + $arr_name = explode('_', $name); |
27 | $brand = $arr_name[0]; | 27 | $brand = $arr_name[0]; |
28 | $article = $arr_name[1]; | 28 | $article = $arr_name[1]; |
29 | 29 | ||
30 | + $params = Yii::$app->request->getQueryParams(); | ||
31 | + | ||
32 | + // получим параметры сортировки из гет запроса | ||
33 | + $sort_params_or = $this->getSortParams($params, 'or'); | ||
34 | + $sort_params_cross = $this->getSortParams($params, 'cross'); | ||
30 | 35 | ||
31 | $arr_values = ['name' => $article, | 36 | $arr_values = ['name' => $article, |
32 | - 'brand' => $brand]; | 37 | + 'brand' => $brand]; |
33 | $arr = ['GoodsViewSearch' => $arr_values]; | 38 | $arr = ['GoodsViewSearch' => $arr_values]; |
34 | 39 | ||
35 | - if(empty( Yii::$app->user->identity )){ | 40 | + if (empty(Yii::$app->user->identity)) { |
36 | $margin_id = 1; | 41 | $margin_id = 1; |
37 | - }else{ | 42 | + } else { |
38 | $margin_id = Yii::$app->user->identity->margin_id; | 43 | $margin_id = Yii::$app->user->identity->margin_id; |
39 | } | 44 | } |
40 | 45 | ||
41 | -// $arr = ['GoodsViewSearch' => ['name' => '0092S40090', | ||
42 | -// 'brand' => 'BOSCH']]; | ||
43 | - | ||
44 | - | ||
45 | Yii::$app->session->setFlash('price_currency_id', 1); | 46 | Yii::$app->session->setFlash('price_currency_id', 1); |
46 | Yii::$app->session->setFlash('price_margin_id', $margin_id); | 47 | Yii::$app->session->setFlash('price_margin_id', $margin_id); |
47 | 48 | ||
48 | $searchModel = new GoodsViewSearch(); | 49 | $searchModel = new GoodsViewSearch(); |
49 | - $goods_provider = $searchModel->search($arr); | 50 | + $goods_provider = $searchModel->search($arr, $sort_params_or); |
50 | 51 | ||
51 | - $crosses_provider = $searchModel->searchCrosses($arr); | 52 | + $crosses_provider = $searchModel->searchCrosses($arr, $sort_params_cross); |
52 | 53 | ||
53 | // для заголовка таблицы (карточка товара) | 54 | // для заголовка таблицы (карточка товара) |
54 | $detailsModel = GoodsView::findOne($arr_values); | 55 | $detailsModel = GoodsView::findOne($arr_values); |
55 | 56 | ||
56 | - return $this->render('index',[ | 57 | + return $this->render('index', [ |
57 | 'goods_data_provider' => $goods_provider, | 58 | 'goods_data_provider' => $goods_provider, |
58 | 'crosses_data_provider' => $crosses_provider, | 59 | 'crosses_data_provider' => $crosses_provider, |
59 | 'detailsModel' => $detailsModel, | 60 | 'detailsModel' => $detailsModel, |
60 | ]); | 61 | ]); |
61 | } | 62 | } |
62 | 63 | ||
64 | + /** | ||
65 | + * @param $params - массив параметров для сортировки | ||
66 | + * @param $prefix - строка, перфикс таблицы сортировки (_or / _cross ) | ||
67 | + * @return массив - итоговый массив с параемтрами для сортировки который подставляется в запрос | ||
68 | + */ | ||
69 | + protected function getSortParams($params, $prefix) | ||
70 | + { | ||
71 | + $default_sort_params = ['price' => SORT_DESC]; | ||
72 | + $sort_params = []; | ||
73 | + | ||
74 | + if ( empty( $params['sort'] ) ) { | ||
75 | + // нет параметров - сортируем по цене по убыванию | ||
76 | + $sort_params = $default_sort_params; | ||
77 | + | ||
78 | + } else { | ||
79 | + // разбираем парметры | ||
80 | + $sort_arr = explode('_', $params['sort']); | ||
81 | + if ($sort_arr[1] === $prefix) { | ||
82 | + if ($sort_arr[0][0] === '-') { | ||
83 | + // если первый символ "-", то по убыванию | ||
84 | + $sort_arr[0] = str_replace('-', '', $sort_arr[0]); | ||
85 | + $sort_params[$sort_arr[0]] = SORT_ASC; | ||
86 | + } else { | ||
87 | + $sort_params[$sort_arr[0]] = SORT_DESC; | ||
88 | + } | ||
89 | + } | ||
90 | + if ( empty( $sort_params ) ) { | ||
91 | + // если так и ненашли подходящих параметров, значит сортируем другую таблицу | ||
92 | + // а для этой вытащим из кеша или дефолтная сортировка | ||
93 | + if ( Yii::$app->cache->exists( "sort_{$prefix}" ) ) { | ||
94 | + $sort_params = Yii::$app->cache->get( "sort_{$prefix}" ); | ||
95 | + } else { | ||
96 | + $sort_params = $default_sort_params; | ||
97 | + } | ||
98 | + } else { | ||
99 | + Yii::$app->cache->set( "sort_{$prefix}", $sort_params, 300 ); | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + return $sort_params; | ||
104 | + } | ||
63 | 105 | ||
64 | } | 106 | } |
65 | \ No newline at end of file | 107 | \ No newline at end of file |
frontend/views/goods/index.php
@@ -4,12 +4,13 @@ use \yii\helpers\Html; | @@ -4,12 +4,13 @@ use \yii\helpers\Html; | ||
4 | 4 | ||
5 | $sort = new Sort([ | 5 | $sort = new Sort([ |
6 | 'attributes' => [ | 6 | 'attributes' => [ |
7 | - 'box' => ['label' => 'Наличие'], | ||
8 | - 'delivery' => ['label' => 'Срок'], | ||
9 | - 'price' => [ | ||
10 | - 'asc' => ['price' => SORT_ASC ], | ||
11 | - 'desc' => ['price' => SORT_DESC], | ||
12 | - 'default' => SORT_DESC, | 7 | + 'box_or' => ['label' => 'Наличие'], |
8 | + 'delivery_or' => ['label' => 'Срок'], | ||
9 | + 'price_or' => [ | ||
10 | + 'label' => 'Цена'], | ||
11 | + 'box_cross' => ['label' => 'Наличие'], | ||
12 | + 'delivery_cross' => ['label' => 'Срок'], | ||
13 | + 'price_cross' => [ | ||
13 | 'label' => 'Цена'], | 14 | 'label' => 'Цена'], |
14 | ], | 15 | ], |
15 | ]); | 16 | ]); |
@@ -108,9 +109,9 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -108,9 +109,9 @@ $this->params['breadcrumbs'][] = $this->title; | ||
108 | <td class="medium_width row_name">Номер детали</td> | 109 | <td class="medium_width row_name">Номер детали</td> |
109 | <td class="large_width row_name">Описание</td> | 110 | <td class="large_width row_name">Описание</td> |
110 | <td class="row_select1 row_name"></td> | 111 | <td class="row_select1 row_name"></td> |
111 | - <td class="right_large row_name link_sort arrow_up"><?= $sort->link('box') ?></td> | ||
112 | - <td class="right_small row_name link_sort arrow_up"><?= $sort->link('delivery') ?></td> | ||
113 | - <td class="right_medium row_name link_sort arrow_up"><?= $sort->link('price') ?></td> | 112 | + <td class="right_large row_name link_sort arrow_up"><?= $sort->link('box_or') ?></td> |
113 | + <td class="right_small row_name link_sort arrow_up"><?= $sort->link('delivery_or') ?></td> | ||
114 | + <td class="right_medium row_name link_sort arrow_up"><?= $sort->link('price_or') ?></td> | ||
114 | 115 | ||
115 | </tr> | 116 | </tr> |
116 | <?php | 117 | <?php |
@@ -128,9 +129,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -128,9 +129,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
128 | </div> | 129 | </div> |
129 | <div class="second_section"> | 130 | <div class="second_section"> |
130 | <p class="bold_line">Замены искомого производителя</p> | 131 | <p class="bold_line">Замены искомого производителя</p> |
131 | - <p class="cross_currency opposite" id="cross_grivna">UAH</p> | ||
132 | - <p class="cross_currency active_button_purple1" id="cross_dollars">USD</p> | ||
133 | - <p class="cross_currency opposite" id="cross_euro">EUR</p> | 132 | + <p </p> |
134 | <table class="tovar_table" cellspacing="0" cellpadding="0" border="0"> | 133 | <table class="tovar_table" cellspacing="0" cellpadding="0" border="0"> |
135 | <tbody> | 134 | <tbody> |
136 | <tr class="name"> | 135 | <tr class="name"> |
@@ -138,9 +137,9 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -138,9 +137,9 @@ $this->params['breadcrumbs'][] = $this->title; | ||
138 | <td class="medium_width row_name">Номер детали</td> | 137 | <td class="medium_width row_name">Номер детали</td> |
139 | <td class="large_width row_name">Описание</td> | 138 | <td class="large_width row_name">Описание</td> |
140 | <td class="row_select1 row_name"></td> | 139 | <td class="row_select1 row_name"></td> |
141 | - <td class="right_large row_name link_sort arrow_up">Наличие</td> | ||
142 | - <td class="right_small row_name link_sort arrow_up">Срок</td> | ||
143 | - <td class="right_medium row_name link_sort arrow_up">Цена</td> | 140 | + <td class="right_large row_name link_sort arrow_up"><?= $sort->link('box_cross') ?></td> |
141 | + <td class="right_small row_name link_sort arrow_up"><?= $sort->link('delivery_cross') ?></td> | ||
142 | + <td class="right_medium row_name link_sort arrow_up"><?= $sort->link('price_cross') ?></td> | ||
144 | 143 | ||
145 | </tr> | 144 | </tr> |
146 | <?php | 145 | <?php |
frontend/views/goods/one_item.php
@@ -76,15 +76,15 @@ $cross_prefix = ( empty($model->crosses) )? '': '_cross'; | @@ -76,15 +76,15 @@ $cross_prefix = ( empty($model->crosses) )? '': '_cross'; | ||
76 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= $model->delivery?> дн.</td></tr> | 76 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= $model->delivery?> дн.</td></tr> |
77 | 77 | ||
78 | </table></td> | 78 | </table></td> |
79 | - <td class="usd<?=$cross_prefix?> right_medium"><table class="inner" border='0' style='border-top:0; border-left:0'> | 79 | + <td class="usd right_medium"><table class="inner" border='0' style='border-top:0; border-left:0'> |
80 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= \Yii::$app->formatter->asDecimal( $model->outputPriceUSD )?></td></tr> | 80 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= \Yii::$app->formatter->asDecimal( $model->outputPriceUSD )?></td></tr> |
81 | 81 | ||
82 | </table></td> | 82 | </table></td> |
83 | - <td class="hidden uah<?=$cross_prefix?> right_medium"><table class="inner" border='0' style='border-top:0; border-left:0'> | 83 | + <td class="hidden uah right_medium"><table class="inner" border='0' style='border-top:0; border-left:0'> |
84 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= \Yii::$app->formatter->asDecimal( $model->outputPriceUAH )?></td></tr> | 84 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= \Yii::$app->formatter->asDecimal( $model->outputPriceUAH )?></td></tr> |
85 | 85 | ||
86 | </table></td> | 86 | </table></td> |
87 | - <td class="hidden eur<?=$cross_prefix?> right_medium"><table class="inner" border='0' style='border-top:0; border-left:0'> | 87 | + <td class="hidden eur right_medium"><table class="inner" border='0' style='border-top:0; border-left:0'> |
88 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= \Yii::$app->formatter->asDecimal( $model->outputPriceEUR )?></td></tr> | 88 | <tr border='0' style='border-top:0; border-left:0'><td border='0' style='border-top:0; border-left:0'><?= \Yii::$app->formatter->asDecimal( $model->outputPriceEUR )?></td></tr> |
89 | 89 | ||
90 | </table></td> | 90 | </table></td> |
frontend/web/css/BC2_catalog_zapchasti.css
@@ -124,22 +124,6 @@ | @@ -124,22 +124,6 @@ | ||
124 | position: relative; | 124 | position: relative; |
125 | text-align: center; | 125 | text-align: center; |
126 | } | 126 | } |
127 | -.cross_currency{ | ||
128 | - display:inline-block; | ||
129 | - | ||
130 | - font-weight: normal; | ||
131 | - color: #6c83b5; | ||
132 | - height: 21px; | ||
133 | - width: 36px; | ||
134 | - border-radius: 4px 0 0 4px; | ||
135 | - border: 1px solid #efeff0; | ||
136 | - background-color: #efeff0; | ||
137 | - cursor: pointer; | ||
138 | - float:right; | ||
139 | - display: inline-block; | ||
140 | - position: relative; | ||
141 | - text-align: center; | ||
142 | -} | ||
143 | 127 | ||
144 | .currency1{ | 128 | .currency1{ |
145 | display:inline-block; | 129 | display:inline-block; |
frontend/web/js/goods.js
@@ -31,33 +31,33 @@ $( document ).ready(function() { | @@ -31,33 +31,33 @@ $( document ).ready(function() { | ||
31 | 31 | ||
32 | 32 | ||
33 | function changeEUR(){ | 33 | function changeEUR(){ |
34 | - if( $(this).hasClass('cross_currency') ){ | ||
35 | - cross_prefix = '_cross'; | ||
36 | - }else{ | ||
37 | - cross_prefix = ''; | ||
38 | - } | 34 | + //if( $(this).hasClass('cross_currency') ){ |
35 | + // cross_prefix = '_cross'; | ||
36 | + //}else{ | ||
37 | + // cross_prefix = ''; | ||
38 | + //} | ||
39 | 39 | ||
40 | show_currency = ['eur']; | 40 | show_currency = ['eur']; |
41 | hidden_currency = ['uah','usd']; | 41 | hidden_currency = ['uah','usd']; |
42 | setVisiblePrice(); | 42 | setVisiblePrice(); |
43 | } | 43 | } |
44 | function changeUAH(){ | 44 | function changeUAH(){ |
45 | - if( $(this).hasClass('cross_currency') ){ | ||
46 | - cross_prefix = '_cross'; | ||
47 | - }else{ | ||
48 | - cross_prefix = ''; | ||
49 | - } | 45 | + //if( $(this).hasClass('cross_currency') ){ |
46 | + // cross_prefix = '_cross'; | ||
47 | + //}else{ | ||
48 | + // cross_prefix = ''; | ||
49 | + //} | ||
50 | 50 | ||
51 | show_currency = ['uah']; | 51 | show_currency = ['uah']; |
52 | hidden_currency = ['eur','usd']; | 52 | hidden_currency = ['eur','usd']; |
53 | setVisiblePrice(); | 53 | setVisiblePrice(); |
54 | } | 54 | } |
55 | function changeUSD(){ | 55 | function changeUSD(){ |
56 | - if( $(this).hasClass('cross_currency') ){ | ||
57 | - cross_prefix = '_cross'; | ||
58 | - }else{ | ||
59 | - cross_prefix = ''; | ||
60 | - } | 56 | + //if( $(this).hasClass('cross_currency') ){ |
57 | + // cross_prefix = '_cross'; | ||
58 | + //}else{ | ||
59 | + // cross_prefix = ''; | ||
60 | + //} | ||
61 | 61 | ||
62 | show_currency = ['usd']; | 62 | show_currency = ['usd']; |
63 | hidden_currency = ['uah','eur']; | 63 | hidden_currency = ['uah','eur']; |
frontend/web/js/script.js
@@ -557,12 +557,7 @@ $('.currency').click(function(){ | @@ -557,12 +557,7 @@ $('.currency').click(function(){ | ||
557 | 557 | ||
558 | } | 558 | } |
559 | ); | 559 | ); |
560 | - $('.cross_currency').click(function(){ | ||
561 | - $('.cross_currency').removeClass('active_button_purple1'); | ||
562 | - $(this).addClass('active_button_purple1'); | ||
563 | 560 | ||
564 | -} | ||
565 | -); | ||
566 | $('.menu_block_center .menu_item').hover(function(){ | 561 | $('.menu_block_center .menu_item').hover(function(){ |
567 | $(this).find('p').addClass('pcolor')}, | 562 | $(this).find('p').addClass('pcolor')}, |
568 | function(){ | 563 | function(){ |