/** * Imports an actual product record in to the database. * * @param array Array of record data */ protected function _ImportRecord($record) { if (!$record['custconemail']) { $this->ImportSession['Results']['Failures'][] = implode(",", $record['original_record']) . " " . GetLang('ImportCustomersMissingEmail'); return; } if (!is_email_address($record['custconemail'])) { $this->ImportSession['Results']['Failures'][] = implode(",", $record['original_record']) . " " . GetLang('ImportCustomersInvalidEmail'); return; } $fillin = array('custconcompany', 'custconfirstname', 'custconlastname', 'custconphone'); foreach ($fillin as $fillkey) { if (!isset($record[$fillkey])) { $record[$fillkey] = ''; } } // Is there an existing customer with the same email? $customerId = 0; $existingFormSessionId = 0; $query = sprintf("select customerid from [|PREFIX|]customers where lower(custconemail)='%s'", $GLOBALS['ISC_CLASS_DB']->Quote(isc_strtolower($record['custconemail']))); $result = $GLOBALS["ISC_CLASS_DB"]->Query($query); if ($row = $GLOBALS["ISC_CLASS_DB"]->Fetch($result)) { // Overriding existing products, set the product id if (isset($this->ImportSession['OverrideDuplicates']) && $this->ImportSession['OverrideDuplicates'] == 1) { $customerId = $row['customerid']; $this->ImportSession['Results']['Updates'][] = $record['custconfirstname'] . " " . $record['custconlastname'] . " (" . $record['custconemail'] . ")"; } else { $this->ImportSession['Results']['Duplicates'][] = $record['custconfirstname'] . " " . $record['custconlastname'] . " (" . $record['custconemail'] . ")"; return; } if (isId($row['custformsessionid'])) { $existingFormSessionId = $row['custformsessionid']; } } $customerData = array('company' => $record['custconcompany'], 'firstname' => $record['custconfirstname'], 'lastname' => $record['custconlastname'], 'email' => $record['custconemail'], 'phone' => $record['custconphone']); if (isset($record['custpassword']) && $record['custpassword'] !== '') { $customerData['password'] = $record['custpassword']; } if (isset($record['custstorecredit'])) { $customerData['storecredit'] = DefaultPriceFormat($record['custstorecredit']); } if (isId($customerId)) { $customerData['customerid'] = $customerId; } // Are we placing the customer in a customer group? $groupId = 0; if (!empty($record['custgroup'])) { static $customerGroups; $groupName = strtolower($record['custgroup']); if (isset($customerGroups[$groupName])) { $groupId = $customerGroups[$groupName]; } else { $query = "\n\t\t\t\t\tSELECT customergroupid\n\t\t\t\t\tFROM [|PREFIX|]customer_groups\n\t\t\t\t\tWHERE LOWER(groupname)='" . $GLOBALS['ISC_CLASS_DB']->Quote($groupName) . "'\n\t\t\t\t"; $groupId = $GLOBALS['ISC_CLASS_DB']->FetchOne($query, 'customergroupid'); // Customer group doesn't exist, create it if (!$groupId) { $newGroup = array('name' => $record['custgroup'], 'discount' => 0, 'isdefault' => 0, 'categoryaccesstype' => 'all'); $entity = new ISC_ENTITY_CUSTOMERGROUP(); $groupId = $entity->add($newGroup); } if ($groupId) { $customerGroups[$groupName] = $groupId; } } } $customerData['customergroupid'] = $groupId; // Do we have a shipping address? $shippingData = array(); if (isset($record['shipfullname']) || isset($record['shipfirstname']) || isset($record['shipaddress1']) || isset($record['shipaddress2']) || isset($record['shipcity']) || isset($record['shipstate']) || isset($record['shipzip']) || isset($record['shipcountry'])) { $fillin = array('shipaddress1', 'shipaddress2', 'shipcity', 'shipstate', 'shipzip', 'shipcountry'); foreach ($fillin as $fillkey) { if (!isset($record[$fillkey])) { $record[$fillkey] = ''; } } $shippingData['shipfirstname'] = ''; $shippingData['shiplastname'] = ''; $shippingData['shipaddress1'] = $record['shipaddress1']; $shippingData['shipaddress2'] = $record['shipaddress2']; $shippingData['shipcity'] = $record['shipcity']; $shippingData['shipstate'] = $record['shipstate']; $shippingData['shipzip'] = $record['shipzip']; $shippingData['shipcountry'] = $record['shipcountry']; $shippingData['shipstateid'] = 0; $shippingData['shipcountryid'] = 0; $shippingData['shipdestination'] = ''; // Find the country and state $shippingData['shipcountryid'] = (int) GetCountryByName($record['shipcountry']); if (!$shippingData['shipcountryid']) { $shippingData['shipcountryid'] = (int) GetCountryIdByISO2($record['shipcountry']); } // Still nothing? 0 for the shipping country ID if (!$shippingData['shipcountryid']) { $shippingData['shipcountryid'] = 0; } if (isset($record['shipstate'])) { $shippingData['shipstateid'] = GetStateByName($record['shipstate'], $shippingData['shipcountryid']); } // Still nothing? 0 for the shipping state ID if (!$shippingData['shipstateid']) { $shippingData['shipstateid'] = 0; } if (!isset($record['shipfullname']) || $record['shipfullname'] == "") { if (isset($record['shipfirstname']) && $record['shipfirstname'] != '') { $shippingData['shipfirstname'] = $record['shipfirstname']; } else { $shippingData['shipfirstname'] = $customerData['firstname']; } if (isset($record['shiplastname']) && $record['shiplastname'] != '') { $shippingData['shiplastname'] = $record['shiplastname']; } else { $shippingData['shiplastname'] = $customerData['lastname']; } } if (!isset($record['shipphone']) && isset($record['custconphone'])) { $shippingData['shipphone'] = $record['custconphone']; } else { $shippingData['shipphone'] = $record['shipphone']; } /** * Handle any of the address custom fields that we might have */ if (!empty($this->customFields) && array_key_exists('custom', $record)) { $shippingData['shipformsessionid'] = $this->_importCustomFormfields(FORMFIELDS_FORM_ADDRESS, $record['custom']); if (!isId($shippingData['shipformsessionid'])) { unset($shippingData['shipformsessionid']); } } } /** * Handle any of the customer custom fields that we might have */ if (!empty($this->customFields) && array_key_exists('custom', $record)) { $formSessionId = $this->_importCustomFormfields(FORMFIELDS_FORM_ACCOUNT, $record['custom'], $existingFormSessionId); if (isId($formSessionId)) { $customerData['custformsessionid'] = $formSessionId; } } $customerData['is_import'] = true; $customerEntity = new ISC_ENTITY_CUSTOMER(); // New customer, insert in to DB if ($customerId == 0) { // Set a temporary password, retrievable later via lost password function if (!isset($customerData['password']) || $customerData['password'] == '') { $customerData['password'] = isc_substr(uniqid(rand(), true), 0, 10); } $customerData['token'] = GenerateCustomerToken(); $customerData['shipping_address'] = $shippingData; $rtn = $customerEntity->add($customerData); ++$this->ImportSession['Results']['SuccessCount']; } else { if (count($shippingData) > 0) { $query = sprintf("select shipid from [|PREFIX|]shipping_addresses where shipcustomerid='%d' and lower(shipaddress1)='%s' and lower(shipaddress2)='%s' and lower(shipcity)='%s' and lower(shipstate)='%s' and lower(shipcountry)='%s'", $GLOBALS['ISC_CLASS_DB']->Quote($customerId), $GLOBALS['ISC_CLASS_DB']->Quote($shippingData['shipaddress1']), $GLOBALS['ISC_CLASS_DB']->Quote($shippingData['shipaddress2']), $GLOBALS['ISC_CLASS_DB']->Quote($shippingData['shipcity']), $GLOBALS['ISC_CLASS_DB']->Quote($shippingData['shipstate']), $GLOBALS['ISC_CLASS_DB']->Quote($shippingData['shipcountry'])); $Result = $GLOBALS['ISC_CLASS_DB']->Query($query); $row = $GLOBALS['ISC_CLASS_DB']->Fetch($Result); // Address doesn't exist, we insert it if (!$row['shipid']) { $customerData['shipping_address'] = $shippingData; } } $rtn = $customerEntity->edit($customerData); } }
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"); } } } } }
/** * 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']; }
/** * 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']; }
/** * Imports an actual product record in to the database. * * @param array Array of record data */ protected function _ImportRecord($record) { static $customerGroups=array(); if(!$record['custconemail']) { $this->ImportSession['Results']['Failures'][] = implode(",", $record['original_record'])." ".GetLang('ImportCustomersMissingEmail'); return; } if(!is_email_address($record['custconemail'])) { $this->ImportSession['Results']['Failures'][] = implode(",", $record['original_record'])." ".GetLang('ImportCustomersInvalidEmail'); return; } // Is there an existing customer with the same email? $existingCustomer = null; $existingFormSessionId = 0; $searchFields = array( "custconemail" => array( "value" => isc_strtolower($record["custconemail"]), "func" => "LOWER" ) ); $customerId = $this->customerEntity->search($searchFields); if (isId($customerId)) { $existingCustomer = $this->customerEntity->get($customerId); } else { $customerId = 0; } if(is_array($existingCustomer)) { // Overriding existing customer, set the customer id if(isset($this->ImportSession['OverrideDuplicates']) && $this->ImportSession['OverrideDuplicates'] == 1) { $this->ImportSession['Results']['Updates'][] = $record['custconfirstname']." ".$record['custconlastname']." (".$record['custconemail'].")"; } else { $this->ImportSession['Results']['Duplicates'][] = $record['custconfirstname']." ".$record['custconlastname']." (".$record['custconemail'].")"; return; } if (isId($existingCustomer['custformsessionid'])) { $existingFormSessionId = $existingCustomer['custformsessionid']; } } else { /** * Fill in the blanks only if we are adding in a customer */ $fillin = array('custconcompany', 'custconfirstname', 'custconlastname', 'custconphone'); foreach ($fillin as $fillkey) { if (!isset($record[$fillkey])) { $record[$fillkey] = ''; } } } $customerData = array(); foreach (array_keys($this->_ImportFields) as $field) { if (substr($field, 0, 4) == "cust" && array_key_exists($field, $record)) { $customerData[$field] = $record[$field]; } } if(isset($customerData["custstorecredit"])) { $customerData["custstorecredit"] = DefaultPriceFormat($customerData["custstorecredit"]); } if (array_key_exists("custgroup", $customerData)) { $customerData["custgroupid"] = $customerData["custgroup"]; } if (isId($customerId)) { $customerData["customerid"] = $customerId; } // Are we placing the customer in a customer group? $groupId = 0; if (array_key_exists("custgroup", $record) && trim($record["custgroup"]) !== "") { $groupName = strtolower($record['custgroup']); if(isset($customerGroups[$groupName])) { $groupId = $customerGroups[$groupName]; } else { $searchFields = array( "groupname" => array( "value" => isc_strtolower($groupName), "func" => "LOWER" ) ); $groupId = $this->groupEntity->search($searchFields); // Customer group doesn't exist, create it if(!isId($groupId)) { $newGroup = array( 'groupname' => $record['custgroup'], 'discount' => 0, 'isdefault' => 0, 'categoryaccesstype' => 'all' ); $groupId = $this->groupEntity->add($newGroup); } if($groupId) { $customerGroups[$groupName] = $groupId; } } } $customerData['custgroupid'] = $groupId; // Do we have a shipping address? $shippingData = array(); if (!$this->ImportSession['IsBulkEdit']) { // Don't import the address if we are missing the street address if(isset($record['shipaddress1']) && trim($record['shipaddress1']) !== "" && (isset($record['shipfirstname']) || isset($record['shipaddress2']) || isset($record['shipcity']) || isset($record['shipstate']) || isset($record['shipzip']) || isset($record['shipcountry']))) { $shippingData[] = $this->ParseAddress($record, $customerId); } } else { // bulk edit import // search for addresses for ($x = 1; $x <= $this->ImportSession['AddressCount']; $x++) { if(isset($record['shipaddress1' . $x]) && trim($record['shipaddress1' . $x]) !== "" && (isset($record['shipfirstname' . $x]) || isset($record['shipaddress2' . $x]) || isset($record['shipcity' . $x]) || isset($record['shipstate' . $x]) || isset($record['shipzip' . $x]) || isset($record['shipcountry' . $x]))) { $shippingData[] = $this->ParseAddress($record, $customerId, $x); } } } if (!empty($shippingData)) { $customerData['addresses'] = $shippingData; } /** * Handle any of the customer custom fields that we might have */ if (!empty($this->customFields) && array_key_exists('custom', $record)) { $formSessionId = $this->_importCustomFormfields(FORMFIELDS_FORM_ACCOUNT, $record['custom'], $existingFormSessionId); if (isId($formSessionId)) { $customerData['custformsessionid'] = $formSessionId; } } $customerData['is_import'] = true; // New customer, insert in to DB if($customerId == 0) { // Set a temporary password, retrievable later via lost password function if(!isset($customerData['custpassword']) || $customerData['custpassword'] == '') { $customerData['custpassword'] = isc_substr(uniqid(rand(), true), 0, 10); } $customerData['customertoken'] = GenerateCustomerToken(); $rtn = $this->customerEntity->add($customerData); ++$this->ImportSession['Results']['SuccessCount']; } // Updating an existing customer else { $rtn = $this->customerEntity->edit($customerData); } }
/** * Create the pending order in the database with the customers selected payment details, etc. * * @return array An array containing information about what needs to be done next. */ public function SavePendingOrder() { $provider = null; $verifyPaymentProvider = true; $redirectToFinishOrder = false; $providerId = ''; $pendingOrderResult = array(); if (!isset($_SESSION['CHECKOUT']['PENDING_DATA'])) { return false; } // Did they agree to signup to any mailing lists? if (isset($_POST['join_mailing_list'])) { ISC_SetCookie("JOIN_MAILING_LIST", 1, time() + 3600 * 24 * 7); } if (isset($_POST['join_order_list'])) { ISC_SetCookie("JOIN_ORDER_LIST", 1, time() + 3600 * 24 * 7); } $orderTotal = $_SESSION['CHECKOUT']['PENDING_DATA']['ORDER_TOTAL']; $giftCertificateAmount = $_SESSION['CHECKOUT']['PENDING_DATA']['GIFTCERTIFICATE_AMOUNT']; $gatewayAmount = $_SESSION['CHECKOUT']['PENDING_DATA']['GATEWAY_AMOUNT']; $creditUsed = 0; $giftCertificates = array(); // Find out what currency we are using. We'll need this later to display their previous orders in the currency that they have selected $selectedCurrency = GetCurrencyById($GLOBALS['CurrentCurrency']); if (isset($_SESSION['OFFERCART']['GIFTCERTIFICATES']) && is_array($_SESSION['OFFERCART']['GIFTCERTIFICATES'])) { $giftCertificates = $_SESSION['OFFERCART']['GIFTCERTIFICATES']; // Now we check that the gift certificates can actually be applied to the order $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES'] = GetClass('ISC_GIFTCERTIFICATES'); $badCertificates = array(); $remainingBalance = 0; $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES']->GiftCertificatesApplicableToOrder($orderTotal, $giftCertificates, $remainingBalance, $badCertificates); // One or more gift certificates were invalid so this order is now invalid if (count($badCertificates) > 0) { $badCertificatesList = '<strong>' . GetLang('BadGiftCertificates') . '</strong><ul>'; foreach ($badCertificates as $code => $reason) { if (is_array($reason) && $reason[0] == "expired") { $reason = sprintf(GetLang('BadGiftCertificateExpired'), CDate($reason[1])); } else { $reason = GetLang('BadGiftCertificate' . ucfirst($reason)); } $badCertificatesList .= sprintf("<li>%s - %s", isc_html_escape($code), $reason); } $badCertificatesList .= "</ul>"; $pendingOrderResult = array('error' => GetLang('OrderContainedInvalidGiftCertificates'), 'errorDetails' => $badCertificatesList); return $pendingOrderResult; } else { if ($orderTotal == $giftCertificateAmount && $remainingBalance > 0) { $pendingOrderResult = array('error' => GetLang('OrderTotalStillRemainingCertificates')); return $pendingOrderResult; } else { if ($orderTotal == $giftCertificateAmount) { $providerId = 'giftcertificate'; $verifyPaymentProvider = false; $redirectToFinishOrder = true; } } } } // If the order total is 0, then we just forward the user on to the "Thank You" page and set the payment provider to '' if ($orderTotal == 0) { $providerId = ''; $verifyPaymentProvider = false; $redirectToFinishOrder = true; } if ($verifyPaymentProvider) { if (isset($_POST['credit_checkout_provider']) && $_POST['credit_checkout_provider'] != "") { $_POST['checkout_provider'] = $_POST['credit_checkout_provider']; } $selected_provider = ""; $providers = GetCheckoutModulesThatCustomerHasAccessTo(true); // If there's more than one, use the value they've chosen if (count($providers) > 1 && isset($_POST['checkout_provider']) || isset($_SESSION['CHECKOUT']['ProviderListHTML'])) { $selected_provider = $_POST['checkout_provider']; } else { if (count($providers) == 1) { $selected_provider = $providers[0]['object']->GetId(); $_POST['checkout_provider'] = $selected_provider; } else { $selected_provider = ''; } } if (!isset($_POST['checkout_provider'])) { $_POST['checkout_provider'] = ''; } // Are we using our store credit? $GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER'); $customer = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerDataByToken(); if (isset($_POST['store_credit']) && $_POST['store_credit'] == 1 && $customer['custstorecredit'] > 0) { // User has not chosen a payment provider and can't afford this order using only store credit, throw back as error if (!$_POST['checkout_provider'] && $customer['custstorecredit'] < $orderTotal) { return false; } else { $onlyCredit = false; $updateExtra = ''; // If we're only using store credit $creditToUse = $orderTotal - $giftCertificateAmount; if ($customer['custstorecredit'] >= $creditToUse) { // Set the checkout provider $providerId = 'storecredit'; $verifyPaymentProvider = false; $redirectToFinishOrder = true; $creditUsed = $creditToUse; $onlyCredit = true; } else { // Using all of our store credit to pay for this order and we owe more. $creditUsed = $customer['custstorecredit']; $gatewayAmount -= $creditUsed; } } } } // Now with round 2, do we still need to verify the payment provider? if ($verifyPaymentProvider) { // If there's more than one provider and one wasn't selected on the order confirmation screen then there's a problem if ((count($providers) == 0 || count($providers) > 1 && !isset($_POST['checkout_provider'])) && !isset($_SESSION['CHECKOUT']['ProviderListHTML'])) { return false; } // Is the payment provider selected actually valid? if (!GetModuleById('checkout', $provider, $selected_provider)) { return false; } $providerId = $provider->GetId(); } // Load up all of the data for the items in the cart $GLOBALS['ISC_CLASS_MAKEAOFFER'] = GetClass('ISC_MAKEAOFFER'); $cartItems = $GLOBALS['ISC_CLASS_MAKEAOFFER']->api->GetProductsInCart(); // OK, we're successful down to here - do they want to create an account? if (isset($_SESSION['CHECKOUT']['CREATE_ACCOUNT'])) { $accountDetails = $_SESSION['CHECKOUT']['ACCOUNT_DETAILS']; $token = GenerateCustomerToken(); $customerData = array('email' => trim($accountDetails['email']), 'password' => $accountDetails['password'], 'firstname' => $accountDetails['firstname'], 'lastname' => $accountDetails['lastname'], 'company' => $accountDetails['company'], 'phone' => $accountDetails['phone'], 'token' => $token); //alandy modify.2011-5-20. /*$sql="select customerid from [|PREFIX|]customers where custconemail='".$accountDetails['email']."'"; $query=$GLOBALS['ISC_CLASS_DB']->Query($sql); while($rs=$GLOBALS['ISC_CLASS_DB']->Fetch($query)){ $GLOBALS['Hasemailflag']="yes"; return array( 'error' => GetLang('AccountInternalError') ); }*/ $cusquery = "SELECT customerid\n\t\t\t\tFROM [|PREFIX|]customers\n\t\t\t\tWHERE isguest = 1 AND LOWER(custconemail)='" . $GLOBALS['ISC_CLASS_DB']->Quote(isc_strtolower($customerData['email'])) . "'"; $cusresult = $GLOBALS['ISC_CLASS_DB']->Query($cusquery); $cusrow = $GLOBALS['ISC_CLASS_DB']->Fetch($cusresult); $custId = $cusrow['customerid']; if ($custId == '') { // 20110613 johnny add ---- add flag for guest user email don't exist if ($_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT']) { $customerData['isguest'] = 1; } $customerId = $GLOBALS['ISC_CLASS_CUSTOMER']->CreateCustomerAccount($customerData, false, $accountDetails['autoAccount']); } else { if (!$_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT']) { $customerId = $GLOBALS['ISC_CLASS_CUSTOMER']->CreateCustomerAccount($customerData, true, $accountDetails['autoAccount']); /* delet already exist guest account $entity = new ISC_ENTITY_CUSTOMER(); $entity->delete($custId); */ } else { $customerId = $custId; // update guest account in customer table for guest user email exist $GLOBALS['ISC_CLASS_DB']->Query("UPDATE [|PREFIX|]customers SET custconfirstname = '" . $customerData['firstname'] . "', custconlastname = '" . $customerData['lastname'] . "' WHERE customerid = {$customerId}"); } } if (!$customerId) { return array('error' => GetLang('AccountInternalError')); } if (!$_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT']) { $GLOBALS['ISC_CLASS_CUSTOMER']->LoginCustomerById($customerId, true); } unset($_SESSION['CHECKOUT']['CREATE_ACCOUNT']); unset($_SESSION['CHECKOUT']['ACCOUNT_DETAILS']); // Log the customer in @ob_end_clean(); } if (isset($_COOKIE['SHOP_TOKEN'])) { $customerToken = $_COOKIE['SHOP_TOKEN']; } else { $customerToken = ''; } $orderComments = ''; if (isset($_REQUEST['ordercomments'])) { $orderComments = $_REQUEST['ordercomments']; } $checkoutSession = $_SESSION['CHECKOUT']; $pendingData = $checkoutSession['PENDING_DATA']; // Get a list of the vendors for all of the items in the cart, and loop through them // to build all of the pending orders $cartContent = $this->BreakdownCartByAddressVendorforshipping(); //Changed to merging function by Simha $vendorOrderInfo = array(); foreach ($cartContent as $vendorId => $addresses) { foreach ($addresses as $addressId => $products) { $allDigital = 1; $productArray = array(); foreach ($products as $cartItemId => $product) { // A physical product, mark as so if ($product['data']['prodtype'] == PT_PHYSICAL) { $allDigital = 0; } // Mark the quantity of this item $productArray[$cartItemId] = $product['quantity']; } $vendorInfo = $pendingData['VENDORS'][$vendorId . '_' . $addressId]; $vendorData = array('itemtotal' => $vendorInfo['ITEM_TOTAL'], 'taxcost' => $vendorInfo['TAX_COST'], 'taxname' => $vendorInfo['TAX_NAME'], 'taxrate' => $vendorInfo['TAX_RATE'], 'totalcost' => $vendorInfo['ORDER_TOTAL'], 'shippingcost' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['COST'], 'handlingcost' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['HANDLING'], 'shippingprovider' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['PROVIDER'], 'shippingmodule' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['MODULE'], 'isdigitalorder' => $allDigital, 'products' => $productArray); if ($addressId == 0) { $addresses = $this->GetOrderShippingAddresses(); $vendorData['shippingaddress'] = $addresses[$addressId]; } else { $vendorData['shippingaddressid'] = $addressId; } // Shipping zones can be configured per vendor, so we need to be sure // to pass this along correctly too if (isset($vendorInfo['SHIPPING_ZONE'])) { $shippingZone = GetShippingZoneById($vendorInfo['SHIPPING_ZONE']); if (is_array($shippingZone)) { $vendorData['ordshippingzoneid'] = $shippingZone['zoneid']; $vendorData['ordshippingzone'] = $shippingZone['zonename']; } } $vendorOrderInfo[$vendorId . '_' . $addressId] = $vendorData; } } // Set some defaults about the rest of the order $pendingOrder = array("customertoken" => $customerToken, 'paymentmethod' => $providerId, "storecreditamount" => $creditUsed, "giftcertificateamount" => $giftCertificateAmount, "giftcertificates" => $giftCertificates, "gatewayamount" => $gatewayAmount, 'totalincludestax' => $pendingData['TAX_INCLUDED'], "currencyid" => $selectedCurrency['currencyid'], "currencyexchangerate" => $selectedCurrency['currencyexchangerate'], 'ordercomments' => $orderComments, 'ipaddress' => GetIP(), 'vendorinfo' => $vendorOrderInfo); if (isset($customerId)) { $pendingOrder['customerid'] = $customerId; } // Determine the address ID we're using for billing if (is_array($_SESSION['CHECKOUT']['BILLING_ADDRESS'])) { $pendingOrder['billingaddress'] = $_SESSION['CHECKOUT']['BILLING_ADDRESS']; } else { $pendingOrder['billingaddressid'] = (int) $_SESSION['CHECKOUT']['BILLING_ADDRESS']; } if (isset($_POST['ordermessage'])) { $pendingOrder['ordermessage'] = $_POST['ordermessage']; } else { $pendingOrder['ordermessage'] = ''; } /** * Save our custom fields. If we are creating a new account then split this up so the * account fields will go in the customers table and the rest will go in the orders table */ if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['customer']) && isset($customerId) && isId($customerId)) { $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['customer']); if (isId($formSessionId)) { $updateData = array('customerid' => $customerId, 'email' => $customerData['email'], 'firstname' => $customerData['firstname'], 'lastname' => $customerData['lastname'], 'company' => $customerData['company'], 'phone' => $customerData['phone'], 'custformsessionid' => $formSessionId); $entity = new ISC_ENTITY_CUSTOMER(); $entity->edit($updateData); } } /** * OK, now to store the custom address fields. Check here to see if we are not split * shipping (single order) */ if (!isset($_SESSION['CHECKOUT']['IS_SPLIT_SHIPPING']) || !$_SESSION['CHECKOUT']['IS_SPLIT_SHIPPING']) { $pendingOrder['ordformsessionid'] = ''; if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']) && is_array($_SESSION['CHECKOUT']['CUSTOM_FIELDS'])) { /** * Save the billing */ if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']) && isset($pendingOrder['billingaddress']['saveAddress']) && $pendingOrder['billingaddress']['saveAddress']) { $pendingOrder['billingaddress']['shipformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']); } /** * Now for the shipping. Only save this once for all the shipping addresses */ if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping'])) { $shippSessId = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping']); foreach ($pendingOrder['vendorinfo'] as $vendorId => $vendorData) { if (isset($vendorData['shippingaddress']['saveAddress']) && $vendorData['shippingaddress']['saveAddress']) { $pendingOrder['vendorinfo'][$vendorId]['shippingaddress']['shipformsessionid'] = $shippSessId; } } } /** * Now the orders. This part is tricky because the billing and shipping information * have the same keys (same fields used in the frontend). We need to split them up * into separate billing and shipping information and then save it */ if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']) && is_array($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing'])) { /** * We create a map first so we can map the shipping information to its proper field * ID */ $billingKeys = array_keys($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']); $fieldAddressMap = $GLOBALS['ISC_CLASS_FORM']->mapAddressFieldList(FORMFIELDS_FORM_BILLING, $billingKeys); /** * OK, we have the map, now to split up the custom fields */ $orderSessData = array(); foreach ($fieldAddressMap as $fieldId => $newShippingFieldId) { $orderSessData[$fieldId] = $_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing'][$fieldId]; if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping'][$fieldId])) { $orderSessData[$newShippingFieldId] = $_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping'][$fieldId]; } } $pendingOrder['ordformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($orderSessData); } } /** * This is for split shipping. Loop through each address to get their default custom * field data, combine it with the billing custom field data, create the form session * record and then save that ID for each address */ } else { $shippingAddresses = $this->GetOrderShippingAddresses(); $origFormSessionData = array(); if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']) && is_array($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing'])) { $origFormSessionData = $_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']; } foreach ($pendingOrder['vendorinfo'] as $vendorId => $vendorData) { $address = null; $orderSessData = array(); if (array_key_exists($vendorData['shippingaddressid'], $shippingAddresses)) { $address = $shippingAddresses[$vendorData['shippingaddressid']]; } if (isset($address['shipformsessionid']) && isId($address['shipformsessionid'])) { $shippingSessionData = $GLOBALS['ISC_CLASS_FORM']->getSavedSessionData($address['shipformsessionid']); if (is_array($shippingSessionData)) { /** * Same deal with this save session data because the billing and shipping data * use the same fields and therefore have the same keys */ $billingKeys = array_keys($origFormSessionData); $fieldAddressMap = $GLOBALS['ISC_CLASS_FORM']->mapAddressFieldList(FORMFIELDS_FORM_BILLING, $billingKeys); /** * OK, we have the map, now to split up the custom fields */ $orderSessData = array(); foreach ($fieldAddressMap as $fieldId => $newShippingFieldId) { $orderSessData[$fieldId] = $origFormSessionData[$fieldId]; $orderSessData[$newShippingFieldId] = $shippingSessionData[$fieldId]; } } } $newFormSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($orderSessData); if (isId($newFormSessionId)) { $pendingOrder['vendorinfo'][$vendorId]['ordformsessionid'] = $newFormSessionId; } } } $pendingToken = CreateOrder($pendingOrder, $cartItems); // Try to add the record and if we can't then take them back to the shopping cart if (!$pendingToken) { return false; } // Persist the pending order token as a cookie for 24 hours ISC_SetCookie("SHOP_ORDER_TOKEN", $pendingToken, time() + 3600 * 24, true); $_COOKIE['SHOP_ORDER_TOKEN'] = $pendingToken; // Redirecting to finish order page? if ($redirectToFinishOrder) { return array('redirectToFinishOrder' => true); } $orderData = LoadPendingOrdersByToken($pendingToken); // Otherwise, the gateway want's to do something $provider->SetOrderData($orderData); // Is this an online payment provider? It would like to do something if ($provider->GetPaymentType() == PAYMENT_PROVIDER_ONLINE || method_exists($provider, "ShowPaymentForm")) { // Call the checkout process for the selected provider if (method_exists($provider, "ShowPaymentForm")) { return array('provider' => $provider, 'showPaymentForm' => true); } else { return array('provider' => $provider); } } else { return array('provider' => $provider); } }
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"); } } }