コード例 #1
0
ファイル: StoreSearch.php プロジェクト: syedmaaz/marxmall-
 /**
  * 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;
 }
コード例 #2
0
ファイル: ProductSearch.php プロジェクト: syedmaaz/marxmall-
 /**
  * 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;
 }
コード例 #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]);
     }
 }
コード例 #4
0
ファイル: Store.php プロジェクト: syedmaaz/marxmall-
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserStores()
 {
     return $this->hasMany(UserStore::className(), ['store_id' => 'store_id']);
 }
コード例 #5
0
ファイル: SiteController.php プロジェクト: syedmaaz/marxmall-
 public function actionRegisterStore()
 {
     $this->layout = 't2/main';
     $userModel = new SignupForm();
     $storeModel = new Store();
     $user_id = 0;
     if ($userModel->load(Yii::$app->request->post()) && $storeModel->load(Yii::$app->request->post())) {
         // print_r($storeModel->validate()); exit;
         if (Yii::$app->user->isGuest) {
             if ($userModel->validate() && ($user = $userModel->signup())) {
                 $user_id = $user->id;
             } else {
                 return $this->render('registerStore', ['userModel' => $userModel, 'storeModel' => $storeModel]);
             }
         } else {
             $user_id = \Yii::$app->user->identity->id;
         }
         $store_img = UploadedFile::getInstances($storeModel, 'file');
         if ($storeModel->validate()) {
             if (!empty($store_img)) {
                 $storeModel->file = $store_img[0];
                 $image_name = '/store/' . $storeModel->file->baseName . '_' . time() . '.' . $storeModel->file->extension;
                 $image_path = Yii::getAlias('@frontend') . '/web/uploads' . $image_name;
                 $storeModel->file->saveAs($image_path);
                 $storeModel->store_picture = $image_name;
             }
             if ($storeModel->save()) {
                 $store_id = $storeModel->store_id;
                 $userStore = new UserStore();
                 $userStore->user_id = $user_id;
                 $userStore->store_id = $store_id;
                 $userStore->save();
                 return $this->redirect(Yii::$app->urlManager->getBaseUrl() . '/backend/web/');
             } else {
                 print_r($storeModel->error);
                 exit;
             }
             // }
         } else {
             print_r($storeModel->errors);
             exit;
             return $this->render('registerStore', ['userModel' => $userModel, 'storeModel' => $storeModel]);
         }
         echo '<pre>';
         print_r($storeModel);
         print_r($store_img);
         exit;
     }
     // $store_img = UploadedFile::getInstances($storeModel, 'file');
     // $storeModel->file = $store_img[0];
     // if($storeModel->validate()) {
     //     if(!empty($store_img)){
     //         $image_name = '/store/' . $storeModel->file->baseName . '_' . time() . '.' . $storeModel->file->extension;
     //         $image_path = Yii::getAlias('@frontend'). '/web/uploads' . $image_name;
     //         $storeModel->file->saveAs( $image_path);
     //         $storeModel->store_picture = $image_name;
     //         if($storeModel->save()) {
     //             $store_id = $storeModel->store_id;
     //             $user_id = \Yii::$app->user->identity->id;
     //             echo $store_id;
     //             echo $user_id;
     //             exit;
     //         }
     //     }
     //    // return $this->redirect(['view', 'id' => $model->store_id]);
     // } else {
     //     // return $this->render('update', [
     //     //     'model' => $model,
     //     // ]);
     // }
     return $this->render('registerStore', ['userModel' => $userModel, 'storeModel' => $storeModel]);
 }