Commit 896400091580f8060e87950c4f28945466797ee1
1 parent
40e4f314
add sort function on goods view
Showing
6 changed files
with
98 additions
and
66 deletions
Show diff stats
console/migrations/m151219_103804_goods_view.php
@@ -17,7 +17,7 @@ class m151219_103804_goods_view extends Migration | @@ -17,7 +17,7 @@ class m151219_103804_goods_view extends Migration | ||
17 | `w_importers`.`name` as `importer_name`, | 17 | `w_importers`.`name` as `importer_name`, |
18 | `t`.`rate` as rate, | 18 | `t`.`rate` as rate, |
19 | `t`.`id` as currency_id, | 19 | `t`.`id` as currency_id, |
20 | - `w_importers`.`delivery`, | 20 | + CAST(`w_importers`.`delivery` AS UNSIGNED ) as delivery, |
21 | if (`w_details_description`.`description` = '', | 21 | if (`w_details_description`.`description` = '', |
22 | if (`w_details_description`.`tecdoc_description` = '', | 22 | if (`w_details_description`.`tecdoc_description` = '', |
23 | `w_details_description`.`supplier_description`, | 23 | `w_details_description`.`supplier_description`, |
frontend/controllers/GoodsController.php
@@ -22,12 +22,10 @@ class GoodsController extends Controller | @@ -22,12 +22,10 @@ class GoodsController extends Controller | ||
22 | 22 | ||
23 | public function actionIndex($name, $id) | 23 | public function actionIndex($name, $id) |
24 | { | 24 | { |
25 | - | ||
26 | $arr_name = explode('_', $name); | 25 | $arr_name = explode('_', $name); |
27 | $brand = $arr_name[0]; | 26 | $brand = $arr_name[0]; |
28 | $article = $arr_name[1]; | 27 | $article = $arr_name[1]; |
29 | 28 | ||
30 | - | ||
31 | $params = Yii::$app->request->getQueryParams(); | 29 | $params = Yii::$app->request->getQueryParams(); |
32 | 30 | ||
33 | // получим параметры сортировки из гет запроса | 31 | // получим параметры сортировки из гет запроса |
@@ -38,15 +36,12 @@ class GoodsController extends Controller | @@ -38,15 +36,12 @@ class GoodsController extends Controller | ||
38 | 'brand' => $brand]; | 36 | 'brand' => $brand]; |
39 | $arr = ['GoodsViewSearch' => $arr_values]; | 37 | $arr = ['GoodsViewSearch' => $arr_values]; |
40 | 38 | ||
41 | - if(empty( Yii::$app->user->identity )){ | 39 | + if (empty(Yii::$app->user->identity)) { |
42 | $margin_id = 1; | 40 | $margin_id = 1; |
43 | - }else{ | 41 | + } else { |
44 | $margin_id = Yii::$app->user->identity->margin_id; | 42 | $margin_id = Yii::$app->user->identity->margin_id; |
45 | } | 43 | } |
46 | 44 | ||
47 | -// $arr = ['GoodsViewSearch' => ['name' => '0092S40090', | ||
48 | -// 'brand' => 'BOSCH']]; | ||
49 | - | ||
50 | if (empty(Yii::$app->user->identity)) { | 45 | if (empty(Yii::$app->user->identity)) { |
51 | $margin_id = 1; | 46 | $margin_id = 1; |
52 | } else { | 47 | } else { |
@@ -68,6 +63,8 @@ class GoodsController extends Controller | @@ -68,6 +63,8 @@ class GoodsController extends Controller | ||
68 | 'goods_data_provider' => $goods_provider, | 63 | 'goods_data_provider' => $goods_provider, |
69 | 'crosses_data_provider' => $crosses_provider, | 64 | 'crosses_data_provider' => $crosses_provider, |
70 | 'detailsModel' => $detailsModel, | 65 | 'detailsModel' => $detailsModel, |
66 | + 'sort_params_or' => $sort_params_or, | ||
67 | + 'sort_params_cross' => $sort_params_cross, | ||
71 | ]); | 68 | ]); |
72 | } | 69 | } |
73 | 70 | ||
@@ -81,7 +78,7 @@ class GoodsController extends Controller | @@ -81,7 +78,7 @@ class GoodsController extends Controller | ||
81 | $default_sort_params = ['price' => SORT_DESC]; | 78 | $default_sort_params = ['price' => SORT_DESC]; |
82 | $sort_params = []; | 79 | $sort_params = []; |
83 | 80 | ||
84 | - if ( empty( $params['sort'] ) ) { | 81 | + if (empty($params['sort'])) { |
85 | // нет параметров - сортируем по цене по убыванию | 82 | // нет параметров - сортируем по цене по убыванию |
86 | $sort_params = $default_sort_params; | 83 | $sort_params = $default_sort_params; |
87 | 84 | ||
@@ -98,19 +95,11 @@ class GoodsController extends Controller | @@ -98,19 +95,11 @@ class GoodsController extends Controller | ||
98 | } | 95 | } |
99 | } | 96 | } |
100 | if ( empty( $sort_params ) ) { | 97 | if ( empty( $sort_params ) ) { |
101 | - //$price_margin_id = Yii::$app->session->getFlash('price_margin_id',1); | ||
102 | // если так и ненашли подходящих параметров, значит сортируем другую таблицу | 98 | // если так и ненашли подходящих параметров, значит сортируем другую таблицу |
103 | - // а для этой вытащим из кеша или дефолтная сортировка | ||
104 | - if ( Yii::$app->cache->exists( "sort_{$prefix}" ) ) { | ||
105 | - $sort_params = Yii::$app->cache->get( "sort_{$prefix}" ); | ||
106 | - } else { | ||
107 | - $sort_params = $default_sort_params; | ||
108 | - } | ||
109 | - } else { | ||
110 | - Yii::$app->cache->set( "sort_{$prefix}", $sort_params, 300 ); | 99 | + // а для этой дефолтная сортировка |
100 | + $sort_params = $default_sort_params; | ||
111 | } | 101 | } |
112 | } | 102 | } |
113 | - | ||
114 | return $sort_params; | 103 | return $sort_params; |
115 | } | 104 | } |
116 | 105 |
frontend/views/goods/index.php
@@ -8,10 +8,12 @@ $sort = new Sort([ | @@ -8,10 +8,12 @@ $sort = new Sort([ | ||
8 | 'box_or' => ['label' => 'Наличие'], | 8 | 'box_or' => ['label' => 'Наличие'], |
9 | 'delivery_or' => ['label' => 'Срок'], | 9 | 'delivery_or' => ['label' => 'Срок'], |
10 | 'price_or' => [ | 10 | 'price_or' => [ |
11 | + 'default' => SORT_DESC, | ||
11 | 'label' => 'Цена'], | 12 | 'label' => 'Цена'], |
12 | 'box_cross' => ['label' => 'Наличие'], | 13 | 'box_cross' => ['label' => 'Наличие'], |
13 | 'delivery_cross' => ['label' => 'Срок'], | 14 | 'delivery_cross' => ['label' => 'Срок'], |
14 | 'price_cross' => [ | 15 | 'price_cross' => [ |
16 | + 'default' => SORT_DESC, | ||
15 | 'label' => 'Цена'], | 17 | 'label' => 'Цена'], |
16 | ], | 18 | ], |
17 | ]); | 19 | ]); |
@@ -20,7 +22,41 @@ $this->registerJsFile('/js/jquery.tablesorter.min.js'); | @@ -20,7 +22,41 @@ $this->registerJsFile('/js/jquery.tablesorter.min.js'); | ||
20 | $this->registerJsFile('/js/goods.js'); | 22 | $this->registerJsFile('/js/goods.js'); |
21 | 23 | ||
22 | $this->params['breadcrumbs'][] = $this->title; | 24 | $this->params['breadcrumbs'][] = $this->title; |
23 | -Pjax::begin(); | 25 | + |
26 | +// определим направление сортировки, для отображения стрелочек | ||
27 | +// для оригинальной таблицы | ||
28 | +if( empty($sort_params_or['price']) ){ | ||
29 | + $price_or_class = ''; | ||
30 | +}else{ | ||
31 | + $price_or_class = ($sort_params_or['price'] == 4)? 'arrow_up': 'arrow_downA'; | ||
32 | +} | ||
33 | +if( empty($sort_params_or['delivery']) ){ | ||
34 | + $delivery_or_class = ''; | ||
35 | +}else{ | ||
36 | + $delivery_or_class = ($sort_params_or['delivery'] == 4)? 'arrow_up': 'arrow_downA'; | ||
37 | +} | ||
38 | +if( empty($sort_params_or['box']) ){ | ||
39 | + $box_or_class = ''; | ||
40 | +}else{ | ||
41 | + $box_or_class = ($sort_params_or['box'] == 4)? 'arrow_up': 'arrow_downA'; | ||
42 | +} | ||
43 | +// для кросс таблицы | ||
44 | +if( empty($sort_params_cross['price']) ){ | ||
45 | + $price_cross_class = ''; | ||
46 | +}else{ | ||
47 | + $price_cross_class = ($sort_params_cross['price'] == 4)? 'arrow_up': 'arrow_downA'; | ||
48 | +} | ||
49 | +if( empty($sort_params_cross['delivery']) ){ | ||
50 | + $delivery_cross_class = ''; | ||
51 | +}else{ | ||
52 | + $delivery_cross_class = ($sort_params_cross['delivery'] == 4)? 'arrow_up': 'arrow_downA'; | ||
53 | +} | ||
54 | +if( empty($sort_params_cross['box']) ){ | ||
55 | + $box_cross_class = ''; | ||
56 | +}else{ | ||
57 | + $box_cross_class = ($sort_params_cross['box'] == 4)? 'arrow_up': 'arrow_downA'; | ||
58 | +} | ||
59 | + | ||
24 | ?> | 60 | ?> |
25 | 61 | ||
26 | 62 | ||
@@ -106,15 +142,16 @@ Pjax::begin(); | @@ -106,15 +142,16 @@ Pjax::begin(); | ||
106 | <p class="currency opposite" id="grivna">UAH</p> | 142 | <p class="currency opposite" id="grivna">UAH</p> |
107 | <p class="currency active_button_purple1" id="dollars">USD</p> | 143 | <p class="currency active_button_purple1" id="dollars">USD</p> |
108 | <p class="currency opposite" id="euro">EUR</p> | 144 | <p class="currency opposite" id="euro">EUR</p> |
145 | + <?php Pjax::begin(['id' => 'original']); ?> | ||
109 | <table class="tovar_table" cellspacing="0" cellpadding="0" border="0"> | 146 | <table class="tovar_table" cellspacing="0" cellpadding="0" border="0"> |
110 | <tbody><tr class="name"> | 147 | <tbody><tr class="name"> |
111 | <td class="small_width row_name">Фирма</td> | 148 | <td class="small_width row_name">Фирма</td> |
112 | <td class="medium_width row_name">Номер детали</td> | 149 | <td class="medium_width row_name">Номер детали</td> |
113 | <td class="large_width row_name">Описание</td> | 150 | <td class="large_width row_name">Описание</td> |
114 | <td class="row_select1 row_name"></td> | 151 | <td class="row_select1 row_name"></td> |
115 | - <td class="right_large row_name link_sort arrow_up"><?= $sort->link('box_or') ?></td> | ||
116 | - <td class="right_small row_name link_sort arrow_up"><?= $sort->link('delivery_or') ?></td> | ||
117 | - <td class="right_medium row_name link_sort arrow_up"><?= $sort->link('price_or') ?></td> | 152 | + <td class="right_large row_name link_sort <?= $box_or_class ?>"><?= $sort->link('box_or') ?></td> |
153 | + <td class="right_small row_name link_sort <?= $delivery_or_class ?>"><?= $sort->link('delivery_or') ?></td> | ||
154 | + <td class="right_medium row_name link_sort <?= $price_or_class ?>"><?= $sort->link('price_or') ?></td> | ||
118 | </tr> | 155 | </tr> |
119 | <?php | 156 | <?php |
120 | echo \yii\widgets\ListView::widget([ | 157 | echo \yii\widgets\ListView::widget([ |
@@ -126,9 +163,11 @@ Pjax::begin(); | @@ -126,9 +163,11 @@ Pjax::begin(); | ||
126 | ?> | 163 | ?> |
127 | 164 | ||
128 | </tbody></table> | 165 | </tbody></table> |
129 | - | 166 | + <?php Pjax::end();?> |
130 | 167 | ||
131 | </div> | 168 | </div> |
169 | + | ||
170 | + <?php Pjax::begin(['id' => 'cross']); ?> | ||
132 | <div class="second_section"> | 171 | <div class="second_section"> |
133 | <p class="bold_line">Замены искомого производителя</p> | 172 | <p class="bold_line">Замены искомого производителя</p> |
134 | <p </p> | 173 | <p </p> |
@@ -139,9 +178,9 @@ Pjax::begin(); | @@ -139,9 +178,9 @@ Pjax::begin(); | ||
139 | <td class="medium_width row_name">Номер детали</td> | 178 | <td class="medium_width row_name">Номер детали</td> |
140 | <td class="large_width row_name">Описание</td> | 179 | <td class="large_width row_name">Описание</td> |
141 | <td class="row_select1 row_name"></td> | 180 | <td class="row_select1 row_name"></td> |
142 | - <td class="right_large row_name link_sort arrow_up"><?= $sort->link('box_cross') ?></td> | ||
143 | - <td class="right_small row_name link_sort arrow_up"><?= $sort->link('delivery_cross') ?></td> | ||
144 | - <td class="right_medium row_name link_sort arrow_up"><?= $sort->link('price_cross') ?></td> | 181 | + <td class="right_large row_name link_sort <?= $box_cross_class ?>"><?= $sort->link('box_cross') ?></td> |
182 | + <td class="right_small row_name link_sort <?= $delivery_cross_class ?>"><?= $sort->link('delivery_cross') ?></td> | ||
183 | + <td class="right_medium row_name link_sort <?= $price_cross_class ?>"><?= $sort->link('price_cross') ?></td> | ||
145 | </tr> | 184 | </tr> |
146 | <?php | 185 | <?php |
147 | echo \yii\widgets\ListView::widget([ | 186 | echo \yii\widgets\ListView::widget([ |
@@ -157,12 +196,11 @@ Pjax::begin(); | @@ -157,12 +196,11 @@ Pjax::begin(); | ||
157 | <img src="/images/yellow_squere.jpg"><p>В наличии на центральном складе ItalAuto, в Киеве</p> | 196 | <img src="/images/yellow_squere.jpg"><p>В наличии на центральном складе ItalAuto, в Киеве</p> |
158 | </div> | 197 | </div> |
159 | </div> | 198 | </div> |
199 | + <?php Pjax::end();?> | ||
160 | </div> | 200 | </div> |
161 | 201 | ||
162 | </div> | 202 | </div> |
163 | -<?php | ||
164 | -Pjax::end(); | ||
165 | -?> | 203 | + |
166 | 204 | ||
167 | 205 | ||
168 | <div class="modal fade" id="details_content_block" > | 206 | <div class="modal fade" id="details_content_block" > |
17.4 KB
frontend/web/js/goods.js
1 | $(document).ready(function () { | 1 | $(document).ready(function () { |
2 | // для таблицы кроссов, классы обозначаются через cross_ | 2 | // для таблицы кроссов, классы обозначаются через cross_ |
3 | var cross_prefix = ''; | 3 | var cross_prefix = ''; |
4 | - | ||
5 | // по умолчанию - цены в долларах, остальные скрываем | 4 | // по умолчанию - цены в долларах, остальные скрываем |
6 | var show_currency = ['usd']; | 5 | var show_currency = ['usd']; |
7 | var hidden_currency = ['uah', 'eur']; | 6 | var hidden_currency = ['uah', 'eur']; |
8 | 7 | ||
8 | + // первоначальная инициация цен | ||
9 | + priceInitialisation(); | ||
10 | + | ||
11 | + // привяжем обработчик смены валюты | ||
9 | $(document).on("click", ".currency", changeCurrency); | 12 | $(document).on("click", ".currency", changeCurrency); |
10 | 13 | ||
11 | - function changeCurrency() { | 14 | + // привяжем обработчик обновления страницы pjax |
15 | + $(document).on('pjax:complete', function() { | ||
16 | + console.log(document.location); | ||
17 | + priceInitialisation(); | ||
18 | + }) | ||
12 | 19 | ||
13 | - if ($(this).attr('id') === 'grivna') { | ||
14 | - show_currency = ['uah']; | ||
15 | - hidden_currency = ['eur', 'usd']; | ||
16 | - } else if ($(this).attr('id') === 'euro') { | ||
17 | - show_currency = ['eur']; | ||
18 | - hidden_currency = ['uah', 'usd']; | ||
19 | - } else if ($(this).attr('id') === 'dollars') { | ||
20 | - show_currency = ['usd']; | ||
21 | - hidden_currency = ['uah', 'eur']; | ||
22 | - } | 20 | + |
21 | + function changeCurrency() { | ||
23 | $('.currency').removeClass('active_button_purple1'); | 22 | $('.currency').removeClass('active_button_purple1'); |
24 | $(this).addClass('active_button_purple1'); | 23 | $(this).addClass('active_button_purple1'); |
24 | + // после смены валюты - покажем цены в выбранной валюте | ||
25 | + priceInitialisation(); | ||
26 | + } | ||
25 | 27 | ||
26 | - setVisiblePrice(); | 28 | + function priceInitialisation() { |
29 | + | ||
30 | + // найдем текущую установленную валюту, и пересчитаем цены в ней | ||
31 | + var current_currency = $('.active_button_purple1')[0]; | ||
32 | + if (typeof current_currency === 'object'){ | ||
33 | + | ||
34 | + if (current_currency.getAttribute('id') === 'grivna') { | ||
35 | + show_currency = ['uah']; | ||
36 | + hidden_currency = ['eur', 'usd']; | ||
37 | + } else if (current_currency.getAttribute('id') === 'euro') { | ||
38 | + show_currency = ['eur']; | ||
39 | + hidden_currency = ['uah', 'usd']; | ||
40 | + } else if (current_currency.getAttribute('id') === 'dollars') { | ||
41 | + show_currency = ['usd']; | ||
42 | + hidden_currency = ['uah', 'eur']; | ||
43 | + } | ||
44 | + setVisiblePrice(); | ||
45 | + } | ||
27 | } | 46 | } |
28 | 47 | ||
29 | function setVisiblePrice() { | 48 | function setVisiblePrice() { |
@@ -72,7 +91,7 @@ $(document).ready(function () { | @@ -72,7 +91,7 @@ $(document).ready(function () { | ||
72 | } | 91 | } |
73 | ); | 92 | ); |
74 | }); | 93 | }); |
75 | - | 94 | + |
76 | //открытие-закрытие карточки товара и смена текста на бирке карточки товара | 95 | //открытие-закрытие карточки товара и смена текста на бирке карточки товара |
77 | function changeText() { | 96 | function changeText() { |
78 | e = document.getElementById('button_grey_card'); | 97 | e = document.getElementById('button_grey_card'); |
@@ -85,15 +104,16 @@ $(document).ready(function () { | @@ -85,15 +104,16 @@ $(document).ready(function () { | ||
85 | $('.tovar_card').toggleClass('tovar_card_visible'); | 104 | $('.tovar_card').toggleClass('tovar_card_visible'); |
86 | $('.table').toggleClass('table_height'); | 105 | $('.table').toggleClass('table_height'); |
87 | }); | 106 | }); |
107 | + // модальная форма с инфой по тех-доку | ||
108 | + $(document).on("click", '.tecdoc_id_info', function(e){ | ||
109 | + var tecdoc_id = $(this).data('id'); | ||
110 | + $.post( "/detail/get-details-for-item", {tecdoc_id:tecdoc_id},function( data ) { | ||
111 | + $('#details_content').empty(); | ||
112 | + $('#details_content').html(data); | ||
88 | 113 | ||
89 | - //стрелочки вниз | ||
90 | - $(document).on( "click",'.link_sort', function () { | ||
91 | - | ||
92 | - $(this).find('.desc').toggleClass('arrow_downA'); | ||
93 | - | ||
94 | - }) | 114 | + }); |
95 | 115 | ||
96 | -}); | 116 | + });}); |
97 | 117 | ||
98 | 118 | ||
99 | 119 |
frontend/web/js/main.js
@@ -51,19 +51,4 @@ $(document).ready(function(){ | @@ -51,19 +51,4 @@ $(document).ready(function(){ | ||
51 | 51 | ||
52 | 52 | ||
53 | }); | 53 | }); |
54 | - | ||
55 | - $('.tecdoc_id_info').click(function(e){ | ||
56 | - var tecdoc_id = $(this).data('id'); | ||
57 | - $.post( "/detail/get-details-for-item", {tecdoc_id:tecdoc_id},function( data ) { | ||
58 | - $('#details_content').empty(); | ||
59 | - $('#details_content').html(data); | ||
60 | - | ||
61 | - | ||
62 | - }); | ||
63 | - | ||
64 | - }); | ||
65 | - | ||
66 | - | ||
67 | - | ||
68 | - | ||
69 | }); | 54 | }); |