Ejemplo n.º 1
0
 public function actionVendorupdate($id)
 {
     $model = new VendorRegister();
     $model->scenario = 'vendoradmin';
     $userData = VendorRegister::find()->where(['uid' => $id])->one();
     $userMain = UserMaster::find()->where(['id' => $id])->one();
     $model->countriesList = Countries::getCountriesUS();
     if ($userData['country'] == NULL) {
         $model->country = 231;
     } else {
         $model->country = $userData['country'];
     }
     $states = Countries::getStatesByCountry($model->country);
     $statesAry = array();
     foreach ($states as $state) {
         $statesAry[$state['id']] = $state['name'];
     }
     $model->statesData = $statesAry;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->uid = $id;
         //$model->dob = 'NOW()';
         $userExist = VendorRegister::find()->where(['uid' => $id])->one();
         if ($userExist != NULL) {
             //echo "00000000000000000";
             $userExist->firstName = $model->firstName;
             $userExist->lastName = $model->lastName;
             $userExist->middleName = $model->middleName;
             $userExist->mobile = $model->mobile;
             $userExist->mobile2 = $model->mobile2;
             $userExist->address2 = $model->address2;
             $userExist->city = $model->city;
             $userExist->state = $model->state;
             $userExist->country = $model->country;
             $userExist->zip = $model->zip;
             $userExist->modifiedDate = 'NOW()';
             if ($userMain->roleId == 2) {
                 $userExist->storeName = $model->storeName;
                 $userExist->storeAddress = $model->storeAddress;
                 $userExist->businessName2 = $model->businessName2;
                 $model->storeImage = UploadedFile::getInstance($model, 'storeImage');
                 if ($model->storeImage != '') {
                     $imageName = rand(1000, 100000) . $model->storeImage->baseName;
                     $model->storeImage->saveAs(Yii::getAlias('@frontend') . '/web/uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension);
                     $model->storeImage = 'uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension;
                 } else {
                     $model->storeImage = $model->storeimgesdup;
                 }
                 $userExist->storeImage = $model->storeImage;
             }
             $userExist->update();
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['index']);
         } else {
             $model->storeImage = UploadedFile::getInstance($model, 'storeImage');
             if ($model->storeImage != '') {
                 $imageName = rand(1000, 100000) . $model->storeImage->baseName;
                 $model->storeImage->saveAs(Yii::getAlias('@frontend') . '/web/uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension);
                 $model->storeImage = 'uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension;
             } else {
                 $model->storeImage = $model->storeimgesdup;
             }
             $model->save();
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['index']);
         }
     } else {
         $model->username = $userMain->username;
         $model->email = $userMain->email;
         $model->roleId = $userMain->roleId;
         $model->status = $userMain->status;
         $model->firstName = $userData['firstName'];
         $model->lastName = $userData['lastName'];
         $model->middleName = $userData['middleName'];
         $model->fax = $userData['fax'];
         $model->mobile = $userData['mobile'];
         $model->mobile2 = $userData['mobile2'];
         $model->address2 = $userData['address2'];
         $model->city = $userData['city'];
         $model->zip = $userData['zip'];
         $model->storeName = $userData['storeName'];
         $model->businessName2 = $userData['businessName2'];
         $model->storeAddress = $userData['storeAddress'];
         $model->storeImage = $userData['storeImage'];
         $model->id = $userData['uid'];
         return $this->render('update', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 public function actionUserupdate($id)
 {
     $model = new RegisterMaster();
     $userData = RegisterMaster::find()->where(['uid' => $id])->one();
     $userMain = UserMaster::find()->where(['id' => $id])->one();
     $model->countriesList = Countries::getCountries();
     $states = Countries::getStatesByCountry($userData['country']);
     $statesAry = array();
     foreach ($states as $state) {
         $statesAry[$state['id']] = $state['name'];
     }
     $model->statesData = $statesAry;
     if ($model->load(Yii::$app->request->post())) {
         $model->uid = $id;
         //$model->dob = 'NOW()';
         $userExist = RegisterMaster::find()->where(['uid' => $id])->one();
         if ($userExist != NULL) {
             //echo "00000000000000000";
             $userExist->firstName = $model->firstName;
             $userExist->lastName = $model->lastName;
             $userExist->middleName = $model->middleName;
             $userExist->gender = $model->gender;
             $userExist->dob = $model->dob;
             $userExist->mobile = $model->mobile;
             $userExist->mobile2 = $model->mobile2;
             $userExist->address1 = $model->address1;
             $userExist->address2 = $model->address2;
             $userExist->city = $model->city;
             $userExist->state = $model->state;
             $userExist->country = $model->country;
             $userExist->zip = $model->zip;
             $userExist->modifiedDate = 'NOW()';
             if ($userMain->roleId == 2) {
                 $userExist->storeName = $model->storeName;
                 $userExist->storeAddress = $model->storeAddress;
                 $model->storeImage = UploadedFile::getInstance($model, 'storeImage');
                 if ($model->storeImage != '') {
                     $imageName = rand(1000, 100000) . $model->storeImage->baseName;
                     $model->storeImage->saveAs('uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension);
                     $model->storeImage = 'uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension;
                     $userExist->storeImage = $model->storeImage;
                     $model->storeImage;
                 }
             }
             $userExist->update();
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['index']);
         } else {
             $model->save();
             print_r($model);
             exit;
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['index']);
         }
     } else {
         $model->username = $userMain->username;
         $model->email = $userMain->email;
         $model->roleId = $userMain->roleId;
         $model->status = $userMain->status;
         $model->firstName = $userData['firstName'];
         $model->lastName = $userData['lastName'];
         $model->middleName = $userData['middleName'];
         $model->gender = $userData['gender'];
         $model->dob = $userData['dob'];
         $model->mobile = $userData['mobile'];
         $model->mobile2 = $userData['mobile2'];
         $model->address1 = $userData['address1'];
         $model->address2 = $userData['address2'];
         $model->city = $userData['city'];
         $model->state = $userData['state'];
         $model->country = $userData['country'];
         $model->zip = $userData['zip'];
         $model->storeName = $userData['storeName'];
         $model->storeAddress = $userData['storeAddress'];
         $model->storeImage = $userData['storeImage'];
         $model->id = $userData['uid'];
         return $this->render('update', ['model' => $model]);
     }
 }