public function search($params) { $query = Product::find()->with('prices'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new \yii\data\Sort(['attributes' => ['name', 'id', 'available']])]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'available' => $this->available, 'producer_id' => $this->producer_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'short_text', $this->short_text]); return $dataProvider; }
public function getProducts() { return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('{{%shop_product_to_category}}', ['category_id' => 'id'])->available(); }
public function getProduct() { return $this->hasOne(Product::className(), ['id' => 'product_id']); }