Commit 8f02e664a73e5ebe4ff634f6f6ccabbf8565a4a1

Authored by Mihail
1 parent b13c67c3

add multisort functional in goods controller

common/models/GoodsViewSearch.php
... ... @@ -38,7 +38,7 @@ class GoodsViewSearch extends GoodsView
38 38 *
39 39 * @return ActiveDataProvider
40 40 */
41   - public function search($params)
  41 + public function search( $params, $sort )
42 42 {
43 43 $query = GoodsView::find();
44 44  
... ... @@ -53,7 +53,8 @@ class GoodsViewSearch extends GoodsView
53 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 59 $dataProvider = new ActiveDataProvider([
59 60 'query' => $query,
... ... @@ -62,7 +63,7 @@ class GoodsViewSearch extends GoodsView
62 63  
63 64 return $dataProvider;
64 65 }
65   - public function searchCrosses($params)
  66 + public function searchCrosses( $params, $sort )
66 67 {
67 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 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 83 $dataProvider = new ActiveDataProvider([
83 84 'query' => $query,
... ...
console/migrations/m151219_103804_goods_view.php
... ... @@ -40,9 +40,9 @@ class m151219_103804_goods_view extends Migration
40 40 if (`w_details_description`.`image` = '',
41 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 46 ) as `image`,
47 47 `w_details_description`.`tecdoc_id`,
48 48  
... ...
frontend/controllers/GoodsController.php
... ... @@ -16,49 +16,91 @@ use Yii;
16 16 use yii\web\Controller;
17 17 use common\models\Details;
18 18  
19   -class GoodsController extends Controller {
  19 +class GoodsController extends Controller
  20 +{
20 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 27 $brand = $arr_name[0];
28 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 36 $arr_values = ['name' => $article,
32   - 'brand' => $brand];
  37 + 'brand' => $brand];
33 38 $arr = ['GoodsViewSearch' => $arr_values];
34 39  
35   - if(empty( Yii::$app->user->identity )){
  40 + if (empty(Yii::$app->user->identity)) {
36 41 $margin_id = 1;
37   - }else{
  42 + } else {
38 43 $margin_id = Yii::$app->user->identity->margin_id;
39 44 }
40 45  
41   -// $arr = ['GoodsViewSearch' => ['name' => '0092S40090',
42   -// 'brand' => 'BOSCH']];
43   -
44   -
45 46 Yii::$app->session->setFlash('price_currency_id', 1);
46 47 Yii::$app->session->setFlash('price_margin_id', $margin_id);
47 48  
48 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 55 $detailsModel = GoodsView::findOne($arr_values);
55 56  
56   - return $this->render('index',[
  57 + return $this->render('index', [
57 58 'goods_data_provider' => $goods_provider,
58 59 'crosses_data_provider' => $crosses_provider,
59 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 107 \ No newline at end of file
... ...
frontend/views/goods/index.php
... ... @@ -4,12 +4,13 @@ use \yii\helpers\Html;
4 4  
5 5 $sort = new Sort([
6 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 14 'label' => 'ะฆะตะฝะฐ'],
14 15 ],
15 16 ]);
... ... @@ -108,9 +109,9 @@ $this->params['breadcrumbs'][] = $this->title;
108 109 <td class="medium_width row_name">ะะพะผะตั€ ะดะตั‚ะฐะปะธ</td>
109 110 <td class="large_width row_name">ะžะฟะธัะฐะฝะธะต</td>
110 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 116 </tr>
116 117 <?php
... ... @@ -128,9 +129,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
128 129 </div>
129 130 <div class="second_section">
130 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 133 <table class="tovar_table" cellspacing="0" cellpadding="0" border="0">
135 134 <tbody>
136 135 <tr class="name">
... ... @@ -138,9 +137,9 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
138 137 <td class="medium_width row_name">ะะพะผะตั€ ะดะตั‚ะฐะปะธ</td>
139 138 <td class="large_width row_name">ะžะฟะธัะฐะฝะธะต</td>
140 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 144 </tr>
146 145 <?php
... ...
frontend/views/goods/one_item.php
... ... @@ -76,15 +76,15 @@ $cross_prefix = ( empty($model-&gt;crosses) )? &#39;&#39;: &#39;_cross&#39;;
76 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 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 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 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 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 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 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 90 </table></td>
... ...
frontend/web/css/BC2_catalog_zapchasti.css
... ... @@ -124,22 +124,6 @@
124 124 position: relative;
125 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 128 .currency1{
145 129 display:inline-block;
... ...
frontend/web/js/goods.js
... ... @@ -31,33 +31,33 @@ $( document ).ready(function() {
31 31  
32 32  
33 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 40 show_currency = ['eur'];
41 41 hidden_currency = ['uah','usd'];
42 42 setVisiblePrice();
43 43 }
44 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 51 show_currency = ['uah'];
52 52 hidden_currency = ['eur','usd'];
53 53 setVisiblePrice();
54 54 }
55 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 62 show_currency = ['usd'];
63 63 hidden_currency = ['uah','eur'];
... ...
frontend/web/js/script.js
... ... @@ -557,12 +557,7 @@ $(&#39;.currency&#39;).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 561 $('.menu_block_center .menu_item').hover(function(){
567 562 $(this).find('p').addClass('pcolor')},
568 563 function(){
... ...