public function actionDestinationSave()
 {
     $id = Yii::$app->request->get('id');
     $model = null;
     if (!empty($id)) {
         $model = UserShippingAddress::findOne($id);
     }
     if (is_null($model)) {
         $model = new UserShippingAddress();
     }
     $model->user_id = $this->getLoggedUser()->id;
     if ($model->load(Yii::$app->request->get()) && $model->save()) {
         $this->getShoppingCart()->destination = $model->id;
         $model = null;
     }
     return $this->renderPartial('_sc_destination', ['model' => $model]);
 }
Example #2
0
 /**
  * register the user
  * @return boolean whether the model passes validation
  */
 public function register()
 {
     if ($this->validate()) {
         $user = new User();
         $user->password = $this->password;
         $user->username = $this->email;
         $user->email = $this->email;
         $user->name = $this->first_name . ' ' . $this->last_name;
         $user->registered = date('Y-m-d H:i:s');
         $user->billing_first_name = $this->first_name;
         $user->billing_last_name = $this->last_name;
         $user->billing_address1 = $this->billing_address1;
         $user->billing_address2 = $this->billing_address2;
         $user->billing_city = $this->billing_city;
         $user->billing_state = $this->billing_state;
         $user->billing_country = $this->billing_country;
         $user->billing_zip = $this->billing_zip;
         $user->billing_phone = $this->billing_phone;
         if ($user->save()) {
             $sa = new UserShippingAddress();
             $sa->user_id = $user->id;
             $sa->shipping_address1 = $this->shipping_address1;
             $sa->shipping_address2 = $this->shipping_address2;
             $sa->shipping_city = $this->shipping_city;
             $sa->shipping_state = $this->shipping_state;
             $sa->shipping_zip = $this->shipping_zip;
             $sa->shipping_country = $this->shipping_country;
             $sa->shipping_phone = $this->shipping_phone;
             $sa->shipping_email = $this->shipping_email;
             $sa->shipping_contact = $this->shipping_contact;
             $sa->shipping_contact2 = $this->shipping_contact2;
             $sa->save();
             $user->generateEmailWelcome();
             return Yii::$app->user->login($user, 0);
         }
     }
     return false;
 }