<?php
namespace common\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\data\Sort;
use yii\helpers\VarDumper;
/**
* ProductSeedsSearch represents the model behind the search form about `common\models\ProductSeeds`.
*/
class ProductSeedsSearch extends ProductSeeds
{
public $sort;
public $category_title;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status', 'new', 'hit', 'sale', 'stock', 'top_sales', 'top_ten', 'category_id', 'quantity', 'img_id', 'gallery_id', 'brand_id', 'ripeness_group', 'country_id', 'rateNum', 'availability', 'created_at', 'updated_at'], 'integer'],
[['title', 'content', 'vendor_code', 'seo_keywords', 'seo_description', 'category_title', 'sort'], 'safe'],
//[['old_price', 'price'], 'number'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
// $query = ProductSeeds::find();
// add conditions that should always apply here
$id = Yii::$app->request->get('id');
$query = ProductSeeds::find()->joinWith('category')->where(['category_id' => $id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'brand_id' => $this->brand_id,
'country_id' => $this->country_id,
'ripeness_group' => $this->ripeness_group,
]);
$query->andFilterWhere([
'and',
['>=', 'price', Yii::$app->request->get('min_zena')],
['<=', 'price', Yii::$app->request->get('max_zena')]
]);
// if ($this->price) {
// $range = explode(',', $this->price);
//
// $query->andFilterWhere([
// 'and',
// ['>=', 'price', $range[0]],
// ['<=', 'price', $range[1]]
// ]);
// }
return $dataProvider;
}
}