Пример #1
0
 /**
  * Actually save a new order or an updated existing order in the database
  * after it's been validated.
  *
  * @param array An array of details about the order to save.
  * @param int The ID of the existing order if we're updating an order.
  * @return boolean True if successful, false if not.
  */
 private function CommitOrder($data, $orderId = 0)
 {
     $GLOBALS['ISC_CLASS_DB']->StartTransaction();
     /**
      * We need to find our billing/shipping details from the form fields first as it is
      * also used in creating the customer
      */
     $billingDetails = array();
     $shippingDetails = array();
     $billingFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_BILLING, true);
     $shippingFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_SHIPPING, true);
     $fields = $billingFields + $shippingFields;
     $addressMap = array('FirstName' => 'firstname', 'LastName' => 'lastname', 'CompanyName' => 'company', 'AddressLine1' => 'address1', 'AddressLine2' => 'address2', 'City' => 'city', 'State' => 'state', 'Zip' => 'zip', 'State' => 'state', 'Country' => 'country', 'Phone' => 'phone');
     foreach (array_keys($fields) as $fieldId) {
         $privateName = $fields[$fieldId]->record['formfieldprivateid'];
         if ($privateName == '' || !array_key_exists($privateName, $addressMap)) {
             continue;
         }
         if ($fields[$fieldId]->record['formfieldformid'] == FORMFIELDS_FORM_BILLING) {
             $detailsVar =& $billingDetails;
         } else {
             $detailsVar =& $shippingDetails;
         }
         /**
          * Find the country
          */
         if (isc_strtolower($privateName) == 'country') {
             $detailsVar['shipcountry'] = $fields[$fieldId]->getValue();
             $detailsVar['shipcountryid'] = GetCountryByName($fields[$fieldId]->getValue());
             if (!isId($detailsVar['shipcountryid'])) {
                 $detailsVar['shipcountryid'] = 0;
             }
             /**
              * Else find the state
              */
         } else {
             if (isc_strtolower($privateName) == 'state') {
                 $detailsVar['shipstate'] = $fields[$fieldId]->getValue();
                 $stateInfo = GetStateInfoByName($detailsVar['shipstate']);
                 if ($stateInfo && isId($stateInfo['stateid'])) {
                     $detailsVar['shipstateid'] = $stateInfo['stateid'];
                 } else {
                     $detailsVar['shipstateid'] = 0;
                 }
                 /**
                  * Else the rest
                  */
             } else {
                 $detailsVar['ship' . $addressMap[$privateName]] = $fields[$fieldId]->getValue();
             }
         }
     }
     // If we're creating an account for this customer, create it now
     if ($data['ordcustid'] == 0 && $data['customerType'] == 'new') {
         $customerData = array('email' => $data['custconemail'], 'password' => $data['custpassword'], 'firstname' => $billingDetails['shipfirstname'], 'lastname' => $billingDetails['shiplastname'], 'company' => $billingDetails['shipcompany'], 'phone' => $billingDetails['shipphone'], 'token' => GenerateCustomerToken(), 'customergroupid' => $data['custgroupid']);
         $GLOBALS['CusFirstname'] = $billingDetails['shipfirstname'];
         # Baskaran
         /* Added the store credit as seperate as it may be disabled while add/edit order - vikas  */
         if (isset($data['custstorecredit'])) {
             $customerData['storecredit'] = DefaultPriceFormat($data['custstorecredit']);
         }
         /**
          * Save the customer custom fields
          */
         if (gzte11(ISC_MEDIUMPRINT)) {
             $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ACCOUNT);
             if (isId($formSessionId)) {
                 $customerData['custformsessionid'] = $formSessionId;
             }
         }
         $entity = new ISC_ENTITY_CUSTOMER();
         $data['ordcustid'] = $entity->add($customerData);
         if (!$data['ordcustid']) {
             $GLOBALS['ISC_CLASS_DB']->RollbackTransaction();
             return false;
         }
     }
     //2010-11-08 Ronnie add When calculating the ship infomation corresponding to no
     $GLOBALS['BCK_shipcountryid'] = $detailsVar['shipcountry'];
     $GLOBALS['BCK_shipstateid'] = $detailsVar['shipstate'];
     if ($GLOBALS['BCK_shipstateid'] == '') {
         $GLOBALS['BCK_shipcountryid'] = $billingDetails['shipcountry'];
         $GLOBALS['BCK_shipstateid'] = $billingDetails['shipstate'];
     }
     foreach ($this->GetCartApi()->GetProductsInCart() as $rowId => $product) {
         if (!isset($product['exists_order_coupon']) && isset($product['discount'])) {
             // Now workout the discount amount
             if ($product['coupontype'] == 0) {
                 // It's a dollar discount
                 $newPrice = $product['product_price'] - $product['discount'];
             } else {
                 // It's a percentage discount
                 $discount = $product['product_price'] / 100 * $product['discount'];
                 if ($discount == $product['product_price']) {
                     $newPrice = 0;
                 } else {
                     $newPrice = $product['product_price'] - $discount;
                 }
             }
             if ($newPrice < 0) {
                 $newPrice = 0;
             }
             $this->GetCartApi()->SetItemValue($rowId, 'discount_price', $newPrice);
         } elseif (isset($product['exists_order_coupon']) && isset($product['discount'])) {
             $this->GetCartApi()->SetItemValue($rowId, 'discount_price', $product['product_price']);
             $newPrice = 0;
             if ($product['coupontype'] == 0) {
                 // It's a dollar discount
                 $newPrice = $product['product_price'] + $product['discount'];
             } else {
                 // It's a percentage discount
                 $newPrice = $product['product_price'] / (1 - $product['discount'] / 100);
             }
             $this->GetCartApi()->SetItemValue($rowId, 'product_price', $newPrice);
         }
     }
     $orderSummary = $this->CalculateOrderSummary();
     //ronnie
     //$orderSummary['taxCost'];
     $defaultCurrency = GetDefaultCurrency();
     $email = '';
     if (isset($data['custconemail']) && $data['customerType'] == 'new') {
         $email = $data['custconemail'];
     } else {
         if (isset($data['anonymousemail']) && $data['customerType'] == 'anonymous') {
             $email = $data['anonymousemail'];
         }
     }
     /**********************************************************
     				Code added by Mayank Jaitly for getting the logged user
     				for adding his/her id as order owner.
     			************************************************************/
     $loggeduser = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetUser();
     //////////  End of alteration
     $custid = $data['ordcustid'];
     $ordstatus = '';
     $query = $GLOBALS['ISC_CLASS_DB']->Query("SELECT * FROM [|PREFIX|]customers c, [|PREFIX|]customer_groups cg WHERE c.customerid = '{$custid}' AND cg.customergroupid = c.custgroupid AND cg.groupname = 'Walk In' ");
     if ($GLOBALS['ISC_CLASS_DB']->CountResult($query) > 0) {
         $ordstatus = '10';
     } else {
         $ordstatus = $data['ordstatus'];
     }
     $billemail = $email;
     $shipemail = $email;
     if ($data['customerType'] == 'anonymous') {
         if (isset($data['anonymousemail']) && !empty($data['anonymousemail'])) {
             $billemail = $email;
             $shipemail = $email;
         } else {
             $billemail = $_POST['ordbillemail'];
             $shipemail = $_POST['ordshipemail'];
         }
     }
     $newOrder = array('paymentmethod' => $data['orderpaymentmodule'], 'customerid' => $data['ordcustid'], 'billingaddress' => $billingDetails, 'ordbillemail' => $billemail, 'ordshipemail' => $shipemail, 'ordbillphone' => $billingDetails['shipphone'], 'geoipcountry' => $billingDetails['shipcountry'], 'geoipcountrycode' => GetCountryISO2ByName($billingDetails['shipcountry']), 'vendorid' => $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId(), 'giftcertificates' => $this->GetCartApi()->GetGiftCertificates(), 'shippingcost' => $orderSummary['shippingCost'], 'handlingcost' => $orderSummary['handlingCost'], 'pending_token' => GenerateOrderToken(), 'itemtotal' => $orderSummary['subtotal'], 'taxcost' => $orderSummary['taxCost'], 'taxrate' => $orderSummary['taxRate'], 'taxname' => $orderSummary['taxName'], 'giftcertificateamount' => $orderSummary['giftCertificateTotal'], 'companygiftcertificateamount' => $orderSummary['companyGiftCertificateTotal'], 'gatewayamount' => $orderSummary['adjustedTotalCost'], 'totalincludestax' => $orderSummary['taxIncluded'], 'shippingprovider' => $orderSummary['shippingMethod'], 'shippingmodule' => $orderSummary['shippingModule'], 'totalcost' => $orderSummary['total'], 'ordstatus' => 0, 'isdigitalorder' => (int) $this->GetCartApi()->AllProductsInCartAreIntangible(), 'currencyid' => $defaultCurrency['currencyid'], 'currencyexchangerate' => 0, 'ordercomments' => @$data['ordcustmessage'], 'ordnotes' => @$data['ordnotes'], 'products' => $this->GetCartApi()->GetProductsInCart(), 'ordtrackingno' => $data['ordtrackingno'], 'orderowner' => $loggeduser['pk_userid']);
     if (isset($data['ordbillsaveAddress'])) {
         $newOrder['billingaddress']['saveAddress'] = 1;
         if (gzte11(ISC_MEDIUMPRINT)) {
             $newOrder['billingaddress']['shipformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_BILLING);
         }
     }
     if ($newOrder['paymentmethod'] == 'manual') {
         $newOrder['paymentmethodname'] = GetLang('ManualPayment');
     } else {
         if ($newOrder['paymentmethod'] == 'giftcertificate') {
             $newOrder['giftcertificateamount'] = $orderSummary['total'];
         } else {
             if ($newOrder['paymentmethod'] == 'storecredit') {
                 $newOrder['storecreditamount'] = $orderSummary['total'];
             } else {
                 if ($newOrder['paymentmethod'] == 'custom') {
                     $newOrder['paymentmethodname'] = $data['paymentField']['custom']['name'];
                 } else {
                     if ($newOrder['paymentmethod'] == 'paypal_admin') {
                         // added new condition for paypal payment option - vikas
                         $newOrder['paymentmethodname'] = GetLang('PaypalPayment');
                     } else {
                         if ($newOrder['paymentmethod'] == 'googlecheckout_admin') {
                             $newOrder['paymentmethodname'] = GetLang('GooglePayment');
                         } else {
                             if ($newOrder['paymentmethod'] == 'creditcard') {
                                 $newOrder['paymentmethodname'] = GetLang('CreditCardPayment');
                             } else {
                                 if ($newOrder['paymentmethod'] == 'cash') {
                                     $newOrder['paymentmethodname'] = GetLang('CashPayment');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!$this->GetCartApi()->AllProductsInCartAreIntangible()) {
         if (isset($data['shippingUseBilling']) && $data['shippingUseBilling'] == 1) {
             $newOrder['shippingaddress'] = $newOrder['billingaddress'];
         } else {
             $newOrder['shippingaddress'] = $shippingDetails;
             if (isset($data['ordshipsaveAddress']) && gzte11(ISC_MEDIUMPRINT)) {
                 /**
                  * This is a bit tricky. We need to convert these shipping fields to use the billing
                  * field IDs when saving in the shipping_addresses table as they all use the billing
                  * fields on the frontend
                  */
                 $shippingFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_SHIPPING, true);
                 $shippingKeys = array_keys($shippingFields);
                 $shippingMap = $GLOBALS['ISC_CLASS_FORM']->mapAddressFieldList(FORMFIELDS_FORM_SHIPPING, $shippingKeys);
                 $shippingSessData = array();
                 foreach ($shippingMap as $fieldId => $newBillingId) {
                     if ($shippingFields[$fieldId]->record['formfieldprivateid'] !== '') {
                         continue;
                     }
                     $shippingSessData[$newBillingId] = $shippingFields[$fieldId]->getValue();
                 }
                 $newOrder['shippingaddress']['shipformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($shippingSessData);
             }
         }
         if (isset($data['ordshipsaveAddress'])) {
             $newOrder['shippingaddress']['saveAddress'] = 1;
         }
     }
     if ($orderId > 0) {
         $existingOrder = GetOrder($orderId);
         $newOrder['vendorid'] = $existingOrder['ordvendorid'];
         $newOrder['extraInfo'] = @unserialize($existingOrder['extrainfo']);
         //Alandy_2011-14-20 debug credit amount error! recalculate the gatewayamount,fetch the gatewayamount from profer order is wrong!
         //$newOrder['gatewayamount'] = $existingOrder['ordgatewayamount'];
         $newOrder['storecreditamount'] = $existingOrder['ordstorecreditamount'];
         $newOrder['currencyid'] = $existingOrder['ordcurrencyid'];
         $newOrder['currencyexchangerate'] = $existingOrder['ordcurrencyexchangerate'];
         $newOrder['orderid'] = $orderId;
         $newOrder['orddate'] = $existingOrder['orddate'];
         $newOrder['ordipaddress'] = $existingOrder['ordipaddress'];
     }
     /**
      * Save the billing/shipping custom fields for the order
      */
     if (gzte11(ISC_MEDIUMPRINT)) {
         if (isId($orderId) && isset($existingOrder['ordformsessionid']) && isId($existingOrder['ordformsessionid'])) {
             $GLOBALS['ISC_CLASS_FORM']->saveFormSession(array(FORMFIELDS_FORM_BILLING, FORMFIELDS_FORM_SHIPPING), true, $existingOrder['ordformsessionid']);
         } else {
             $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(array(FORMFIELDS_FORM_BILLING, FORMFIELDS_FORM_SHIPPING));
             if (isId($formSessionId)) {
                 $newOrder['ordformsessionid'] = $formSessionId;
             }
         }
     }
     // dada.wang 20120406 save cgc change
     $cgces = $this->GetCartApi()->Get('COMPANYGIFTCERTIFICATES');
     if (is_array($cgces) && !empty($cgces)) {
         $newOrder['companygiftcertificates'] = $cgces;
     }
     $entity = new ISC_ENTITY_ORDER();
     if (isset($existingOrder)) {
         $newOrder['adminflag'] = 1;
         //dada.wang 2012-04-10 if has gc or cgc was remove then use this function to remove it
         $this->RemoveGCAndCGC($newOrder);
         if (!$entity->edit($newOrder)) {
             $GLOBALS['ISC_CLASS_DB']->RollbackTransaction();
             return false;
         }
     } else {
         $newOrder['adminflag'] = 1;
         $data['orderid'] = $entity->add($newOrder);
         if (!$data['orderid']) {
             $GLOBALS['ISC_CLASS_DB']->RollbackTransaction();
             return false;
         }
         $newOrder['orderid'] = $data['orderid'];
     }
     // If one or more gift certificates were used we need to apply them to this order
     if ($newOrder['giftcertificateamount'] > 0 && isset($newOrder['giftcertificates']) && !empty($newOrder['giftcertificates'])) {
         $usedCertificates = array();
         $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES'] = GetClass('ISC_GIFTCERTIFICATES');
         $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES']->ApplyGiftCertificatesToOrder($newOrder['orderid'], $newOrder['totalcost'], $newOrder['giftcertificates'], $usedCertificates);
     }
     // Add by NI_20100827_Jack
     // If one or more gift certificates were used we need to apply them to this order
     if ($newOrder['companygiftcertificateamount'] > 0 && isset($newOrder['companygiftcertificates']) && !empty($newOrder['companygiftcertificates'])) {
         $usedCertificates = array();
         $GLOBALS['ISC_CLASS_COMPANY_GIFT_CERTIFICATES'] = GetClass('ISC_COMPANYGIFTCERTIFICATES');
         $GLOBALS['ISC_CLASS_COMPANY_GIFT_CERTIFICATES']->ApplyCompanyGiftCertificatesToOrder($newOrder['orderid'], $newOrder['totalcost'], $newOrder['companygiftcertificates'], $usedCertificates);
     }
     $GLOBALS['ISC_CLASS_DB']->CommitTransaction();
     // Did the payment method have any info it needs to save? Save it
     $provider = null;
     GetModuleById('checkout', $provider, $data['orderpaymentmodule']);
     if (is_object($provider) && method_exists($provider, 'SaveManualPaymentFields')) {
         $fields = $data['paymentField'][$data['orderpaymentmodule']];
         $provider->SaveManualPaymentFields(GetOrder($data['orderid'], false, false), $fields);
     }
     if ($data['ordstatus'] != $newOrder['ordstatus']) {
         UpdateOrderStatus($data['orderid'], $data['ordstatus'], false);
     }
     // If we're emailing the customer about their order, send it now
     if (isset($data['emailinvoice']) && $data['emailinvoice'] == 1) {
         EmailInvoiceToCustomer($data['orderid']);
     }
     unset($_SESSION['ORDER_MANAGER'][$data['orderSession']]);
     /*************************************************************
     					Alterations done by Mayank Jaitly on 28 June 2010
     			**************************************************************/
     /*	
     // commented the below code as this is not needed.
     	$customerYMMdata=array(
     						   	'year' => $data['searchyear'],
     							'make' => $data['searchmake'],
     							'model' => MakeURLNormal($data['searchmodel']),
     							'bed_size' =>$data['bedsize'],
     							'cab_size' =>$data['cabsize']
     							
     						   );
     							   
     	$clarion_entity = new ISC_ADMIN_CLARION();
     	$ymmID=$clarion_entity->fnSaveUserYMM($customerYMMdata,$data['ordcustid'],$_REQUEST['customerType'],$data['orderid']);
     */
     /***********************	End of Alteration		*********/
     /***************************************************************
     				Code Added by Mayank Jaitly on 29 June 2010
     			****************************************************************/
     // commented the below code as this is not needed.
     //	$clarion_entity->fnUpdateOrderYMM($data['orderid'],$ymmID);
     /********************* End of code   **************************/
     return $data['orderid'];
 }
Пример #2
0
 private function CreateAccountStep2()
 {
     $savedataDetails = array(FORMFIELDS_FORM_ACCOUNT => array('EmailAddress' => 'email', 'Password' => 'password', 'ConfirmPassword' => 'confirmpassword', 'FirstName' => 'firstname', 'LastName' => 'lastname', 'CompanyName' => 'company', 'Phone' => 'phone'), FORMFIELDS_FORM_ADDRESS => array('FirstName' => 'shipfirstname', 'LastName' => 'shiplastname', 'CompanyName' => 'shipcompany', 'AddressLine1' => 'shipaddress1', 'AddressLine2' => 'shipaddress2', 'City' => 'shipcity', 'State' => 'shipstate', 'Country' => 'shipcountry', 'Zip' => 'shipzip', 'Phone' => 'shipphone', 'BuildingType' => 'shipdestination'));
     /**
      * Validate and map submitted field data in one loop
      */
     $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ACCOUNT, true);
     $fields += $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ADDRESS, true);
     $customerData = array();
     $shippingData = array();
     $password = '';
     $confirmPassword = '';
     foreach (array_keys($fields) as $fieldId) {
         /**
          * Validate
          */
         $errmsg = '';
         if (!$fields[$fieldId]->runValidation($errmsg)) {
             return $this->CreateAccountStep1($errmsg);
         }
         foreach ($savedataDetails as $type => $map) {
             /**
              * Are we in the customer section or the shipping?
              */
             if ($type == FORMFIELDS_FORM_ACCOUNT) {
                 $referencedData =& $customerData;
             } else {
                 $referencedData =& $shippingData;
             }
             /**
              * We're only interested in the private custom fields here
              */
             if (array_key_exists($fields[$fieldId]->record['formfieldprivateid'], $map)) {
                 $label = $map[$fields[$fieldId]->record['formfieldprivateid']];
                 $referencedData[$label] = $fields[$fieldId]->getValue();
                 /**
                  * Store the values somewhere if this is a apssword/confirm-password field
                  */
                 if ($fields[$fieldId]->record['formfieldprivateid'] == 'Password') {
                     $password = $referencedData[$label];
                 } else {
                     if ($fields[$fieldId]->record['formfieldprivateid'] == 'ConfirmPassword') {
                         $confirmPassword = $referencedData[$label];
                     }
                 }
             }
         }
     }
     /**
      * Clean up some of the data
      */
     if (isset($shippingData['shipstate'])) {
         $state = GetStateInfoByName($shippingData['shipstate']);
         if ($state) {
             $shippingData['shipstateid'] = $state['stateid'];
         } else {
             $shippingData['shipstateid'] = '';
         }
     }
     if (isset($shippingData['shipcountry'])) {
         $countryId = GetCountryByName($shippingData['shipcountry']);
         if (isId($countryId)) {
             $shippingData['shipcountryid'] = $countryId;
         } else {
             $shippingData['shipcountryid'] = '';
         }
     }
     if (isset($shippingData['shipdestination'])) {
         $data = $fields[$fieldId]->getValue();
         if (isc_strtolower($shippingData[$label]) == 'house') {
             $shippingData[$label] = 'residential';
         } else {
             $shippingData[$label] = 'commercial';
         }
     }
     $customerData["shipping_address"] = $shippingData;
     $captcha = '';
     if (isset($_POST['captcha'])) {
         $captcha = $_POST['captcha'];
     }
     $captcha_check = true;
     // Do we need to check captcha?
     if (GetConfig('CaptchaEnabled')) {
         $GLOBALS['ISC_CLASS_CAPTCHA'] = GetClass('ISC_CAPTCHA');
         if (isc_strtolower($captcha) == isc_strtolower($GLOBALS['ISC_CLASS_CAPTCHA']->LoadSecret())) {
             // Captcha validation succeeded
             $captcha_check = true;
         } else {
             // Captcha validation failed
             $captcha_check = false;
         }
     }
     if (!$captcha_check) {
         $this->CreateAccountStep1(GetLang("CaptchaCodeError"));
         die;
     }
     // Does an account with this email address already exist?
     if ($this->AccountWithEmailAlreadyExists(trim($customerData['email']))) {
         $this->CreateAccountStep1("already_exists");
     } else {
         if (!$this->ValidatePhoneNumber($customerData['phone'])) {
             $this->CreateAccountStep1("invalid_number");
         } else {
             if ($password !== $confirmPassword) {
                 $this->CreateAccountStep1("invalid_passwords");
             } else {
                 // Create the user account in the database
                 $token = GenerateCustomerToken();
                 /* Added for to get customer group id, and save for new customer -- Baskaran */
                 $result = $GLOBALS['ISC_CLASS_DB']->Query("select customergroupid from [|PREFIX|]customer_groups where isdefault = '1'");
                 $groupid = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
                 if ($GLOBALS['ISC_CLASS_DB']->CountResult($result) > '0') {
                     $customerData['customergroupid'] = $groupid['customergroupid'];
                 } else {
                     $customerData['customergroupid'] = 0;
                 }
                 /* code ends */
                 $customerData['token'] = $token;
                 $_SESSION['FROM_REG'] = 0;
                 $customerId = $this->CreateCustomerAccount($customerData);
                 /* delete the guest account with the same email
                 			if ($this->AccountWithEmailAlreadyExists(trim($customerData['email']), 0, 1)) {
                 				$cusquery = "SELECT customerid
                 					FROM [|PREFIX|]customers
                 					WHERE isguest = 1 AND LOWER(custconemail)='" . $GLOBALS['ISC_CLASS_DB']->Quote(isc_strtolower(trim($customerData['email']))) . "'";
                 				$cusresult = $GLOBALS['ISC_CLASS_DB']->Query($cusquery);
                 				$cusrow = $GLOBALS['ISC_CLASS_DB']->Fetch($cusresult);
                 				$custId = $cusrow['customerid'];
                 				$entity = new ISC_ENTITY_CUSTOMER();
                 				$entity->delete($custId);
                 			}*/
                 if (isId($customerId)) {
                     // The account was created, let's log them in automatically
                     $this->LoginCustomerById($customerId, true);
                     // Show the "thank you for registering" page
                     if (isset($_SESSION['LOGIN_REDIR']) && $_SESSION['LOGIN_REDIR'] != '') {
                         $GLOBALS['Continue'] = GetLang('ClickHereToContinue');
                         $GLOBALS['ContinueLink'] = urldecode($_SESSION['LOGIN_REDIR']);
                         $_SESSION['FROM_REG'] = 1;
                     } else {
                         $GLOBALS['Continue'] = GetLang('ClickHereContinueShopping');
                         $GLOBALS['ContinueLink'] = $GLOBALS['ShopPath'];
                     }
                     $GLOBALS['ISC_LANG']['CreateAccountThanksIntro'] = sprintf(GetLang('CreateAccountThanksIntro'), $GLOBALS['StoreName'], isc_html_escape($customerData['email']));
                     $GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(GetConfig('StoreName') . " - " . GetLang('CreateAccountThanks'));
                     if (!isset($_SESSION['IsCheckingOut'])) {
                         // Take them to the default thank you page if they aren't checking out
                         $GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("createaccount_thanks");
                         $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate();
                     } else {
                         /**
                          * This is an order so take them straight to the shipping provider page. Also save the
                          * shipping address here as we will need the custom fields
                          */
                         if (isset($_SESSION['CHECKOUT']['IS_SPLIT_SHIPPING']) && $_SESSION['CHECKOUT']['IS_SPLIT_SHIPPING'] == true) {
                             header("Location: " . $GLOBALS['ShopPath'] . "/checkout.php?action=multiple");
                         } else {
                             header("Location: " . $GLOBALS['ShopPath'] . "/checkout.php");
                         }
                     }
                     die;
                 } else {
                     // Couldn't create the account
                     $this->CreateAccountStep1("database_error");
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Actually save a new order or an updated existing order in the database
  * after it's been validated.
  *
  * @param array An array of details about the order to save.
  * @param int The ID of the existing order if we're updating an order.
  * @return boolean True if successful, false if not.
  */
 private function CommitOrder($data, $orderId = 0)
 {
     $GLOBALS['ISC_CLASS_DB']->StartTransaction();
     /**
      * We need to find our billing/shipping details from the form fields first as it is
      * also used in creating the customer
      */
     $billingDetails = array();
     $shippingDetails = array();
     $billingFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_BILLING, true);
     $shippingFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_SHIPPING, true);
     $fields = $billingFields + $shippingFields;
     $addressMap = array('FirstName' => 'firstname', 'LastName' => 'lastname', 'CompanyName' => 'company', 'AddressLine1' => 'address1', 'AddressLine2' => 'address2', 'City' => 'city', 'State' => 'state', 'Zip' => 'zip', 'State' => 'state', 'Country' => 'country', 'Phone' => 'phone');
     foreach (array_keys($fields) as $fieldId) {
         $privateName = $fields[$fieldId]->record['formfieldprivateid'];
         if ($privateName == '' || !array_key_exists($privateName, $addressMap)) {
             continue;
         }
         if ($fields[$fieldId]->record['formfieldformid'] == FORMFIELDS_FORM_BILLING) {
             $detailsVar =& $billingDetails;
         } else {
             $detailsVar =& $shippingDetails;
         }
         /**
          * Find the country
          */
         if (isc_strtolower($privateName) == 'country') {
             $detailsVar['shipcountry'] = $fields[$fieldId]->getValue();
             $detailsVar['shipcountryid'] = GetCountryByName($fields[$fieldId]->getValue());
             if (!isId($detailsVar['shipcountryid'])) {
                 $detailsVar['shipcountryid'] = 0;
             }
             /**
              * Else find the state
              */
         } else {
             if (isc_strtolower($privateName) == 'state') {
                 $detailsVar['shipstate'] = $fields[$fieldId]->getValue();
                 $stateInfo = GetStateInfoByName($detailsVar['shipstate']);
                 if ($stateInfo && isId($stateInfo['stateid'])) {
                     $detailsVar['shipstateid'] = $stateInfo['stateid'];
                 } else {
                     $detailsVar['shipstateid'] = 0;
                 }
                 /**
                  * Else the rest
                  */
             } else {
                 $detailsVar['ship' . $addressMap[$privateName]] = $fields[$fieldId]->getValue();
             }
         }
     }
     // If we're creating an account for this customer, create it now
     if ($data['ordcustid'] == 0 && $data['customerType'] == 'new') {
         $customerData = array('email' => $data['custconemail'], 'password' => $data['custpassword'], 'firstname' => $billingDetails['shipfirstname'], 'lastname' => $billingDetails['shiplastname'], 'company' => $billingDetails['shipcompany'], 'phone' => $billingDetails['shipphone'], 'token' => GenerateCustomerToken(), 'customergroupid' => $data['custgroupid'], 'storecredit' => DefaultPriceFormat($data['custstorecredit']));
         /**
          * Save the customer custom fields
          */
         if (gzte11(ISC_MEDIUMPRINT)) {
             $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ACCOUNT);
             if (isId($formSessionId)) {
                 $customerData['custformsessionid'] = $formSessionId;
             }
         }
         $entity = new ISC_ENTITY_CUSTOMER();
         $data['ordcustid'] = $entity->add($customerData);
         if (!$data['ordcustid']) {
             $GLOBALS['ISC_CLASS_DB']->RollbackTransaction();
             return false;
         }
     }
     $orderSummary = $this->CalculateOrderSummary();
     $defaultCurrency = GetDefaultCurrency();
     $email = '';
     if (isset($data['custconemail']) && $data['customerType'] == 'new') {
         $email = $data['custconemail'];
     } else {
         if (isset($data['anonymousemail']) && $data['customerType'] == 'anonymous') {
             $email = $data['anonymousemail'];
         }
     }
     $newOrder = array('paymentmethod' => $data['orderpaymentmodule'], 'customerid' => $data['ordcustid'], 'billingaddress' => $billingDetails, 'ordbillemail' => $email, 'ordbillphone' => $billingDetails['shipphone'], 'geoipcountry' => $billingDetails['shipcountry'], 'geoipcountrycode' => GetCountryISO2ByName($billingDetails['shipcountry']), 'vendorid' => $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId(), 'giftcertificates' => $this->GetCartApi()->GetGiftCertificates(), 'shippingcost' => $orderSummary['shippingCost'], 'handlingcost' => $orderSummary['handlingCost'], 'pending_token' => GenerateOrderToken(), 'itemtotal' => $orderSummary['subtotal'], 'taxcost' => $orderSummary['taxCost'], 'taxrate' => $orderSummary['taxRate'], 'taxname' => $orderSummary['taxName'], 'giftcertificateamount' => $orderSummary['giftCertificateTotal'], 'gatewayamount' => $orderSummary['adjustedTotalCost'], 'totalincludestax' => $orderSummary['taxIncluded'], 'shippingprovider' => $orderSummary['shippingMethod'], 'shippingmodule' => $orderSummary['shippingModule'], 'totalcost' => $orderSummary['total'], 'ordstatus' => 0, 'isdigitalorder' => (int) $this->GetCartApi()->AllProductsInCartAreIntangible(), 'currencyid' => $defaultCurrency['currencyid'], 'currencyexchangerate' => 0, 'ordercomments' => @$data['ordcustmessage'], 'ordnotes' => @$data['ordnotes'], 'products' => $this->GetCartApi()->GetProductsInCart(), 'ordtrackingno' => $data['ordtrackingno']);
     if (isset($data['ordbillsaveAddress'])) {
         $newOrder['billingaddress']['saveAddress'] = 1;
         if (gzte11(ISC_MEDIUMPRINT)) {
             $newOrder['billingaddress']['shipformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_BILLING);
         }
     }
     if ($newOrder['paymentmethod'] == 'manual') {
         $newOrder['paymentmethodname'] = GetLang('ManualPayment');
     } else {
         if ($newOrder['paymentmethod'] == 'giftcertificate') {
             $newOrder['giftcertificateamount'] = $orderSummary['total'];
         } else {
             if ($newOrder['paymentmethod'] == 'storecredit') {
                 $newOrder['storecreditamount'] = $orderSummary['total'];
             } else {
                 if ($newOrder['paymentmethod'] == 'custom') {
                     $newOrder['paymentmethodname'] = $data['paymentField']['custom']['name'];
                 }
             }
         }
     }
     if (!$this->GetCartApi()->AllProductsInCartAreIntangible()) {
         if (isset($data['shippingUseBilling']) && $data['shippingUseBilling'] == 1) {
             $newOrder['shippingaddress'] = $newOrder['billingaddress'];
         } else {
             $newOrder['shippingaddress'] = $shippingDetails;
             if (isset($data['ordshipsaveAddress']) && gzte11(ISC_MEDIUMPRINT)) {
                 /**
                  * This is a bit tricky. We need to convert these shipping fields to use the billing
                  * field IDs when saving in the shipping_addresses table as they all use the billing
                  * fields on the frontend
                  */
                 $shippingFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_SHIPPING, true);
                 $shippingKeys = array_keys($shippingFields);
                 $shippingMap = $GLOBALS['ISC_CLASS_FORM']->mapAddressFieldList(FORMFIELDS_FORM_SHIPPING, $shippingKeys);
                 $shippingSessData = array();
                 foreach ($shippingMap as $fieldId => $newBillingId) {
                     if ($shippingFields[$fieldId]->record['formfieldprivateid'] !== '') {
                         continue;
                     }
                     $shippingSessData[$newBillingId] = $shippingFields[$fieldId]->getValue();
                 }
                 $newOrder['shippingaddress']['shipformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($shippingSessData);
             }
         }
         if (isset($data['ordshipsaveAddress'])) {
             $newOrder['shippingaddress']['saveAddress'] = 1;
         }
     }
     if ($orderId > 0) {
         $existingOrder = GetOrder($orderId);
         $newOrder['vendorid'] = $existingOrder['ordvendorid'];
         $newOrder['extraInfo'] = @unserialize($existingOrder['extrainfo']);
         $newOrder['gatewayamount'] = $existingOrder['ordgatewayamount'];
         $newOrder['storecreditamount'] = $existingOrder['ordstorecreditamount'];
         $newOrder['currencyid'] = $existingOrder['ordcurrencyid'];
         $newOrder['currencyexchangerate'] = $existingOrder['ordcurrencyexchangerate'];
         $newOrder['orderid'] = $orderId;
         $newOrder['orddate'] = $existingOrder['orddate'];
         $newOrder['ordipaddress'] = $existingOrder['ordipaddress'];
     }
     /**
      * Save the billing/shipping custom fields for the order
      */
     if (gzte11(ISC_MEDIUMPRINT)) {
         if (isId($orderId) && isset($existingOrder['ordformsessionid']) && isId($existingOrder['ordformsessionid'])) {
             $GLOBALS['ISC_CLASS_FORM']->saveFormSession(array(FORMFIELDS_FORM_BILLING, FORMFIELDS_FORM_SHIPPING), true, $existingOrder['ordformsessionid']);
         } else {
             $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(array(FORMFIELDS_FORM_BILLING, FORMFIELDS_FORM_SHIPPING));
             if (isId($formSessionId)) {
                 $newOrder['ordformsessionid'] = $formSessionId;
             }
         }
     }
     $entity = new ISC_ENTITY_ORDER();
     if (isset($existingOrder)) {
         if (!$entity->edit($newOrder)) {
             $GLOBALS['ISC_CLASS_DB']->RollbackTransaction();
             return false;
         }
     } else {
         $data['orderid'] = $entity->add($newOrder);
         if (!$data['orderid']) {
             $GLOBALS['ISC_CLASS_DB']->RollbackTransaction();
             return false;
         }
     }
     // If one or more gift certificates were used we need to apply them to this order
     if ($newOrder['giftcertificateamount'] > 0 && isset($newOrder['giftcertificates']) && !empty($newOrder['giftcertificates'])) {
         $usedCertificates = array();
         $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES'] = GetClass('ISC_GIFTCERTIFICATES');
         $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES']->ApplyGiftCertificatesToOrder($newOrder['orderid'], $newOrder['totalcost'], $newOrder['giftcertificates'], $usedCertificates);
     }
     $GLOBALS['ISC_CLASS_DB']->CommitTransaction();
     // Did the payment method have any info it needs to save? Save it
     $provider = null;
     GetModuleById('checkout', $provider, $data['orderpaymentmodule']);
     if (is_object($provider) && method_exists($provider, 'SaveManualPaymentFields')) {
         $fields = $data['paymentField'][$data['orderpaymentmodule']];
         $provider->SaveManualPaymentFields(GetOrder($data['orderid'], false, false), $fields);
     }
     if ($data['ordstatus'] != $newOrder['ordstatus']) {
         UpdateOrderStatus($data['orderid'], $data['ordstatus'], false);
     }
     // If we're emailing the customer about their order, send it now
     if (isset($data['emailinvoice']) && $data['emailinvoice'] == 1) {
         EmailInvoiceToCustomer($data['orderid']);
     }
     unset($_SESSION['ORDER_MANAGER'][$data['orderSession']]);
     return $data['orderid'];
 }
Пример #4
0
/**
 *	Return a state's ISO code based on its name
 */
function GetStateISO2ByName($stateName)
{
    $stateInfo = GetStateInfoByName($stateName);
    if (isset($stateInfo['stateid'])) {
        return $stateInfo['stateabbrv'];
    } else {
        return false;
    }
}
Пример #5
0
 /**
  * Validate an incoming shipping or billing address checking for missing fields and showing error
  * messages where necessary. Returns a structured address array if the passed address is valid.
  *
  * @param string The type of address to validate (billing or shipping)
  * @return array An array of information about the address if valid.
  */
 private function GetExpressCheckoutAddressData($type)
 {
     // Check to see if our state is required for the selected country
     $stateRequired = false;
     if (isset($_POST[$type . '_country']) && isId($_POST[$type . '_country']) && (!isset($_POST[$type . '_state']) || !$_POST[$type . '_state'])) {
         $query = $GLOBALS['ISC_CLASS_DB']->Query("SELECT COUNT(*) AS Total FROM [|PREFIX|]country_states WHERE statecountry='" . (int) $_POST[$type . '_country'] . "'");
         if (($total = $GLOBALS['ISC_CLASS_DB']->FetchOne($query, 'Total')) > 0) {
             $stateRequired = true;
         }
     }
     $addressVars = array('shipfirstname' => array('field' => $type . '_FirstName', 'required' => true, 'message' => GetLang('EnterShippingFirstName')), 'shiplastname' => array('field' => $type . '_LastName', 'required' => true, 'message' => GetLang('EnterShippingLastName')), 'shipcompany' => array('field' => $type . '_CompanyName', 'required' => false), 'shipaddress1' => array('field' => $type . '_AddressLine1', 'required' => true, 'message' => GetLang('EnterShippingAddress')), 'shipaddress2' => array('field' => $type . '_AddressLine2', 'required' => false), 'shipcity' => array('field' => $type . '_City', 'required' => true, 'message' => GetLang('EnterShippingCity')), 'shipstate' => array('field' => $type . '_State', 'required' => $stateRequired, 'message' => GetLang('EnterShippingState')), 'shipzip' => array('field' => $type . '_Zip', 'required' => true, 'message' => GetLang('EnterShippingZip')), 'shipcountry' => array('field' => $type . '_Country', 'required' => true, 'message' => GetLang('EnterShippingCountry')), 'shipphone' => array('field' => $type . '_Phone', 'required' => true, 'message' => GetLang('EnterShippingPhone')));
     if ($type == 'billing' && !CustomerIsSignedIn()) {
         $addressVars['shipemail'] = array('field' => 'billing_EmailAddress', 'required' => true, 'message' => GetLang('AccountEnterValidEmail'));
     }
     $addressData = array();
     $step = ucfirst($type) . 'Address';
     foreach ($addressVars as $field => $fieldInfo) {
         $postField = $fieldInfo['field'];
         // If this field is required and it hasn't been passed then we need to spit out an error
         if ($fieldInfo['required'] == true && (!isset($_POST[$postField]) || !$_POST[$postField])) {
             $tags[] = $this->MakeXMLTag('status', 0);
             $tags[] = $this->MakeXMLTag('step', $step);
             $tags[] = $this->MakeXMLTag('focus', '#' . $postField);
             $tags[] = $this->MakeXMLTag('message', $fieldInfo['message']);
             $this->SendXMLHeader();
             $this->SendXMLResponse($tags);
             exit;
         }
         // If the state field, we also need to get the ID of the state and save it too
         if ($field == 'shipstate') {
             $stateInfo = GetStateInfoByName($_POST[$postField]);
             $addressData['shipstate'] = $_POST[$postField];
             if ($stateInfo) {
                 $addressData['shipstateid'] = $stateInfo['stateid'];
             } else {
                 $addressData['shipstateid'] = 0;
             }
             continue;
         } else {
             if ($field == 'shipcountry') {
                 $addressData['shipcountry'] = $_POST[$postField];
                 $addressData['shipcountryid'] = GetCountryByName($_POST[$postField]);
                 if (!isId($addressData['shipcountryid'])) {
                     $addressData['shipcountryid'] = 0;
                 }
                 continue;
             }
         }
         $addressData[$field] = $_POST[$postField];
     }
     $addressData['shipdestination'] = 'residential';
     // OK, we've got everything we want, we can just return it now
     return $addressData;
 }
Пример #6
0
 /**
  * Validate an incoming shipping/billing address.
  *
  * @param string The type of address to validate (billing or shipping)
  * @param array An array of errors, passed by reference - if there are any
  * @return array An array of information about the address if valid.
  */
 public function ValidateGuestCheckoutAddress($type, &$errors)
 {
     $errors = array();
     $addressVars = array('shipfirstname' => array('field' => $type . '_FirstName', 'required' => true, 'message' => GetLang('EnterShippingFirstName')), 'shiplastname' => array('field' => $type . '_LastName', 'required' => true, 'message' => GetLang('EnterShippingLastName')), 'shipcompany' => array('field' => $type . '_CompanyName', 'required' => false), 'shipaddress1' => array('field' => $type . '_AddressLine1', 'required' => true, 'message' => GetLang('EnterShippingAddress')), 'shipaddress2' => array('field' => $type . '_AddressLine2', 'required' => false), 'shipcity' => array('field' => $type . '_City', 'required' => true, 'message' => GetLang('EnterShippingCity')), 'shipstate' => array('field' => $type . '_State', 'required' => true, 'message' => GetLang('EnterShippingState')), 'shipzip' => array('field' => $type . '_Zip', 'required' => true, 'message' => GetLang('EnterShippingZip')), 'shipcountry' => array('field' => $type . '_Country', 'required' => true, 'message' => GetLang('EnterShippingCountry')));
     if ($type == 'billing' && !CustomerIsSignedIn()) {
         if (!isset($_POST['billing_EmailAddress']) || !is_email_address($_POST['billing_EmailAddress'])) {
             $errors[] = GetLang('AccountEnterValidEmail');
             return false;
         }
         $_POST['shipemail'] = $_POST['billing_EmailAddress'];
         // Check that this email address isn't already in use by a customer
         $customer = GetClass('ISC_CUSTOMER');
         if ($customer->AccountWithEmailAlreadyExists($_POST['shipemail'])) {
             $errors[] = sprintf(GetLang('CheckoutEmailAddressInUse'), GetConfig('ShopPath') . '/login.php');
             return false;
         }
     }
     $addressData = array();
     foreach ($addressVars as $field => $fieldInfo) {
         $postField = $fieldInfo['field'];
         // If this field is required and it hasn't been passed then we need to spit out an error
         if ($fieldInfo['required'] == true && (!isset($_POST[$postField]) || $_POST[$postField] == '')) {
             $errors[] = $fieldInfo['message'];
             return false;
         }
         // If the state field, we also need to get the ID of the state and save it too
         if ($field == 'shipstate') {
             $addressData['shipstate'] = $_POST[$type . '_State'];
             $addressData['shipstateid'] = 0;
             $stateInfo = GetStateInfoByName($_POST[$type . '_State']);
             if ($stateInfo) {
                 $addressData['shipstateid'] = $stateInfo['stateid'];
             }
             continue;
         } else {
             if ($field == 'shipcountry') {
                 $addressData['shipcountry'] = $_POST[$postField];
                 $addressData['shipcountryid'] = GetCountryByName($_POST[$postField]);
                 continue;
             }
         }
         $addressData[$field] = $_POST[$postField];
     }
     $addressData['shipdestination'] = 'residential';
     // OK, we've got everything we want, we can just return it now
     return $addressData;
 }
Пример #7
0
		private function CreateAccountStep2()
		{
			$savedataDetails = array(

				/**
				 * Customer Details
				 */
				FORMFIELDS_FORM_ACCOUNT => array(
					'EmailAddress' => 'custconemail',
					'Password' => 'custpassword',
					'ConfirmPassword' => 'custconfirmpassword',
					'FirstName' => 'custconfirstname',
					'LastName' => 'custconlastname',
					'CompanyName' => 'custconcompany',
					'Phone' => 'custconphone',
				),

				/**
				 * Shipping Details
				 */
				FORMFIELDS_FORM_ADDRESS => array(
					'FirstName' => 'shipfirstname',
					'LastName' => 'shiplastname',
					'CompanyName' => 'shipcompany',
					'AddressLine1' => 'shipaddress1',
					'AddressLine2' => 'shipaddress2',
					'City' => 'shipcity',
					'State' => 'shipstate',
					'Country' => 'shipcountry',
					'Zip' => 'shipzip',
					'Phone' => 'shipphone',
					'BuildingType' => 'shipdestination'
				)
			);

			/**
			 * Validate and map submitted field data in one loop
			 */
			$fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ACCOUNT, true);
			$fields += $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ADDRESS, true);
			$customerData = array();
			$shippingData = array();
			$password = '';
			$confirmPassword = '';

			foreach (array_keys($fields) as $fieldId) {

				/**
				 * Validate
				 */
				$errmsg = '';
				if (!$fields[$fieldId]->runValidation($errmsg)) {
					return $this->CreateAccountStep1($errmsg);
				}

				foreach ($savedataDetails as $type => $map) {

					/**
					 * Are we in the customer section or the shipping?
					 */
					if ($type == FORMFIELDS_FORM_ACCOUNT) {
						$referencedData =& $customerData;
					} else {
						$referencedData =& $shippingData;
					}

					/**
					 * We're only interested in the private custom fields here
					 */
					if (array_key_exists($fields[$fieldId]->record['formfieldprivateid'], $map)) {
						$label = $map[$fields[$fieldId]->record['formfieldprivateid']];
						$referencedData[$label] = $fields[$fieldId]->getValue();

						/**
						 * Store the values somewhere if this is a apssword/confirm-password field
						 */
						if ($fields[$fieldId]->record['formfieldprivateid'] == 'Password') {
							$password = $referencedData[$label];
						} else if ($fields[$fieldId]->record['formfieldprivateid'] == 'ConfirmPassword') {
							$confirmPassword = $referencedData[$label];
						}
					}
				}
			}

			/**
			 * Clean up some of the data
			 */
			if (isset($shippingData['shipstate'])) {
				$state = GetStateInfoByName($shippingData['shipstate']);
				if ($state) {
					$shippingData['shipstateid'] = $state['stateid'];
				} else {
					$shippingData['shipstateid'] = '';
				}
			}
			if (isset($shippingData['shipcountry'])) {
				$countryId = GetCountryByName($shippingData['shipcountry']);
				if (isId($countryId)) {
					$shippingData['shipcountryid'] = $countryId;
				} else {
					$shippingData['shipcountryid'] = '';
				}
			}
			if (isset($shippingData['shipdestination'])) {
				$data = $fields[$fieldId]->getValue();
				if (isc_strtolower($shippingData[$label]) == 'house') {
					$shippingData[$label] = 'residential';
				} else {
					$shippingData[$label] = 'commercial';
				}
			}

			// Does an account with this email address already exist?
			if ($this->AccountWithEmailAlreadyExists($customerData['custconemail'])) {
				$this->CreateAccountStep1("already_exists");
			}
			// Else is the provided phone number valid?
			else if (!$this->ValidatePhoneNumber($customerData['custconphone'])) {
				$this->CreateAccountStep1("invalid_number");
			}
			// Else the passwords don't match
			else if ($password !== $confirmPassword) {
				$this->CreateAccountStep1("invalid_passwords");
			}
			else {
				// Create the user account in the database
				$token = GenerateCustomerToken();
				$customerData['customertoken'] = $token;

				// Add in the form sessions here AFTER all the validation
				$accountFormSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ACCOUNT);

				if (isId($accountFormSessionId)) {
					$customerData['custformsessionid'] = $accountFormSessionId;
				}

				$shippingFormSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ADDRESS);

				if (isId($shippingFormSessionId)) {
					$shippingData['shipformsessionid'] = $shippingFormSessionId;
				}

				$customerData["addresses"] = array($shippingData);
				$_SESSION['FROM_REG'] = 0;
				$customerId = $this->CreateCustomerAccount($customerData);

				if (isId($customerId)) {

					// The account was created, let's log them in automatically
					$this->LoginCustomerById($customerId, true);

					// Show the "thank you for registering" page
					if (isset($_SESSION['LOGIN_REDIR']) && $_SESSION['LOGIN_REDIR'] != '') {
						$GLOBALS['Continue'] = GetLang('ClickHereToContinue');
						$GLOBALS['ContinueLink'] = urldecode($_SESSION['LOGIN_REDIR']);
						$_SESSION['FROM_REG'] = 1;
					}
					// User has just registered (not in the middle of an order - click here to visit your account)
					else {
						$GLOBALS['Continue'] = GetLang('ClickHereContinueShopping');
						$GLOBALS['ContinueLink'] = $GLOBALS['ShopPath'];
					}
					$GLOBALS['ISC_LANG']['CreateAccountThanksIntro'] = sprintf(GetLang('CreateAccountThanksIntro'), $GLOBALS['StoreName'], isc_html_escape($customerData['custconemail']));
					$GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(GetConfig('StoreName') . " - " . GetLang('CreateAccountThanks'));

					if (!isset($_SESSION['IsCheckingOut'])) {
						// Take them to the default thank you page if they aren't checking out
						$GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("createaccount_thanks");
						$GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate();
					}
					else {

						/**
						 * This is an order so take them straight to the shipping provider page. Also save the
						 * shipping address here as we will need the custom fields
						 */
						if (getCustomerQuote()->getIsSplitShipping()) {
							header("Location: " . $GLOBALS['ShopPath'] . "/checkout.php?action=multiple");
						}
						else {
							header("Location: " . $GLOBALS['ShopPath'] . "/checkout.php");
						}

					}

					die();
				}
				else {
					// Couldn't create the account
					$this->CreateAccountStep1("database_error");
				}
			}
		}