/** * @author Chienlv levanchien.it@gmail.com * @todo action process payment, support Paypal and Pin */ public function actionProcess() { $data = isset($_POST) ? $_POST : false; if ($data) { #{ switch ($data['payment-method']) { /** * @todo Default is Paypal * @link http://stackoverflow.com/questions/14843212/submit-form-via-curl-and-redirect-browser-to-paypal tutoria */ default: case 0: #Delete $ data ['payment-method'] because it is not for paypal unset($data['payment-method']); #The variable $data obtained from the form sent to header('Location: https://www.paypal.com/cgi-bin/webscr?' . http_build_query($data)); break; /** * @todo use Pin paymant * Cac tham so gui tu from * validate email? @toantv */ /** * @todo use Pin paymant * Cac tham so gui tu from * validate email? @toantv */ case 1: $model = new PinPaymentForm(); if (isset($_POST['PinPaymentForm'])) { $model->attributes = $_POST['PinPaymentForm']; if ($model->validate()) { $reponse = $model->pinPayMent(); if (isset($reponse['error'])) { Yii::app()->user->setFlash('errors', $reponse); } elseif (isset($reponse['response'])) { $model_pay = new UserPayment(); $model_pay->payment_date = new CDbExpression('NOW()'); $model_pay->payment_type = 'CREDIT-PIN'; $model_pay->payment_value = number_format($reponse['response']['amount'] / 100, 2); $model_pay->user_id = Yii::app()->user->id; $model_pay->staff_id = null; $model_pay->payment_note = $reponse['response']['token']; $model_pay->save(); $BoxoCart = new BoxoCart(); $BoxoCart->confirmOrder(); $this->redirect(array('user/payments')); } } } $this->render('_pin', array('model' => $model, 'paymentMethod' => $data['payment-method'], 'amount' => $data['amount'])); break; /** * @todo Bank Transfer */ /** * @todo Bank Transfer */ case 2: //Send email $adminEmail = SnapUtil::config('boxomatic/adminEmail'); $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName'); $message = new YiiMailMessage('Transfer information of ' . Yii::app()->name); $message->view = 'bank_transfer'; $message->setBody($data, 'text/html'); $message->addTo($adminEmail); $message->addTo($data['email']); $message->setFrom(array($adminEmail => $adminEmailFromName)); if (Yii::app()->mail->send($message)) { $BoxoCart = new BoxoCart(); $BoxoCart->confirmOrder(); } $this->render('_bank_transfer', array('data' => $data)); break; } } }
/** * Displays the login page */ public function actionLogin() { $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $BoxoCart = new BoxoCart(); $BoxoCart->populateCart(); //$this->redirect(Yii::app()->user->returnUrl); $this->redirect(array('shop/checkout')); } } // display the login form $this->render('login', array('model' => $model)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $Customer = $this->loadModel($id); if ($Customer->id !== Yii::app()->user->id) { throw new CHttpException(403, 'You are not authorized to perform this action.'); } if (isset($_POST['role']) && $_POST['role'] == 'customer') { $UserLoc = new UserLocation(); $UserLoc->user_id = $Customer->user_id; $UserLoc->location_id = $Customer->location_id; $UserLoc->address = $Customer->user_address; $UserLoc->address2 = $Customer->user_address2; $UserLoc->suburb = $Customer->user_suburb; $UserLoc->state = $Customer->user_state; $UserLoc->postcode = $Customer->user_postcode; $UserLoc->phone = !empty($Customer->user_phone) ? $Customer->user_phone : $Customer->user_mobile; $UserLoc->save(); $Customer->user_id = $Customer->user_id; $Customer->update(array('user_id')); } $allSaved = true; if (isset($_POST['Supplier'])) { $Supplier = $Customer->Supplier; $Supplier->attributes = $_POST['Supplier']; if (!$Supplier->update()) { $allSaved = false; } } if (isset($_POST['role'])) { $Customer->setRole($_POST['role']); } if (isset($_POST['BoxomaticUser'])) { $oldLocation = $Customer->location_id; $oldDeliveryDay = $Customer->delivery_day; $Customer->attributes = $_POST['BoxomaticUser']; $locationId = $_POST['BoxomaticUser']['delivery_location_key']; $custLocationId = new CDbExpression('NULL'); if (strpos($locationId, '-')) { //has a customer location $parts = explode('-', $locationId); $locationId = $parts[1]; $custLocationId = $parts[0]; } $Customer->location_id = $locationId; $Customer->user_location_id = $custLocationId; $Customer->validate(); if (!$Customer->update()) { $allSaved = false; } //Update the cart to prevent ordering on an unavailable day $BoxoCart = new BoxoCart(); $BoxoCart->delivery_day = $Customer->delivery_day; $BoxoCart->setLocation_id($Customer->location_id); $BoxoCart->setDelivery_date_id($BoxoCart->getNextDeliveryDate()->id); //The frontend system currently doesn't handle ordering from multiple locations //so delete all orders if changing location if ($Customer->location_id != $oldLocation || $Customer->delivery_day != $oldDeliveryDay) { $deleted = false; foreach ($Customer->getFutureOrders() as $Order) { $Order->delete(); $deleted = true; } $BoxoCart->emptyCart(); if ($deleted) { Yii::app()->user->setFlash('warning', 'All future orders removed.'); } } if ($allSaved) { $this->redirect(array('user/update', 'id' => $Customer->id)); } } $custLocDataProvider = null; $custLocDataProvider = new CActiveDataProvider('UserLocation', array('criteria' => array('condition' => 'user_id=' . $Customer->id))); $this->render('update', array('model' => $Customer, 'custLocDataProvider' => $custLocDataProvider)); }