/** * 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; }
public function actionDestinationDelete($id) { /** @var UserShippingAddress $model */ $model = UserShippingAddress::findOne($id); if (!is_null($model) && $model->user_id == $this->getLoggedUser()->id) { $model->delete(); } return $this->renderPartial('_sc_destination', ['model' => null]); }
public function actionDestinationEdit($id) { if (!is_null($user = $this->getLoggedUser())) { /** @var UserShippingAddress $model */ $model = UserShippingAddress::findOne($id); if (!is_null($model) && $model->user_id == $user->id) { $form = new DestinationForm($model); if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post()) && $form->update($model)) { return $this->renderPartial('_destination', ['model' => $model]); } return $this->renderPartial('_destination_edit', ['model' => $form, 'id' => $id]); } } return null; }
/** * @return \yii\db\ActiveQuery */ public function getUserShippingAddresses() { return $this->hasMany(UserShippingAddress::className(), ['user_id' => 'id']); }