Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Product::find()->with('category');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'is_del' => $this->is_del, 'is_hot' => $this->is_hot, 'is_new' => $this->is_new, 'is_best' => $this->is_best, 'category_id' => $this->category_id, 'is_free_shipping' => $this->is_free_shipping, 'quantity' => $this->quantity, 'brand_id' => $this->brand_id, 'shipping' => $this->shipping, 'price' => $this->price, 'market_price' => $this->market_price, 'shop_price' => $this->shop_price, 'is_promote' => $this->is_promote, 'promote_price' => $this->promote_price, 'promote_start_date' => $this->promote_start_date, 'promote_end_date' => $this->promote_end_date, 'points' => $this->points, 'tax_class_id' => $this->tax_class_id, 'date_available' => $this->date_available, 'weight' => $this->weight, 'length' => $this->length, 'width' => $this->width, 'height' => $this->height, 'mini_mum' => $this->mini_mum, 'viewed' => $this->viewed, 'sort' => $this->sort, 'status' => $this->status, 'stock_status' => $this->stock_status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     //->andFilterWhere(['like', 'model', $this->model])
     $query->andFilterWhere(['like', 'sku', $this->sku])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'brief', $this->brief])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }