Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $stores = [];
     if (\Yii::$app->user->identity->id != 1) {
         $stores = UserStore::find()->select('store_id')->where(['user_id' => Yii::$app->user->identity->id])->all();
         $stores = ArrayHelper::getColumn($stores, 'store_id');
     }
     $query = Store::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['store_id' => $this->store_id]);
     $query->andFilterWhere(['like', 'store_name', $this->store_name])->andFilterWhere(['like', 'store_desc', $this->store_desc])->andFilterWhere(['like', 'store_picture', $this->store_picture])->andFilterWhere(['in', 'store_id', $stores]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $stores = [];
     if (\Yii::$app->user->identity->id != 1) {
         $stores = UserStore::find()->select('store_id')->where(['user_id' => Yii::$app->user->identity->id])->all();
         $stores = ArrayHelper::getColumn($stores, 'store_id');
     }
     // print_r(yii\helpers\ArrayHelper::getColumn($store, 'store_id')); exit;
     $query = Product::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['prod_id' => $this->prod_id, 'prod_price' => $this->prod_price, 'currency' => $this->currency, 'store_id' => $this->store_id, 'in_stock' => $this->in_stock, 'num_product' => $this->num_product]);
     $query->andFilterWhere(['like', 'prod_name', $this->prod_name])->andFilterWhere(['like', 'prod_desc', $this->prod_desc])->andFilterWhere(['in', 'store_id', $stores]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     // echo Yii::getAlias('@common'); exit;
     $model = new Product();
     $modelProdMeta = new ProductMeta();
     $stores = [];
     if (\Yii::$app->user->identity->id == 1) {
         $stores = \common\models\UserStore::find()->select('store_id')->where(['user_id' => Yii::$app->user->identity->id])->all();
         $stores = \yii\helpers\ArrayHelper::getColumn($stores, 'store_id');
         $storeList = \common\models\Store::find()->where(['IN', 'store_id', $stores])->all();
     } else {
         $storeList = \common\models\Store::find()->all();
     }
     if ($postData = Yii::$app->request->post()) {
         if ($model->load($postData) && $model->save()) {
             $prod_id = $model->prod_id;
             foreach ($model->cat_id as $cat) {
                 $catModel = new ProdCat();
                 $catModel->cat_id = $cat;
                 $catModel->prod_id = $prod_id;
                 $catModel->save();
             }
             $file = UploadedFile::getInstances($model, 'images');
             $model->file = $file[0];
             $image_path = Yii::getAlias('@frontend') . '/web/uploads/product/' . $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension;
             $model->file->saveAs($image_path);
             $this->updateProductMeta($id, 'prod_img', $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension);
             foreach ($postData['PMeta'] as $key => $meta_value) {
                 $this->updateProductMeta($id, $key, $meta_value);
             }
             return $this->redirect(['view', 'id' => $model->prod_id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'modelProdMeta' => $modelProdMeta, 'storeList' => $storeList]);
     }
 }