コード例 #1
0
 function getCustomer()
 {
     $this->autoRender = false;
     $sql = "SELECT * FROM customer_old;";
     $datas = $this->Cabinet->query($sql);
     App::import("Model", "CustomerManager.Customer");
     App::import("Model", "CustomerManager.BuilderAccount");
     App::import("Model", "CustomerManager.CustomerAddress");
     foreach ($datas as $data) {
         $Customer_model = new Customer();
         $BuilderAccount_model = new BuilderAccount();
         $CustomerAddress_model = new CustomerAddress();
         $cus_data['Customer']['last_name'] = $data['customer_old']['CustomerName'];
         $cus_data['Customer']['website'] = $data['customer_old']['WebSite'];
         if ($data['customer_old']['Inactive'] == 0) {
             $cus_data['Customer']['status'] = 1;
         } else {
             $cus_data['Customer']['status'] = 0;
         }
         $cus_data['Customer']['address'] = $data['customer_old']['loc_Address1'];
         $cus_data['Customer']['city'] = $data['customer_old']['loc_City'];
         $cus_data['Customer']['province'] = $data['customer_old']['loc_Province'];
         $cus_data['Customer']['postal_code'] = $data['customer_old']['loc_PostalCode'];
         $cus_data['Customer']['country'] = $data['customer_old']['loc_Country'];
         $cus_data['Customer']['phone'] = $data['customer_old']['loc_Phone'];
         $cus_data['Customer']['fax_number'] = $data['customer_old']['loc_FaxNumber'];
         $cus_data['Customer']['customer_type_id'] = 2;
         $cus_data['Customer']['site_address_exists'] = 1;
         $sales_person = array($this->loginUser['id']);
         $cus_data['Customer']['sales_representatives'] = serialize($sales_person);
         $Customer_model->save($cus_data['Customer']);
         App::uses("CustomerSalesRepresentetives", "CustomerManager.Model");
         $s = new CustomerSalesRepresentetives();
         $sales_data['customer_id'] = $Customer_model->id;
         $sales_data['user_id'] = $this->loginUser['id'];
         $s->save($sales_data);
         $cus_data['BuilderAccount']['customer_id'] = $Customer_model->id;
         $cus_data['BuilderAccount']['builder_legal_name'] = $data['customer_old']['CustomerName'];
         $cus_data['BuilderAccount']['credit_terms'] = $data['customer_old']['CreditTerms'];
         $cus_data['BuilderAccount']['credit_limit'] = $data['customer_old']['CreditLimit'];
         $cus_data['BuilderAccount']['invoice_on_day'] = $data['customer_old']['StartDate'];
         $cus_data['BuilderAccount']['quotes_validity'] = 30;
         $BuilderAccount_model->save($cus_data['BuilderAccount']);
         $cus_data['CustomerAddress']['customer_id'] = $Customer_model->id;
         $cus_data['CustomerAddress']['first_name'] = $data['customer_old']['con_ContactName'];
         $cus_data['CustomerAddress']['title'] = $data['customer_old']['con_Title'];
         $cus_data['CustomerAddress']['phone'] = $data['customer_old']['con_WorkPhone'];
         $cus_data['CustomerAddress']['fax_number'] = $data['customer_old']['con_FAX'];
         $cus_data['CustomerAddress']['cell'] = $data['customer_old']['con_MobilePhone'];
         $cus_data['CustomerAddress']['address'] = $data['customer_old']['con_Address1'];
         $cus_data['CustomerAddress']['city'] = $data['customer_old']['con_City'];
         $cus_data['CustomerAddress']['province'] = $data['customer_old']['con_Province'];
         $cus_data['CustomerAddress']['postal_code'] = $data['customer_old']['con_PostalCode'];
         $cus_data['CustomerAddress']['country'] = $data['customer_old']['con_Country'];
         $cus_data['CustomerAddress']['email'] = $data['customer_old']['con_eMail_Address'];
         $CustomerAddress_model->save($cus_data['CustomerAddress']);
     }
 }
コード例 #2
0
ファイル: PaymentController.php プロジェクト: KaranSofat/yii
 public function actionIndex()
 {
     $model = new PaymentCustomerUser();
     $booking = new CustomerBooking();
     $address = new CustomerAddress();
     $company = new CompanyRequest();
     $ses = Yii::app()->session['CleaningDetail'];
     $servicetype = Yii::app()->session['ServiceTypeId'];
     $zip = $ses['CleaningTime']['PostCode'];
     // echo "<pre>";print_r(base64_decode($_REQUEST['value']));die;
     //echo "<pre>";print_r($ses);die;
     //$myProducts = Yii::app()->session['detail'];
     $detail = Yii::app()->session['detail'];
     foreach ($detail['Additional'] as $k => $d) {
         $detailadnl[$k] = ServicetypeAdditionalservices::model()->findAll(array('condition' => 'id=:id', 'params' => array(':id' => $k)));
     }
     foreach ($detailadnl as $key => $nam) {
         // echo "<pre>";print_r($nam);
         foreach ($nam as $value) {
             $detailadnl[$key] = $value['additional_service_name'];
         }
     }
     //echo "<pre>";print_r($detail['Additional']);
     $finalDetailadnl = array_combine($detailadnl, $detail['Additional']);
     //echo "<pre>";print_r($fin);die;
     //$price         =$_REQUEST['price'];
     // code to get the method from admin %age or fiexd cost  of total amount
     $paymentAdmin = PaymentToAdmin::model()->find(array('condition' => 'status=1'));
     if (!empty($paymentAdmin)) {
         //echo "adda";die;
         if ($paymentAdmin['type_of_cost'] == 'Fixed') {
             $price = $paymentAdmin['cost_percentage'];
         } else {
             if (isset($_REQUEST['value'])) {
                 $pri = $paymentAdmin['cost_percentage'] * base64_decode($_REQUEST['value']);
                 $pce = $pri / 100;
                 $price = $pce;
             } else {
                 $price = base64_decode($_REQUEST['value1']);
             }
         }
     } else {
         $price = base64_decode($_REQUEST['value']);
     }
     //echo $price;die;
     $service_id = $_REQUEST['service_id'];
     $rec = UkPostcodes::model()->findByattributes(array('postcode' => $zip));
     // detail for logged user
     $loggedId = Yii::app()->session['loggedId'];
     $customerDetail = PaymentCustomerUser::model()->findByPk(array('id' => $loggedId));
     //echo "<pre>";print_r($customerDetail);die;
     //echo "<pre>";print_r($servicetype);die;
     if (isset($_POST['PaymentCustomerUser'])) {
         $logged = Yii::app()->session['loggedId'];
         //echo "<pre>";print_r($ses);die;
         $model->attributes = $_POST['PaymentCustomerUser'];
         if ($model->validate()) {
             // echo "<pre>";print_r($_REQUEST);die;
             $exp = $_REQUEST['PaymentCustomerUser']['expire'];
             $res = explode("/", $exp);
             $month = $res[0];
             $year = $res[1];
             $cardDetail = implode(explode(" ", trim($_REQUEST['PaymentCustomerUser']['cardDetail'])));
             /*if($_REQUEST['value']==0)
               {
               	 $price=0;
               }	*/
             $paymentInfo = array('Member' => array('first_name' => $_REQUEST['PaymentCustomerUser']['cname'], 'last_name' => $_REQUEST['PaymentCustomerUser']['clname'], 'billing_address' => $_REQUEST['PaymentCustomerUser']['caddress'], 'billing_address2' => $_REQUEST['PaymentCustomerUser']['caddress'], 'billing_country' => $_REQUEST['PaymentCustomerUser']['country'], 'billing_city' => $_REQUEST['PaymentCustomerUser']['city'], 'billing_zip' => $_REQUEST['PaymentCustomerUser']['zipcode']), 'CreditCard' => array('card_number' => $cardDetail, 'expiration_month' => trim($month), 'expiration_year' => trim($year), 'cv_code' => $_REQUEST['PaymentCustomerUser']['code'], 'credit_type' => $_REQUEST['PaymentCustomerUser']['cardType']), 'Order' => array('theTotal' => $price));
             // echo "<pre>";print_r($paymentInfo);
             $result = Yii::app()->Paypal->DoDirectPayment($paymentInfo);
             //echo http_build_query($data, 'flags_');
             //echo "<pre>";print_r($result);die;
             if ($result['ACK'] == 'Failure') {
                 $links = CmsPages::model()->findAll();
                 Yii::app()->params['MyArray'] = $links;
                 Yii::app()->user->setFlash('ack', "Please check your card details");
                 $this->render('index', array('model' => $model, 'town' => $rec, 'price' => $price, 'service_id' => $service_id));
             }
             if (!Yii::app()->Paypal->isCallSucceeded($result)) {
                 if (Yii::app()->Paypal->apiLive === true) {
                     //Live mode basic error message
                     $error = 'We were unable to process your request. Please try again later';
                 } else {
                     //Sandbox output the actual error message to dive in.
                     $error = $result['L_LONGMESSAGE0'];
                 }
                 echo $error;
             } else {
                 //Payment was completed successfully, do the rest of your stuff
                 // code to register the customer and save  transaction id in differ table
                 if (!empty($result['TRANSACTIONID'])) {
                     $model->cname = $_REQUEST['PaymentCustomerUser']['cname'];
                     $model->clname = $_REQUEST['PaymentCustomerUser']['clname'];
                     $model->caddress = $_REQUEST['PaymentCustomerUser']['caddress'];
                     $model->zipcode = $_REQUEST['PaymentCustomerUser']['zipcode'];
                     $model->phone = $_REQUEST['PaymentCustomerUser']['phone'];
                     $model->email = $_REQUEST['PaymentCustomerUser']['email'];
                     $model->city = $_REQUEST['PaymentCustomerUser']['city'];
                     $model->country = $_REQUEST['PaymentCustomerUser']['country'];
                     $model->cregistered = date('Y-m-d');
                     $email = $_REQUEST['PaymentCustomerUser']['email'];
                     $user = PaymentCustomerUser::model()->exists('email=:email', array('email' => $email));
                     // $user=PaymentCustomerUser::model()->findByAttributes(array('email'=>$email));
                     //echo "<pre>";print_r($user);die;
                     //if(count($user)<0)
                     if (empty($user)) {
                         //echo "hlo";die;
                         $cleartext_password = rand(0, 9999);
                         $model->password = md5($cleartext_password);
                         if ($model->save()) {
                             $signature = md5($model->email . $model->password);
                             $subject = 'Welcome to Wow Cleans';
                             $body = $this->renderPartial('registrationEmail', array('model' => $model, 'password' => $cleartext_password, 'url' => $this->createAbsoluteUrl('../registration/login', array('email' => $model->email, 'signature' => $signature))), true);
                             Yii::app()->mailer->send($model->email, $subject, $body);
                             // booking detail for register customer here
                             $custId = Yii::app()->db->getLastInsertID();
                             $transId = $result['TRANSACTIONID'];
                             $cust = PaymentCustomerUser::model()->findByAttributes(array('id' => $custId));
                             $companyDetail = ServiceUser::model()->findByAttributes(array('id' => $_REQUEST['service_id']));
                             //echo "<pre>";print_r($companyDetail);die;
                             // save address for customer in different table
                             $address->address = $_REQUEST['PaymentCustomerUser']['caddress'];
                             $address->zipcode = $_REQUEST['PaymentCustomerUser']['zipcode'];
                             $address->date = date('Y-m-d');
                             $address->customer_id = $custId;
                             $address->save();
                             $address_id = Yii::app()->db->getLastInsertID();
                             $re = CustomerAddress::model()->findByAttributes(array('customer_id' => $custId));
                             //echo "<pre>";print_r($re);die;
                             $addressId = $re->id;
                             $booking->customer_id = $custId;
                             $booking->service_id = $_REQUEST['service_id'];
                             $booking->service_type_id = $servicetype;
                             //$booking->price          =$_REQUEST['price'];
                             $booking->price = $price;
                             $booking->trans_id = $transId;
                             $booking->date = date('Y-m-d');
                             if (!empty($address_id)) {
                                 $booking->customer_address_id = $address_id;
                             } else {
                                 $booking->customer_address_id = $addressId;
                             }
                             $detail = Yii::app()->session['detail'];
                             // echo "<pre>";print_r($detail);die;
                             foreach ($detail['Cleaning'] as $type => $number) {
                                 $cleaningDetail .= $number . "-" . $type . ",";
                             }
                             $booking->cleaningDetail = substr($cleaningDetail, 0, -1);
                             /*foreach($detail['Additional'] as $k=>$val)
                               {
                               	  if($val!=0)
                               	  {
                               	  	 $addnl .=$val."-".$k.",";
                               	  }	
                               }	*/
                             foreach ($finalDetailadnl as $k => $val) {
                                 if ($val != 0) {
                                     $addnl .= $val . "-" . $k . ",";
                                 }
                             }
                             $booking->additional = substr($addnl, 0, -1);
                             $booking->additional_details = $detail['AdditionalCustDetail']['AdditionalCustDetail'];
                             if ($booking->save()) {
                                 //booking id for thaks page
                                 $insert_id = Yii::app()->db->getLastInsertID();
                                 $cutId = Booking::model()->findByPk(array('id' => $insert_id));
                                 $customerId = $cutId->customer_id;
                                 /*code to enter the company request details in company request table*/
                                 $company->booking_id = $insert_id;
                                 $company->service_id = $_REQUEST['service_id'];
                                 $company->customer_id = $customerId;
                                 $company->cleaningtime = $ses['CleaningTime']['time'];
                                 $company->postcode = $ses['CleaningTime']['PostCode'];
                                 $company->cleaningdate = date("Y-m-d", strtotime($ses['CleaningTime']['CleaningDate']));
                                 $company->date = date('Y-m-d');
                                 $company->no_of_hours = $ses['CleaningTime']['noOfhour'];
                                 $company->no_of_cleaners = $ses['CleaningTime']['noOfCleaners'];
                                 $company->save(false);
                                 // echo $insert_id;die;
                                 // send mail to customer
                                 $subject = 'Welcome to Wow Cleans';
                                 $body = $this->renderPartial('customerEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                                 Yii::app()->mailer->send($cust->email, $subject, $body);
                                 // send mail to company
                                 $subject = 'Welcome to Wow Cleans';
                                 $body = $this->renderPartial('companyEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                                 Yii::app()->mailer->send($companyDetail->email, $subject, $body);
                                 //$this->refresh();
                                 //$this->redirect(array('../registration/index'));
                             }
                             // booking detail for register customer ends here
                             $link = CmsPages::model()->findAll();
                             Yii::app()->params['MyArray'] = $link;
                             // $this->redirect('thanks','param1'=>$companyDetail);
                             $this->redirect(array('payment/thanks', 'param1' => $insert_id));
                             //exit();
                             //$this->refresh();
                             //$this->redirect(array('registration/registration'));
                         }
                     } else {
                         // echo "fsf";die;
                         //$price     =$_REQUEST['price'];
                         $email = $_REQUEST['PaymentCustomerUser']['email'];
                         $transId = $result['TRANSACTIONID'];
                         $rec = PaymentCustomerUser::model()->findByAttributes(array('email' => $email));
                         //echo "<pre>";print_r($rec);die;
                         $custId = $rec->id;
                         $companyDetail = ServiceUser::model()->findByAttributes(array('id' => $_REQUEST['service_id']));
                         // save address for customer in different table
                         $address->address = $_REQUEST['PaymentCustomerUser']['caddress'];
                         $address->zipcode = $_REQUEST['PaymentCustomerUser']['zipcode'];
                         $address->date = date('Y-m-d');
                         $address->customer_id = $custId;
                         if (!($user = CustomerAddress::model()->exists('address=:address', array('address' => $_REQUEST['PaymentCustomerUser']['caddress'])))) {
                             $address->save();
                             $address_id = Yii::app()->db->getLastInsertID();
                         }
                         //$address_id = Yii::app()->db->getLastInsertID();
                         $re = CustomerAddress::model()->findByAttributes(array('customer_id' => $custId));
                         //echo "<pre>";print_r($rec->id);die;
                         $addressId = $re->id;
                         $booking->customer_id = $custId;
                         $booking->service_id = $_REQUEST['service_id'];
                         $booking->service_type_id = $servicetype;
                         //$booking->price          =$_REQUEST['price'];
                         $booking->price = $price;
                         $booking->trans_id = $transId;
                         $booking->date = date('Y-m-d');
                         if (!empty($address_id)) {
                             $booking->customer_address_id = $address_id;
                         } else {
                             $booking->customer_address_id = $addressId;
                         }
                         $detail = Yii::app()->session['detail'];
                         // echo "<pre>";print_r($detail);die;
                         foreach ($detail['Cleaning'] as $type => $number) {
                             $cleaningDetail .= $number . "-" . $type . ",";
                         }
                         $booking->cleaningDetail = substr($cleaningDetail, 0, -1);
                         //echo "<pre>";print_r($detail['Additional']);die;
                         /*foreach($detail['Additional'] as $k=>$val)
                           {
                           	  if($val!=0)
                           	  {
                           	  	 $addnl .=$val."-".$k.",";
                           	  }	
                           } */
                         foreach ($finalDetailadnl as $k => $val) {
                             if ($val != 0) {
                                 $addnl .= $val . "-" . $k . ",";
                             }
                         }
                         $booking->additional = substr($addnl, 0, -1);
                         $booking->additional_details = $detail['AdditionalCustDetail']['AdditionalCustDetail'];
                         if ($booking->save(false)) {
                             $insert_id = Yii::app()->db->getLastInsertID();
                             $cutId = Booking::model()->findByPk(array('id' => $insert_id));
                             //echo "<pre>";print_r($cutId);die;
                             $customerId = $cutId->customer_id;
                             /*code to add the company request details in company request table*/
                             $company->booking_id = $insert_id;
                             $company->service_id = $_REQUEST['service_id'];
                             $company->customer_id = $customerId;
                             $company->cleaningtime = $ses['CleaningTime']['time'];
                             $company->postcode = $ses['CleaningTime']['PostCode'];
                             $company->cleaningdate = date("Y-m-d", strtotime($ses['CleaningTime']['CleaningDate']));
                             $company->date = date('Y-m-d');
                             $company->no_of_hours = $ses['CleaningTime']['noOfhour'];
                             $company->no_of_cleaners = $ses['CleaningTime']['noOfCleaners'];
                             $company->save(false);
                             // send mail to customer
                             $subject = 'Welcome to Wow Cleans';
                             $body = $this->renderPartial('customerEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                             Yii::app()->mailer->send($rec->email, $subject, $body);
                             // send mail to company
                             $subject = 'Welcome to Wow Cleans';
                             $body = $this->renderPartial('companyEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                             Yii::app()->mailer->send($companyDetail->email, $subject, $body);
                             //$this->refresh();
                             if ($logged != '') {
                                 //$this->redirect(array('../registration/customerdashboard'));
                                 $this->redirect(array('payment/thanks', 'param1' => $insert_id));
                             } else {
                                 $this->redirect(array('payment/thanks', 'param1' => $insert_id));
                                 //$this->redirect(array('../registration/index'));
                             }
                         }
                         //echo $servicetype; die;
                         //echo "<pre>";print_r($rec);die;
                     }
                 }
             }
             Yii::app()->end();
         } else {
             $errors = $model->getErrors();
             // var_dump($errors);
         }
     }
     $links = CmsPages::model()->findAll();
     Yii::app()->params['MyArray'] = $links;
     $this->render('index', array('model' => $model, 'town' => $rec, 'price' => $price, 'service_id' => $service_id, 'customerDetail' => $customerDetail));
 }
コード例 #3
0
 /**
  * Extract shipping and billing address information, create address book and map to the carts
  */
 protected function actionConvertAddressBook()
 {
     $sql = "select * from xlsws_cart where billaddress_id IS NULL and address_bill IS NOT NULL order by id limit 500";
     $arrProducts = Yii::app()->db->createCommand($sql)->query();
     while (($result = $arrProducts->read()) !== false) {
         $result['email'] = strtolower($result['email']);
         //verify that Customer ID really exists in customer table
         $objCust = Customer::model()->findByPk($result['customer_id']);
         if (!$objCust instanceof Customer) {
             $result['customer_id'] = 0;
         }
         if (strlen($result['address_bill']) > 0) {
             $arrAddress = explode("\n", $result['address_bill']);
             if (count($arrAddress) == 5) {
                 //old format address, should be 6 pieces
                 $arrAddress[5] = $arrAddress[4];
                 $strSt = $arrAddress[3];
                 if ($strSt[0] == " ") {
                     //no state on this address
                     $arrAddress[4] = substr($strSt, 1, 100);
                     $arrAddress[3] = "";
                 } else {
                     $arrSt = explode(" ", $strSt);
                     $arrAddress[3] = $arrSt[0];
                     $arrAddress[4] = str_replace($arrSt[0] . " ", "", $strSt);
                 }
             }
             $objAddress = new CustomerAddress();
             if (count($arrAddress) >= 5) {
                 $objCountry = Country::LoadByCode($arrAddress[5]);
                 if ($objCountry) {
                     $objAddress->country_id = $objCountry->id;
                     $objState = State::LoadByCode($arrAddress[3], $objCountry->id);
                     if ($objState) {
                         $objAddress->state_id = $objState->id;
                     }
                 }
                 $objAddress->address1 = $arrAddress[0];
                 $objAddress->address2 = $arrAddress[1];
                 $objAddress->city = $arrAddress[2];
                 $objAddress->postal = $arrAddress[4];
                 $objAddress->first_name = $result['first_name'];
                 $objAddress->last_name = $result['last_name'];
                 $objAddress->company = $result['company'];
                 $objAddress->phone = $result['phone'];
                 $objAddress->residential = CustomerAddress::RESIDENTIAL;
                 $objAddress->created = $result['datetime_cre'];
                 $objAddress->modified = $result['datetime_cre'];
                 $objAddress->active = 1;
                 if (empty($objAddress->address2)) {
                     $objAddress->address2 = null;
                 }
                 if (empty($objAddress->company)) {
                     $objAddress->company = null;
                 }
                 $blnFound = false;
                 if ($result['customer_id'] > 0) {
                     //See if this is already in our database
                     $objPriorAddress = CustomerAddress::model()->findByAttributes(array('address1' => $objAddress->address1, 'address2' => $objAddress->address2, 'city' => $objAddress->city, 'postal' => $objAddress->postal, 'first_name' => $objAddress->first_name, 'last_name' => $objAddress->last_name, 'company' => $objAddress->company, 'phone' => $objAddress->phone));
                     if ($objPriorAddress instanceof CustomerAddress) {
                         Yii::app()->db->createCommand("update xlsws_cart set billaddress_id=" . $objPriorAddress->id . " where id=" . $result['id'])->execute();
                         $blnFound = true;
                     } else {
                         $objAddress->customer_id = $result['customer_id'];
                     }
                 } else {
                     //We need a shell customer record just for the email
                     $objC = Customer::model()->findByAttributes(array('email' => $result['email']));
                     if ($objC instanceof Customer) {
                         Yii::app()->db->createCommand("UPDATE xlsws_cart set customer_id=" . $objC->id . " where id=" . $result['id'])->execute();
                     } else {
                         $objC = new Customer();
                         $objC->record_type = Customer::GUEST;
                         $objC->email = $result['email'];
                         $objC->first_name = $objAddress->first_name;
                         $objC->last_name = $objAddress->last_name;
                         $objC->company = $objAddress->company;
                         if (!$objC->validate()) {
                             $arrErr = $objC->getErrors();
                             if (isset($arrErr['email'])) {
                                 $objC->email = $result['id'] . "*****@*****.**";
                             }
                             if (!$objC->validate()) {
                                 return print_r($objC->getErrors(), true);
                             }
                         }
                         if (!$objC->save()) {
                             Yii::log("Import Error " . print_r($objC->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                             return print_r($objC->getErrors(), true);
                         } else {
                             $cid = $objC->id;
                         }
                         Yii::app()->db->createCommand("UPDATE xlsws_cart set customer_id=" . $cid . " where id=" . $result['id'])->execute();
                     }
                     $result['customer_id'] = $objC->id;
                     $objAddress->customer_id = $result['customer_id'];
                 }
                 if (!$blnFound) {
                     if (!$objAddress->save()) {
                         //We have a corrupt billing address, just blank it out so import goes on
                         Yii::app()->db->createCommand("update xlsws_cart set address_bill=null where id=" . $result['id'])->execute();
                     } else {
                         $cid = $objAddress->id;
                         Yii::app()->db->createCommand("update xlsws_cart set billaddress_id=" . $cid . " where id=" . $result['id'])->execute();
                     }
                 }
             } else {
                 //We have a corrupt billing address, just blank it out so import goes on
                 Yii::app()->db->createCommand("update xlsws_cart set address_bill=null where id=" . $result['id'])->execute();
             }
             $objAddress = new CustomerAddress();
             $objCountry = Country::LoadByCode($result['ship_country']);
             if ($objCountry) {
                 $objAddress->country_id = $objCountry->id;
                 $objState = State::LoadByCode($result['ship_state'], $objCountry->id);
                 if ($objState) {
                     $objAddress->state_id = $objState->id;
                 }
             }
             $objAddress->first_name = $result['ship_firstname'];
             $objAddress->last_name = $result['ship_lastname'];
             $objAddress->company = $result['ship_company'];
             $objAddress->address1 = $result['ship_address1'];
             $objAddress->address2 = $result['ship_address2'];
             $objAddress->city = $result['ship_city'];
             $objAddress->postal = $result['ship_zip'];
             $objAddress->phone = $result['ship_phone'];
             $objAddress->residential = CustomerAddress::RESIDENTIAL;
             $objAddress->created = $result['datetime_cre'];
             $objAddress->modified = $result['datetime_cre'];
             $objAddress->active = 1;
             if (empty($objAddress->address2)) {
                 $objAddress->address2 = null;
             }
             if (empty($objAddress->company)) {
                 $objAddress->company = null;
             }
             $blnFound = false;
             if ($result['customer_id'] > 0) {
                 //See if this is already in our database
                 $objPriorAddress = CustomerAddress::model()->findByAttributes(array('address1' => $objAddress->address1, 'city' => $objAddress->city, 'postal' => $objAddress->postal, 'first_name' => $objAddress->first_name, 'last_name' => $objAddress->last_name, 'company' => $objAddress->company, 'phone' => $objAddress->phone));
                 if ($objPriorAddress instanceof CustomerAddress) {
                     Yii::app()->db->createCommand("update xlsws_cart set shipaddress_id=" . $objPriorAddress->id . " where id=" . $result['id'])->execute();
                     $blnFound = true;
                 } else {
                     $objAddress->customer_id = $result['customer_id'];
                 }
             }
             if (!$blnFound) {
                 if (!$objAddress->save()) {
                     Yii::log("Import Error " . print_r($objAddress->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 } else {
                     $cid = $objAddress->id;
                     Yii::app()->db->createCommand("update xlsws_cart set shipaddress_id=" . $cid . " where id=" . $result['id'])->execute();
                 }
             }
         }
         $objShipping = new CartShipping();
         $objShipping->shipping_method = $result['shipping_method'];
         $objShipping->shipping_module = $result['shipping_module'];
         $objShipping->shipping_data = $result['shipping_data'];
         $objShipping->shipping_cost = $result['shipping_cost'];
         $objShipping->shipping_sell = $result['shipping_sell'];
         if (!$objShipping->save()) {
             return print_r($objShipping->getErrors());
         } else {
             $cid = $objShipping->id;
         }
         Yii::app()->db->createCommand("update xlsws_cart set shipping_id=" . $cid . " where id=" . $result['id'])->execute();
         $objPayment = new CartPayment();
         $objPayment->payment_method = $result['payment_method'];
         $objPayment->payment_module = str_replace(".php", "", $result['payment_module']);
         $objPayment->payment_data = $result['payment_data'];
         $objPayment->payment_amount = $result['payment_amount'];
         $objPayment->datetime_posted = $result['datetime_posted'];
         if ($result['fk_promo_id'] > 0) {
             $objPromo = PromoCode::model()->findByPk($result['fk_promo_id']);
             if ($objPromo) {
                 $objPayment->promocode = $objPromo->code;
             }
         }
         if (!$objPayment->save()) {
             return print_r($objPayment->getErrors());
         } else {
             $cid = $objPayment->id;
         }
         Yii::app()->db->createCommand("update xlsws_cart set payment_id=" . $cid . " where id=" . $result['id'])->execute();
     }
     $results2 = Yii::app()->db->createCommand("select count(*) from xlsws_cart where billaddress_id IS NULL and address_bill IS NOT NULL")->queryScalar();
     if ($results2 == 0) {
         $remain = 8;
     } else {
         $remain = 3;
     }
     return array('result' => "success", 'makeline' => $remain, 'total' => 50, 'tag' => 'Converting cart addresses, ' . $results2 . ' remaining');
 }
コード例 #4
0
 /**
  * See if Customer Address already exists by searching for passed information.
  * If not, we create it.
  * @param null $config
  * @return CustomerAddress|null
  */
 public static function findOrCreate($config = null)
 {
     if (is_null($config)) {
         return null;
     }
     //Search. If successful, return object, otherwise save (to create new object) and return that
     $obj = new CustomerAddress();
     $obj->attributes = $config;
     if ($obj->validate() === false) {
         return $obj;
     }
     $dataProvider = $obj->search();
     $arrAdd = $dataProvider->getData();
     if (count($arrAdd)) {
         return $arrAdd[0];
     } else {
         $obj->save();
         return $obj;
     }
 }
コード例 #5
0
    /**
     * Displays and processes the checkout form. This is our big function which
     * validates everything and calls for order completion when done.
     * TODO: Would be better broken into small functions to aid unit testing.
     */
    public function actionCheckout()
    {
        // We shouldn't be in this controller if we don't have any products in
        // our cart.
        if (!Yii::app()->shoppingcart->itemCount) {
            Yii::log("Attempted to check out with no cart items", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
            Yii::app()->user->setFlash('warning', Yii::t('cart', 'Oops, you cannot checkout. You have no items in your cart.'));
            if (!Yii::app()->user->isGuest && Yii::app()->user->fullname == "Guest") {
                // Probably here because of cancelling an AIM payment.
                Yii::log("Checkout as Guest .. logging out", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                Yii::app()->user->logout();
            }
            $this->redirect($this->createAbsoluteUrl("/cart", array(), 'http'));
        }
        $this->pageTitle = _xls_get_conf('STORE_NAME') . ' : Checkout';
        // Set breadcrumbs.
        $this->breadcrumbs = array(Yii::t('global', 'Edit Cart') => array('/cart'), Yii::t('global', 'Checkout') => array('cart/checkout'));
        $model = new CheckoutForm();
        $model->objAddresses = CustomerAddress::getActiveAddresses();
        // If this cart was built from another person's wish list.
        if (Yii::app()->shoppingcart->HasShippableGift) {
            $model->objAddresses = array_merge($model->objAddresses, Yii::app()->shoppingcart->GiftAddress);
        }
        if (isset($_POST['CheckoutForm'])) {
            $strLogLevel = Yii::app()->getComponent('log')->routes[0]->levels;
            if (stripos($strLogLevel, ",info")) {
                $arrSubmitted = $_POST['CheckoutForm'];
                // Redact sensitive information.
                if (isset($arrSubmitted['cardNumber'])) {
                    $arrSubmitted['cardNumber'] = "A " . strlen($arrSubmitted['cardNumber']) . " digit number here";
                }
                if (isset($arrSubmitted['cardCVV'])) {
                    $arrSubmitted['cardCVV'] = "A " . strlen($arrSubmitted['cardCVV']) . " digit number here";
                }
                Yii::log("*** CHECKOUT FORM *** Submission data: " . print_r($arrSubmitted, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
            }
            $model->attributes = $_POST['CheckoutForm'];
            if (Yii::app()->params['SHIP_SAME_BILLSHIP']) {
                $model->billingSameAsShipping = 1;
            }
            // Force lower case on emails.
            $model->contactEmail = strtolower($model->contactEmail);
            $model->contactEmail_repeat = strtolower($model->contactEmail_repeat);
            $cacheModel = clone $model;
            unset($cacheModel->cardNumber);
            unset($cacheModel->cardCVV);
            unset($cacheModel->cardExpiryMonth);
            unset($cacheModel->cardExpiryYear);
            Yii::app()->session['checkout.cache'] = $cacheModel;
            if (!Yii::app()->user->IsGuest) {
                $model->setScenario('formSubmitExistingAccount');
            } elseif ($model->createPassword) {
                $model->setScenario('formSubmitCreatingAccount');
            } else {
                $model->setScenario('formSubmitGuest');
            }
            // Copy address book to field if necessary.
            $model->fillFieldsFromPreselect();
            // Validate our primary CheckoutForm model here.
            $valid = $model->validate();
            //For any payment processor with its own form -- not including CC -- validate here
            if ($model->paymentProvider) {
                $objPaymentModule = Modules::model()->findByPk($model->paymentProvider);
                $objComponent = Yii::app()->getComponent($objPaymentModule->module);
                if (isset($objComponent->subform)) {
                    Yii::log("Form validation for card provider  " . strip_tags($objComponent->name()), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    $paymentSubform = $objComponent->subform;
                    $paymentSubformModel = new $paymentSubform();
                    $paymentSubformModel->attributes = isset($_POST[$paymentSubform]) ? $_POST[$paymentSubform] : array();
                    $subValidate = $paymentSubformModel->validate();
                    $valid = $subValidate && $valid;
                } else {
                    Yii::log("Payment module " . strip_tags($objComponent->name()), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                }
            }
            //If this came in as AJAX validation, return the results and exit
            if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                echo $valid;
                Yii::app()->end();
            }
            //If all our validation passed, run our checkout procedure
            if ($valid) {
                Yii::log("All actionCheckout validation passed, attempting to complete checkout", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                $objCart = Yii::app()->shoppingcart;
                //Assign CartID if not currently assigned
                //If we have provided a password
                if ($model->createPassword) {
                    Yii::log("Password was part of CheckoutForm", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    // Test to see if we can log in with the provided password.
                    $identity = new UserIdentity($model->contactEmail, $model->createPassword);
                    $identity->authenticate();
                    switch ($identity->errorCode) {
                        case UserIdentity::ERROR_PASSWORD_INVALID:
                            //Oops, email is already in system but not with that password
                            Yii::app()->user->setFlash('error', Yii::t('global', 'This email address already exists but that is not the correct password so we cannot log you in.'));
                            Yii::log($model->contactEmail . " login from checkout with invalid password", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                            $this->refresh();
                            return;
                        case UserIdentity::ERROR_USERNAME_INVALID:
                            $objCustomer = Customer::CreateFromCheckoutForm($model);
                            $identity = new UserIdentity($model->contactEmail, $model->createPassword);
                            $identity->authenticate();
                            if ($identity->errorCode !== UserIdentity::ERROR_NONE) {
                                Yii::log("Error logging in after creating account for " . $model->contactEmail . ". Error:" . $identity->errorCode . " Cannot continue", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                                Yii::app()->user->setFlash('error', Yii::t('global', 'Error logging in after creating account. Cannot continue.'));
                                $this->refresh();
                                return;
                            }
                            break;
                        case UserIdentity::ERROR_NONE:
                            break;
                        default:
                            Yii::log("Error: Unhandled errorCode " . $identity->errorCode, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                            break;
                    }
                    $intTaxCode = Yii::app()->shoppingcart->tax_code_id;
                    //Save tax code already chosen
                    Yii::app()->user->login($identity, 3600 * 24 * 30);
                    Yii::app()->user->setState('createdoncheckout', 1);
                    Yii::app()->shoppingcart->tax_code_id = $intTaxCode;
                }
                // If we're not logged in, create guest account, or get our logged in ID.
                if (Yii::app()->user->isGuest) {
                    Yii::log("Creating Guest account to complete checkout", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    if (is_null($objCart->customer_id)) {
                        //create a new guest ID
                        $identity = new GuestIdentity();
                        Yii::app()->user->login($identity, 300);
                        $intCustomerId = $objCart->customer_id = $identity->getId();
                        $this->intGuestCheckout = 1;
                        $objCustomer = Customer::model()->findByPk($intCustomerId);
                        $objCustomer->first_name = $model->contactFirstName;
                        $objCustomer->last_name = $model->contactLastName;
                        $objCustomer->mainphone = $model->contactPhone;
                        $objCustomer->email = $model->contactEmail;
                        $objCustomer->save();
                    } else {
                        $intCustomerId = $objCart->customer_id;
                        $objCustomer = Customer::model()->findByPk($intCustomerId);
                    }
                } else {
                    $intCustomerId = Yii::app()->user->getId();
                    $objCustomer = Customer::model()->findByPk($intCustomerId);
                }
                $objCart->customer_id = $intCustomerId;
                if (trim($objCart->currency) == '') {
                    $objCart->currency = _xls_get_conf('CURRENCY_DEFAULT', 'USD');
                }
                $objCart->save();
                //If shipping address is value, then choose that
                //otherwise enter new shipping address
                //and assign value
                if ($model->intShippingAddress) {
                    $objCart->shipaddress_id = $model->intShippingAddress;
                } else {
                    Yii::log("Creating new shipping address", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    if (empty($model->shippingLabel)) {
                        $model->shippingLabel = Yii::t('global', 'Unlabeled Address');
                    }
                    $objAddress = new CustomerAddress();
                    $objAddress->customer_id = $intCustomerId;
                    $objAddress->address_label = $model->shippingLabel;
                    $objAddress->first_name = $model->shippingFirstName;
                    $objAddress->last_name = $model->shippingLastName;
                    $objAddress->address1 = $model->shippingAddress1;
                    $objAddress->address2 = $model->shippingAddress2;
                    $objAddress->city = $model->shippingCity;
                    $objAddress->state_id = $model->shippingState;
                    $objAddress->postal = $model->shippingPostal;
                    $objAddress->country_id = $model->shippingCountry;
                    $objAddress->residential = $model->shippingResidential;
                    if (!$objAddress->save()) {
                        Yii::app()->user->setFlash('error', print_r($objAddress->getErrors(), true));
                        Yii::log("Error creating CustomerAddress Shipping " . print_r($objAddress->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                        $this->refresh();
                    }
                    $objCart->shipaddress_id = $model->intShippingAddress = $objAddress->id;
                    unset($objAddress);
                }
                if ($objCustomer instanceof Customer) {
                    if (is_null($objCustomer->default_shipping_id)) {
                        $objCustomer->default_shipping_id = $model->intShippingAddress;
                        $objCustomer->save();
                        try {
                            $objCart->setTaxCodeByDefaultShippingAddress();
                        } catch (Exception $e) {
                            Yii::log("Error updating customer cart " . $e->getMessage(), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                        }
                        $objCart->recalculateAndSave();
                    }
                }
                // If billing address is value, then choose that otherwise enter
                // new billing address and assign value.
                if ($model->intBillingAddress) {
                    $objCart->billaddress_id = $model->intBillingAddress;
                } elseif ($model->billingSameAsShipping) {
                    $objCart->billaddress_id = $model->intBillingAddress = $model->intShippingAddress;
                } else {
                    if (empty($model->billingLabel)) {
                        $model->billingLabel = Yii::t('checkout', 'Unlabeled address');
                    }
                    if (!Yii::app()->user->isGuest) {
                        $objCustomer = Customer::GetCurrent();
                        if ($objCustomer instanceof Customer) {
                            $model->contactFirstName = $objCustomer->first_name;
                            $model->contactLastName = $objCustomer->last_name;
                        }
                    }
                    $objAddress = new CustomerAddress();
                    $objAddress->customer_id = $intCustomerId;
                    $objAddress->address_label = $model->billingLabel;
                    $objAddress->first_name = $model->contactFirstName;
                    $objAddress->last_name = $model->contactLastName;
                    $objAddress->company = $model->contactCompany;
                    $objAddress->address1 = $model->billingAddress1;
                    $objAddress->address2 = $model->billingAddress2;
                    $objAddress->city = $model->billingCity;
                    $objAddress->state_id = $model->billingState;
                    $objAddress->postal = $model->billingPostal;
                    $objAddress->country_id = $model->billingCountry;
                    $objAddress->phone = $model->contactPhone;
                    $objAddress->residential = $model->billingResidential;
                    if (!$objAddress->save()) {
                        Yii::app()->user->setFlash('error', print_r($objAddress->getErrors(), true));
                        Yii::log("Error creating CustomerAddress Billing " . print_r($objAddress->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                        $this->refresh();
                    }
                    $objCart->billaddress_id = $model->intBillingAddress = $objAddress->id;
                    unset($objAddress);
                }
                if ($objCustomer instanceof Customer) {
                    if (is_null($objCustomer->default_billing_id)) {
                        $objCustomer->default_billing_id = $model->intBillingAddress;
                        $objCustomer->save();
                    }
                }
                // Mark order as awaiting payment.
                Yii::log("Marking as " . OrderStatus::AwaitingPayment, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                $objCart->cart_type = CartType::awaitpayment;
                $objCart->status = OrderStatus::AwaitingPayment;
                $objCart->downloaded = 0;
                $objCart->origin = _xls_get_ip();
                $objCart->save();
                //save cart so far
                // Assign next WO number, and LinkID.
                $objCart->SetIdStr();
                Yii::log("Order assigned " . $objCart->id_str, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                $objCart->linkid = $objCart->GenerateLink();
                // Get Shipping Information.
                // Prices are stored in session from Calculate Shipping.
                // TODO: rewrite to use the "selectedCartScenario" mechanism.
                $objShippingModule = Modules::model()->findByPk($model->shippingProvider);
                $arrShippingOptionPrice = Yii::app()->session->get('ship.prices.cache', null);
                if ($arrShippingOptionPrice === null) {
                    Yii::app()->user->setFlash('error', Yii::t('global', 'Oops, something went wrong, please try submitting your order again.'));
                    Yii::log('Cannot checkout: ship.prices.cache was not cached. This should never happen.', 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    // Must use false here to prevent process termination or
                    // the UTs die completely when this occurs.
                    $this->refresh(false);
                    return;
                }
                $fltShippingSell = $arrShippingOptionPrice[$model->shippingProvider][$model->shippingPriority];
                $fltShippingCost = $fltShippingSell - $objShippingModule->markup;
                // If the chosen shipping module has In-Store pickup, charge
                // store local tax.
                if (Yii::app()->getComponent($objShippingModule->module)->IsStorePickup) {
                    Yii::log("In Store pickup chosen, requires store tax code", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    $objCart->tax_code_id = TaxCode::getDefaultCode();
                    $objCart->recalculateAndSave();
                }
                // If we have a shipping object already, update it, otherwise create it.
                if (isset($objCart->shipping)) {
                    $objShipping = $objCart->shipping;
                    //update
                } else {
                    //create
                    $objShipping = new CartShipping();
                    if (!$objShipping->save()) {
                        print_r($objShipping->getErrors());
                    }
                }
                $objShipping->shipping_module = $objShippingModule->module;
                Yii::log("Shipping module is " . $objShipping->shipping_module, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                $providerLabel = Yii::app()->session['ship.providerLabels.cache'][$model->shippingProvider];
                $priorityLabel = Yii::app()->session['ship.priorityLabels.cache'][$model->shippingProvider][$model->shippingPriority];
                if (stripos($priorityLabel, $providerLabel) !== false) {
                    $strLabel = $priorityLabel;
                } else {
                    $strLabel = $providerLabel . ' ' . $priorityLabel;
                }
                $objShipping->shipping_data = $strLabel;
                $objShipping->shipping_method = $objShippingModule->product;
                $objShipping->shipping_cost = $fltShippingCost;
                $objShipping->shipping_sell = $fltShippingSell;
                $objShipping->save();
                $objCart->shipping_id = $objShipping->id;
                $objCart->save();
                //save cart so far
                // Update the cart totals.
                $objCart->recalculateAndSave();
                // Get payment Information.
                $objPaymentModule = Modules::model()->findByPk($model->paymentProvider);
                // If we have a payment object already, update it, otherwise create it.
                if (isset($objCart->payment)) {
                    $objPayment = $objCart->payment;
                    //update
                } else {
                    //create
                    $objPayment = new CartPayment();
                    if (!$objPayment->save()) {
                        print_r($objPayment->getErrors());
                    }
                }
                Yii::log("Payment method is " . $objPaymentModule->payment_method, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                $objPayment->payment_method = $objPaymentModule->payment_method;
                $objPayment->payment_module = $objPaymentModule->module;
                $objPayment->save();
                $objCart->payment_id = $objPayment->id;
                $objCart->save();
                /* RUN PAYMENT HERE */
                Yii::log("Running payment on " . $objCart->id_str, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                // See if we have a subform for our payment module, set that as
                // part of running payment module.
                if (isset($paymentSubformModel)) {
                    $arrPaymentResult = Yii::app()->getComponent($objPaymentModule->module)->setCheckoutForm($model)->setSubForm($paymentSubformModel)->run();
                } else {
                    $arrPaymentResult = Yii::app()->getComponent($objPaymentModule->module)->setCheckoutForm($model)->run();
                }
                // If we have a full Jump submit form, render it out here.
                if (isset($arrPaymentResult['jump_form'])) {
                    Yii::log("Using payment jump form", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    $objCart->printed_notes .= $model->orderNotes;
                    $this->completeUpdatePromoCode();
                    $this->layout = '//layouts/jumper';
                    Yii::app()->clientScript->registerScript('submit', '$(document).ready(function(){
						$("form:first").submit();
						});');
                    $this->render('jumper', array('form' => $arrPaymentResult['jump_form']));
                    Yii::app()->shoppingcart->releaseCart();
                    return;
                }
                // At this point, if we have a JumpURL, off we go...
                if (isset($arrPaymentResult['jump_url']) && $arrPaymentResult['jump_url']) {
                    Yii::log("Using payment jump url", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    // Redirect to another URL for payment.
                    $objCart->printed_notes .= $model->orderNotes;
                    $this->completeUpdatePromoCode();
                    Yii::app()->shoppingcart->releaseCart();
                    Yii::app()->controller->redirect($arrPaymentResult['jump_url']);
                    return;
                }
                // to support error messages that occur with Cayan during the createTransaction process
                // see the extension for more info
                if (isset($arrPaymentResult['errorMessage'])) {
                    Yii::app()->user->setFlash('error', $arrPaymentResult['errorMessage']);
                    $this->redirect($this->createAbsoluteUrl('/cart/checkout'));
                }
                // If we are this far, we're using an Advanced Payment (or
                // non-payment like COD) so save the result of the payment
                // process (may be pass or fail).
                $objPayment->payment_data = $arrPaymentResult['result'];
                $objPayment->payment_amount = $arrPaymentResult['amount_paid'];
                $objPayment->datetime_posted = isset($retVal['payment_date']) ? date("Y-m-d H:i:s", strtotime($retVal['payment_date'])) : new CDbExpression('NOW()');
                $objPayment->save();
                if (isset($arrPaymentResult['success']) && $arrPaymentResult['success']) {
                    Yii::log("Payment Success! Wrapping up processing", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    //We have successful payment, so close out the order and show the receipt
                    $objCart->printed_notes .= $model->orderNotes;
                    $this->completeUpdatePromoCode();
                    self::EmailReceipts($objCart);
                    Yii::log('Receipt e-mails added to the queue', 'info', __CLASS__ . '.' . __FUNCTION__);
                    self::FinalizeCheckout($objCart);
                    return;
                } else {
                    Yii::app()->user->setFlash('error', isset($arrPaymentResult['result']) ? $arrPaymentResult['result'] : "UNKNOWN ERROR");
                }
            } else {
                Yii::log("Error submitting form " . print_r($model->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                Yii::app()->user->setFlash('error', Yii::t('cart', 'Please check your form for errors.'));
                if (YII_DEBUG) {
                    Yii::app()->user->setFlash('error', "DEBUG: " . _xls_convert_errors_display(_xls_convert_errors($model->getErrors())));
                }
            }
        } else {
            if (isset(Yii::app()->session['checkout.cache'])) {
                $model = Yii::app()->session['checkout.cache'];
                $model->clearErrors();
            } else {
                //If this is the first time we're displaying the Checkout form, set some defaults
                $model->setScenario('formSubmit');
                $model->billingCountry = _xls_get_conf('DEFAULT_COUNTRY');
                $model->shippingCountry = _xls_get_conf('DEFAULT_COUNTRY');
                $model->billingSameAsShipping = 1;
                $model->billingResidential = 1;
                $model->shippingResidential = 1;
                //Set our default payment module to first on the list
                $obj = new CheckoutForm();
                $data = array_keys($obj->getPaymentMethods());
                if (count($data) > 0) {
                    $model->paymentProvider = $data[0];
                }
                if (!Yii::app()->user->isGuest) {
                    //For logged in users, preset to customer account information
                    $objCustomer = Customer::GetCurrent();
                    if (!$objCustomer instanceof Customer) {
                        //somehow we're logged in without a valid Customer object
                        Yii::app()->user->logout();
                        $url = Yii::app()->createUrl('site/index');
                        $this->redirect($url);
                    }
                    $model->contactFirstName = $objCustomer->first_name;
                    $model->contactLastName = $objCustomer->last_name;
                    $model->contactPhone = $objCustomer->mainphone;
                    $model->contactEmail = $objCustomer->email;
                    if (!empty($objCustomer->defaultBilling)) {
                        $model->intBillingAddress = $objCustomer->default_billing_id;
                    }
                    if (!empty($objCustomer->defaultShipping)) {
                        $model->intShippingAddress = $objCustomer->default_shipping_id;
                    }
                } else {
                    //Set some defaults for guest checkouts
                    $model->receiveNewsletter = Yii::app()->params['DISABLE_ALLOW_NEWSLETTER'] == 1 ? 0 : 1;
                }
            }
        }
        $this->objCart = Yii::app()->shoppingcart;
        // When CheckoutForm is initialized the shippingProvider and
        // shippingPriority are null.  The AJAX validation sends empty
        // strings for these fields until a shipping option is selected.
        if (is_null($model->shippingProvider) || $model->shippingProvider === '') {
            // Use -1 to indicate that the shipping provider has not been chosen.
            $model->shippingProvider = '-1';
        }
        if (is_null($model->shippingPriority) || $model->shippingPriority === '') {
            // Use -1 to indicate that the shipping priority has not been chosen.
            $model->shippingPriority = '-1';
        }
        //If we have a default shipping address on, hide our Shipping box
        if (!empty($model->intShippingAddress) && count($model->objAddresses) > 0) {
            Yii::app()->clientScript->registerScript('shipping', '$(document).ready(function(){
				$("#CustomerContactShippingAddress").hide();
				});');
            // These need to go at POS_END because they need to be ran after
            // SinglePageCheckout has been instantiated. Further granularity in
            // the load order can be achieved by passing an integer to the
            // $position parameter. @See CClientScript::registerScript.
            Yii::app()->clientScript->registerScript('shippingforceclick', '$(document).ready(function(){
				singlePageCheckout.calculateShipping();
				});', CClientScript::POS_END);
        }
        //If we have a default billing address on, hide our Billing box
        if (!empty($model->intBillingAddress) && count($model->objAddresses) > 0) {
            Yii::app()->clientScript->registerScript('billingadd', '$(document).ready(function(){
				$("#CustomerContactBillingAddressAdd").hide();
				});');
        }
        //If Same as Billing checkbox is on, hide our Billing box
        if ($model->billingSameAsShipping) {
            Yii::app()->clientScript->registerScript('billing', 'if ($("#CheckoutForm_billingSameAsShipping:checked").length>0)
				$("#CustomerContactBillingAddress").hide();');
        }
        $paymentForms = $model->getAlternativePaymentMethodsThatUseSubForms();
        // If we have chosen a payment provider (indicating this is a refresh),
        // repick here.
        if ($model->paymentProvider > 0) {
            $objPaymentModule = Modules::model()->findByPk($model->paymentProvider);
            if ($objPaymentModule instanceof Modules) {
                $objModule = Yii::app()->getComponent($objPaymentModule->module);
                if (!$objModule) {
                    Yii::log("Error missing module " . $objPaymentModule->module, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                    $model->paymentProvider = null;
                } else {
                    $subForm = $objModule->subform;
                    if (isset($subForm)) {
                        if (isset($_POST[$subForm])) {
                            $paymentForms[$objPaymentModule->id]->attributes = $_POST[$subForm];
                            $paymentForms[$objPaymentModule->id]->validate();
                        }
                    }
                    Yii::app()->clientScript->registerScript('payment', sprintf('$(document).ready(function(){
							singlePageCheckout.changePayment(%s)
							});', CJSON::encode($model->paymentProvider)), CClientScript::POS_END);
                }
            } else {
                $model->paymentProvider = null;
            }
        }
        // Disable button on Submit to prevent double-clicking.
        $cs = Yii::app()->clientScript;
        $cs->registerScript('submit', '$("checkout:submit").mouseup(function() {
			$(this).attr("disabled",true);
			$(this).parents("form").submit();
			})', CClientScript::POS_READY);
        // This registers a backwards-compatibility shim for the pre-3.2.2
        // single-page checkout. 3.2.2 moved much of the JavaScript out of
        // checkout.php and _cartjs.php into WsSinglePageCheckout.js to
        // improve testability. This shim exists to support stores with a
        // customized checkout that is based on a version before 3.2.2. At
        // some point, we should find a way to move customers customers forward
        // and remove this shim.
        $cs->registerScript('compatibility-shim', '$(document).ready(function(){
				if (typeof singlePageCheckout === "undefined" && typeof updateShippingPriority === "function") {
					singlePageCheckout = {
						calculateShipping: function() { $("#btnCalculate").click(); },
						changePayment: function(paymentProviderId) { changePayment(paymentProviderId); },
						pickShippingProvider: function(providerId) { updateShippingPriority(providerId); },
						updateCart: function(priorityId) { updateCart(priorityId); }
					};
				}
			})', CClientScript::POS_BEGIN);
        // Clear out anything we don't to survive the round trip.
        $model->cardNumber = null;
        $model->cardCVV = null;
        $this->render('checkout', array('model' => $model, 'paymentForms' => $paymentForms));
    }