/** * Checkout as a guest or as an existing user * * @return void */ public function actionIndex() { $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew(); // did user leave checkout and come back? $returnRoute = $this->checkoutForm->getCheckoutPoint(); if (is_null($returnRoute) === false && isset($_GET['showLogin']) === false) { // send user to correct checkout point $this->redirect($this->createAbsoluteUrl($returnRoute)); } // if the user is already logged in take them straight to shipping if (!Yii::app()->user->isGuest) { $objCustomer = Customer::GetCurrent(); $this->checkoutForm->contactEmail = $this->checkoutForm->contactEmail_repeat = $objCustomer->email; $this->checkoutForm->saveFormToSession(); // set cart customer if missing $objCart = Yii::app()->shoppingcart; if ($objCart->customer_id !== $objCustomer->id) { $objCart->customer_id = $objCustomer->id; $objCart->save(); } $this->redirect($this->createAbsoluteUrl('/checkout/shippingaddress')); } $this->publishJS('index'); $this->layout = '/layouts/checkout-column2'; $model = new LoginForm(); $showLoginPasswordField = false; // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and continue if valid if ($model->guest == 0) { $showLoginPasswordField = true; $success = $model->validate() && $model->login(); } else { $model->setScenario('Guest'); $success = $model->validate(); } if ($success) { $this->checkoutForm->passedScenario = $model->getScenario(); $this->checkoutForm->contactEmail = strtolower($model->email); $this->checkoutForm->contactEmail_repeat = strtolower($model->email); $this->checkoutForm->saveFormToSession(); if ($this->checkoutForm->validate()) { if ($model->guest) { $this->redirect($this->createAbsoluteUrl('/checkout/shipping')); } else { $this->redirect($this->createAbsoluteUrl("/checkout/shippingaddress")); } } } $this->checkoutForm->addErrors($model->getErrors()); } $blnShowLogin = false; if (isset($_SESSION['checkoutform.cache'])) { $model->email = $_SESSION['checkoutform.cache']['contactEmail']; } if (isset($_GET['showLogin'])) { $blnShowLogin = $_GET['showLogin']; } // display the login form $this->render('index', array('model' => $model, 'error' => $this->formatErrors(), 'blnShowLogin' => $blnShowLogin, 'showLoginPasswordField' => $showLoginPasswordField)); }