/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProductModel::find(); $query->with(['category', 'group']); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { $query->where('1=0'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'group_id' => $this->group_id, 'category_id' => $this->category_id, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(Product::className(), ['id' => 'product_id']); }
public function actionProductList($term = '') { $response = Yii::$app->response; $response->format = 'json'; return Product::find()->filterWhere(['like', 'lower([[name]])', strtolower($term)])->orFilterWhere(['like', 'lower([[name]])', strtolower($term)])->limit(10)->asArray()->all(); }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::className(), ['category_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('product_vendor', ['vendor_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(\backend\models\master\Product::className(), ['id' => 'item_id']); }
/** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $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.'); } }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('product_stock', ['warehouse_id' => 'id']); }