예제 #1
0
 public function actionCheckout()
 {
     $cart = $this->getCart();
     if (!empty($cart)) {
         $user = Yii::app()->user;
         $address = array();
         //$address = Address::model()->findAll('id=:id', array(':id'=>41));
         if (!$user->isGuest) {
             $address = Address::model()->findAll('user_id=:id AND country_id=:c_id', array(':id' => $user->id, ':c_id' => 156));
         }
         if (!empty($_GET['golp']) && is_numeric($_GET['golp'])) {
             $id = 0;
             $id = $_GET['golp'];
             $naddress = Address::model()->findAll('user_id=:user_id AND id=:id', array(':user_id' => $user->id, ':id' => $id));
             $model = CheckoutAddress::model()->findByPk($id);
             if (empty($naddress)) {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'The address you selected is invalid');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_shipping', array('model' => $model, 'address' => $address), false, true);
                     Yii::app()->end();
                 }
                 $this->render('_shipping', array('model' => $model, 'address' => $address));
                 Yii::app()->end();
             }
             Yii::app()->user->setState('user_cart', $cart);
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 $this->renderPartial('_payment', array('app' => $model), false, true);
                 Yii::app()->end();
             } else {
                 $this->redirect(array('payment', 'id' => $model->id));
             }
         } else {
             $model = new CheckoutAddress();
         }
         if (isset($_POST['Address'])) {
             $_POST['CheckoutAddress'] = $_POST['Address'];
         }
         if (isset($_POST['CheckoutAddress'])) {
             $model->attributes = $_POST['CheckoutAddress'];
             $model->user_id = 0;
             if (!empty($user->id)) {
                 $model->user_id = $user->id;
             }
             $model->country_id = 156;
             if ($model->save()) {
                 /*
                 $cart['shipping']['email'] = $model->email;
                 $cart['shipping']['telephone'] = $model->telephone;
                 $cart['shipping']['firstname'] = $model->firstname;
                 $cart['shipping']['lastname'] = $model->lastname;
                 $cart['shipping']['address_1'] = $model->address_1;
                 $cart['shipping']['address_2'] = $model->address_2;
                 $cart['shipping']['city'] = $model->city;
                 $cart['shipping']['postal_code'] = $model->postal_code;
                 $cart['shipping']['country_id'] = 156;
                 $cart['shipping']['zone_id'] = $model->zone_id;
                 */
                 Yii::app()->user->setState('user_cart', $cart);
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_payment', array('app' => $model), false, true);
                     Yii::app()->end();
                 } else {
                     $this->redirect(array('payment', 'id' => $model->id));
                 }
             }
         }
         if (Yii::app()->getRequest()->getIsAjaxRequest()) {
             $this->renderPartial('_shipping', array('model' => $model, 'address' => $address), false, true);
             Yii::app()->end();
         }
         $this->render('_shipping', array('model' => $model, 'address' => $address));
         Yii::app()->end();
     }
     $this->redirect(array('cart'));
 }
예제 #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Customer();
     $profile = new Profile();
     $address = new CheckoutAddress();
     //Yii::app()->session['cid'] = '';
     $this->performAjaxValidation(array($model, $profile), 'customer-form');
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate() && $this->validateAddress()) {
             $realp = PasswordHelper::generateStrongPassword();
             $model->password = $realp;
             $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password);
             $model->password = PasswordHelper::hashPassword($model->password);
             $model->status = 0;
             $model->type = 1;
             if ($model->save()) {
                 Yii::app()->session['cid'] = $model->id;
                 $profile->user_id = $model->id;
                 $profile->save();
                 if (!empty($_POST['Customer']['c_group_id'])) {
                     foreach ($_POST['Customer']['c_group_id'] as $groupid) {
                         $customerGroup = new CustomerCGroup();
                         $customerGroup->user_id = $model->id;
                         $customerGroup->c_group_id = $groupid;
                         $customerGroup->save();
                     }
                 }
                 $passwordHistory = new PasswordHistory();
                 $passwordHistory->profile_id = $model->id;
                 $passwordHistory->password = $model->password;
                 $passwordHistory->save();
                 foreach ($this->_address as $address) {
                     $address->user_id = $model->id;
                     $address->save();
                 }
                 if (Yii::app()->getModule('user')->sendActivationMail) {
                     $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url)));
                 }
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, Yii::t('info', 'Customer was successfully created'));
                 $this->renderPartial('_view', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true);
                 Yii::app()->end();
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'An error occurred while trying to create new customer, please try again.'));
                 /*$this->render('create',array(
                 			'model'=>$model,
                 			'profile'=>$profile,
                 		));*/
             }
         } else {
             $profile->validate();
             $this->validateAddress();
             //echo GxActiveForm::validateMultiple(array($model,$profile,$address));
             //Yii::app()->end();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form_address', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'profile' => $profile, 'address' => $this->_address));
 }
 public function actionCheckout()
 {
     $cart = Yii::app()->user->getState('special_order');
     if (!empty($cart)) {
         $user = Yii::app()->user;
         $address = array();
         //$address = Address::model()->findAll('id=:id', array(':id'=>41));
         if (!$user->isGuest) {
             $address = Address::model()->findAll('user_id=:id AND country_id=:c_id', array(':id' => $user->id, ':c_id' => 156));
         }
         if (!empty($_GET['golp']) && is_numeric($_GET['golp'])) {
             $id = 0;
             $id = $_GET['golp'];
             $naddress = Address::model()->findAll('user_id=:user_id AND id=:id', array(':user_id' => $user->id, ':id' => $id));
             $model = CheckoutAddress::model()->findByPk($id);
             if (empty($naddress)) {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'The address you selected is invalid');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('/cart/_shipping', array('model' => $model, 'address' => $address), false, true);
                     Yii::app()->end();
                 }
                 $this->render('/cart/_shipping', array('model' => $model, 'address' => $address));
                 Yii::app()->end();
             }
             //Yii::app()->user->setState('user_cart', $cart);
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 $this->renderPartial('_view', array('model' => $order), false, true);
             } else {
                 $this->render('view', array('model' => $order));
             }
             Yii::app()->end();
         } else {
             $model = new CheckoutAddress();
         }
         if (isset($_POST['Address'])) {
             $_POST['CheckoutAddress'] = $_POST['Address'];
         }
         if (isset($_POST['CheckoutAddress'])) {
             $model->attributes = $_POST['CheckoutAddress'];
             $model->user_id = 0;
             if (!empty($user->id)) {
                 $model->user_id = $user->id;
             }
             $model->country_id = 156;
             if ($model->save()) {
                 $order = new SpecialOrder();
                 $order->product_name = $cart['product_name'];
                 $order->product_quantity = $cart['product_quantity'];
                 $order->product_colour = $cart['product_colour'];
                 $order->specification = $cart['specification'];
                 $order->comment = $cart['comment'];
                 $order->email = $model->email;
                 $order->telephone = $model->telephone;
                 $order->firstname = $model->firstname;
                 $order->lastname = $model->lastname;
                 $order->address_1 = $model->address_1;
                 $order->address_2 = $model->address_2;
                 $order->city = $model->city;
                 $order->postal_code = $model->postal_code;
                 $order->country_id = 156;
                 $order->zone_id = $model->zone_id;
                 $order->ip = Yii::app()->request->userHostAddress;
                 $order->user_agent = Yii::app()->request->userAgent;
                 $order->order_status_id = 1;
                 $order->payment_code = uniqid() . rand(1, 9);
                 $order->save();
                 //Yii::app()->user->setState('user_cart', $cart);
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $order), false, true);
                 } else {
                     $this->render('view', array('model' => $order));
                 }
                 Yii::app()->end();
             }
         }
         if (Yii::app()->getRequest()->getIsAjaxRequest()) {
             $this->renderPartial('/cart/_shipping', array('model' => $model, 'address' => $address), false, true);
             Yii::app()->end();
         }
         $this->render('/cart/_shipping', array('model' => $model, 'address' => $address));
         Yii::app()->end();
     }
     $this->redirect(array('specialorder'));
 }