public function actionCreate() { // if some data has been entered before or the user is already logged in, // take the already existing data and prefill the input form if ($model = Shop::getCustomer()) { $address = $model->address; } else { $model = new Customer(); } if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if (isset($_POST['Address'])) { $address = new Address(); $address->attributes = $_POST['Address']; if ($address->save()) { $model->address_id = $address->id; } } if (!Yii::app()->user->isGuest) { $model->user_id = Yii::app()->user->id; } $model->validate(); if (Shop::module()->useWithYum && isset($_POST['register']) && ($_POST['register'] = true)) { if (isset($_POST['Customer']['password']) && isset($_POST['Customer']['passwordRepeat'])) { if ($_POST['Customer']['password'] != $_POST['Customer']['passwordRepeat']) { $model->addError('password', Shop::t('Passwords do not match')); } else { if ($_POST['Customer']['password'] == '') { $model->addError('password', Shop::t('Password is empty')); } else { $user = new YumUser(); $profile = new YumProfile(); $profile->attributes = $_POST['Customer']; $profile->attributes = $_POST['Address']; if ($user->register(strtr($model->email, array('@' => '_', '.' => '_')), $_POST['Customer']['password'], $profile)) { $user->status = YumUser::STATUS_ACTIVE; $user->save(false, array('status')); $model->user_id = $user->id; Shop::setFlash(Shop::t('Successfully registered user')); } else { $model->addErrors($user->getErrors()); $model->addErrors($profile->getErrors()); Shop::setFlash(Shop::t('Error while registering user')); } } } } } if (!$model->hasErrors()) { if ($model->save()) { Yii::app()->user->setState('customer_id', $model->customer_id); $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id)); } } } $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address())); }