Blame view

frontend/controllers/SearchController.php 1.78 KB
cc658b4c   Yarik   Big commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  <?php
      
      namespace frontend\controllers;
      
      use common\modules\product\models\Product;
      use yii\data\ActiveDataProvider;
      use yii\web\Controller;
      
      /**
       * Search controller
       */
      class SearchController extends Controller
      {
          
          /**
           * Displays search result.
           * @return string
           */
          public function actionIndex()
          {
              $search = \Yii::$app->request->get('search');
              if(empty( $search )) {
                  return $this->redirect([ 'site/index' ]);
              }
              $query = Product::find()
d55d2fe0   Yarik   Multilanguage
26
27
28
                              ->joinWith('lang', true, 'INNER JOIN')
                              ->joinWith('variants.lang', true, 'INNER JOIN')
                              ->joinWith('brand.lang', true, 'INNER JOIN')
cc658b4c   Yarik   Big commit
29
30
                              ->where([
                                  'ilike',
d55d2fe0   Yarik   Multilanguage
31
                                  'product_lang.name',
cc658b4c   Yarik   Big commit
32
33
34
35
                                  $search,
                              ])
                              ->orWhere([
                                  'ilike',
d55d2fe0   Yarik   Multilanguage
36
                                  'brand_lang.name',
cc658b4c   Yarik   Big commit
37
38
39
40
                                  $search,
                              ])
                              ->orWhere([
                                  'ilike',
d55d2fe0   Yarik   Multilanguage
41
                                  'product_variant_lang.name',
cc658b4c   Yarik   Big commit
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
                                  $search,
                              ]);
              $dataProvider = new ActiveDataProvider([
                  'query'      => $query,
                  'pagination' => [
                      'pageSize' => 20,
                  ],
              ]);
              
              return $this->render('index', [
                  'dataProvider' => $dataProvider,
                  'search'       => $search,
              ]);
          }
      }