Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param Catalogs $catalog
  *
  * @return ActiveDataProvider
  */
 public function search($params, $catalog)
 {
     $viewList = CookieController::getViewList();
     $productsID = [];
     $productsID = array_merge($productsID, $catalog->getProducts()->select('product_id')->asArray()->all());
     foreach ($catalog->children()->all() as $child) {
         $productsID = array_merge($productsID, $child->getProducts()->select('product_id')->asArray()->all());
     }
     $query = Products::find()->where(['product_id' => $productsID]);
     $price_min = $query->min('price');
     $price_max = $query->max('price');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $viewList == 'panel' ? 6 : 5]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name]);
     // print_r($this->price_min);
     $query->andFilterWhere(['>=', 'price', $this->price_min]);
     $query->andFilterWhere(['<=', 'price', $this->price_max]);
     //print_r($params['ProductsCatalogSearch']);
     if ($params['ProductsCatalogSearch']['count'] == self::ALL) {
         // echo "всееее";
         // $query->andWhere('a > :a', ['a' => 'a'])
     } elseif ($params['ProductsCatalogSearch']['count'] == self::AVAILABLE) {
         // echo "в наличиbbи";
         $query->andWhere('count > 0');
     } elseif ($params['ProductsCatalogSearch']['count'] == self::NOT_AVAILABLE) {
         // echo "нетууу";
         $query->andWhere('count <= 0');
     }
     return ['dataProvider' => $dataProvider, 'price_min' => $price_min, 'price_max' => $price_max];
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $viewList = CookieController::getViewList();
     $query = Products::find()->select(['product_id', 'name', 'price', 'gallery_id', "IF (LENGTH(precontent) > 200,\n                CONCAT(LEFT(TRIM(TRAILING '.' FROM precontent),150),'...'),\n                LEFT(TRIM(TRAILING '.' FROM precontent),150))\n             as precontent"])->where(['popular' => true]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $viewList == 'panel' ? 6 : 5]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         return $dataProvider;
     }
     if (isset($params['ProductsPopularSearch']['count'])) {
         if ($params['ProductsPopularSearch']['count'] == Products::AVAILABLE) {
             // echo "в наличии";
             $query->andWhere('count > 0');
         } elseif ($params['ProductsPopularSearch']['count'] == Products::NOT_AVAILABLE) {
             // echo "нетууу";
             $query->andWhere('count <= 0');
         }
     }
     return $dataProvider;
 }
Ejemplo n.º 3
0
use yii\data\ActiveDataProvider;
use yii\widgets\LinkPager;
?>


<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 panel-basic panel-basic-default">
    <h4>Популярные товары</h4>
    <hr>
    <?
    echo $this->render('_search', [
        'model' => $searchModel,
    ])
    ?>
</div>
<?php 
$viewList = CookieController::getViewList();
if ($dataProvider->count > 0) {
    if ($viewList == 'list' or !isset($viewList)) {
        echo $this->render('_list', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
    } elseif ($viewList == 'panel') {
        echo $this->render('_panel', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
    }
    echo LinkPager::widget(['pagination' => $dataProvider->pagination]);
} else {
    echo $this->render('emptyList', ['model' => $model]);
}
?>

<?php 
?>