Commit 896400091580f8060e87950c4f28945466797ee1

Authored by Mihail
1 parent 40e4f314

add sort function on goods view

console/migrations/m151219_103804_goods_view.php
... ... @@ -17,7 +17,7 @@ class m151219_103804_goods_view extends Migration
17 17 `w_importers`.`name` as `importer_name`,
18 18 `t`.`rate` as rate,
19 19 `t`.`id` as currency_id,
20   - `w_importers`.`delivery`,
  20 + CAST(`w_importers`.`delivery` AS UNSIGNED ) as delivery,
21 21 if (`w_details_description`.`description` = '',
22 22 if (`w_details_description`.`tecdoc_description` = '',
23 23 `w_details_description`.`supplier_description`,
... ...
frontend/controllers/GoodsController.php
... ... @@ -22,12 +22,10 @@ class GoodsController extends Controller
22 22  
23 23 public function actionIndex($name, $id)
24 24 {
25   -
26 25 $arr_name = explode('_', $name);
27 26 $brand = $arr_name[0];
28 27 $article = $arr_name[1];
29 28  
30   -
31 29 $params = Yii::$app->request->getQueryParams();
32 30  
33 31 // получим параметры сортировки из гет запроса
... ... @@ -38,15 +36,12 @@ class GoodsController extends Controller
38 36 'brand' => $brand];
39 37 $arr = ['GoodsViewSearch' => $arr_values];
40 38  
41   - if(empty( Yii::$app->user->identity )){
  39 + if (empty(Yii::$app->user->identity)) {
42 40 $margin_id = 1;
43   - }else{
  41 + } else {
44 42 $margin_id = Yii::$app->user->identity->margin_id;
45 43 }
46 44  
47   -// $arr = ['GoodsViewSearch' => ['name' => '0092S40090',
48   -// 'brand' => 'BOSCH']];
49   -
50 45 if (empty(Yii::$app->user->identity)) {
51 46 $margin_id = 1;
52 47 } else {
... ... @@ -68,6 +63,8 @@ class GoodsController extends Controller
68 63 'goods_data_provider' => $goods_provider,
69 64 'crosses_data_provider' => $crosses_provider,
70 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 78 $default_sort_params = ['price' => SORT_DESC];
82 79 $sort_params = [];
83 80  
84   - if ( empty( $params['sort'] ) ) {
  81 + if (empty($params['sort'])) {
85 82 // нет параметров - сортируем по цене по убыванию
86 83 $sort_params = $default_sort_params;
87 84  
... ... @@ -98,19 +95,11 @@ class GoodsController extends Controller
98 95 }
99 96 }
100 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 103 return $sort_params;
115 104 }
116 105  
... ...
frontend/views/goods/index.php
... ... @@ -8,10 +8,12 @@ $sort = new Sort([
8 8 'box_or' => ['label' => 'Наличие'],
9 9 'delivery_or' => ['label' => 'Срок'],
10 10 'price_or' => [
  11 + 'default' => SORT_DESC,
11 12 'label' => 'Цена'],
12 13 'box_cross' => ['label' => 'Наличие'],
13 14 'delivery_cross' => ['label' => 'Срок'],
14 15 'price_cross' => [
  16 + 'default' => SORT_DESC,
15 17 'label' => 'Цена'],
16 18 ],
17 19 ]);
... ... @@ -20,7 +22,41 @@ $this->registerJsFile('/js/jquery.tablesorter.min.js');
20 22 $this->registerJsFile('/js/goods.js');
21 23  
22 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 142 <p class="currency opposite" id="grivna">UAH</p>
107 143 <p class="currency active_button_purple1" id="dollars">USD</p>
108 144 <p class="currency opposite" id="euro">EUR</p>
  145 + <?php Pjax::begin(['id' => 'original']); ?>
109 146 <table class="tovar_table" cellspacing="0" cellpadding="0" border="0">
110 147 <tbody><tr class="name">
111 148 <td class="small_width row_name">Фирма</td>
112 149 <td class="medium_width row_name">Номер детали</td>
113 150 <td class="large_width row_name">Описание</td>
114 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 155 </tr>
119 156 <?php
120 157 echo \yii\widgets\ListView::widget([
... ... @@ -126,9 +163,11 @@ Pjax::begin();
126 163 ?>
127 164  
128 165 </tbody></table>
129   -
  166 + <?php Pjax::end();?>
130 167  
131 168 </div>
  169 +
  170 + <?php Pjax::begin(['id' => 'cross']); ?>
132 171 <div class="second_section">
133 172 <p class="bold_line">Замены искомого производителя</p>
134 173 <p </p>
... ... @@ -139,9 +178,9 @@ Pjax::begin();
139 178 <td class="medium_width row_name">Номер детали</td>
140 179 <td class="large_width row_name">Описание</td>
141 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 184 </tr>
146 185 <?php
147 186 echo \yii\widgets\ListView::widget([
... ... @@ -157,12 +196,11 @@ Pjax::begin();
157 196 <img src="/images/yellow_squere.jpg"><p>В наличии на центральном складе ItalAuto, в Киеве</p>
158 197 </div>
159 198 </div>
  199 + <?php Pjax::end();?>
160 200 </div>
161 201  
162 202 </div>
163   -<?php
164   -Pjax::end();
165   -?>
  203 +
166 204  
167 205  
168 206 <div class="modal fade" id="details_content_block" >
... ...
frontend/web/images/icon2r.png 0 → 100644

17.4 KB

frontend/web/js/goods.js
1 1 $(document).ready(function () {
2 2 // для таблицы кроссов, классы обозначаются через cross_
3 3 var cross_prefix = '';
4   -
5 4 // по умолчанию - цены в долларах, остальные скрываем
6 5 var show_currency = ['usd'];
7 6 var hidden_currency = ['uah', 'eur'];
8 7  
  8 + // первоначальная инициация цен
  9 + priceInitialisation();
  10 +
  11 + // привяжем обработчик смены валюты
9 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 22 $('.currency').removeClass('active_button_purple1');
24 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 48 function setVisiblePrice() {
... ... @@ -72,7 +91,7 @@ $(document).ready(function () {
72 91 }
73 92 );
74 93 });
75   -
  94 +
76 95 //открытие-закрытие карточки товара и смена текста на бирке карточки товара
77 96 function changeText() {
78 97 e = document.getElementById('button_grey_card');
... ... @@ -85,15 +104,16 @@ $(document).ready(function () {
85 104 $('.tovar_card').toggleClass('tovar_card_visible');
86 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 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 });
... ...