/** * Save the submitted shipping address form data * * Method will map and save all the shipping address data * * @access private * @param array $fields The form fields to save * @param int $customerId The customerId * @param int $shippingId The optional shipping ID. Default is 0 (new record) * @return mixed The new shipping ID on successful new record, TRUE if record successfully * updated, FALSE on error */ private function saveAddressFields($fields, $customerId, $shippingId=0) { if (!is_array($fields) || empty($fields) || !isId($customerId)) { return false; } $savedata = array( 'shipcustomerid' => $customerId ); if (isId($shippingId)) { $savedata['shipid'] = $shippingId; } /** * Map the private data */ $country = $state = ''; foreach (array_keys($fields) as $fieldId) { $privateId = $fields[$fieldId]->record['formfieldprivateid']; if ($privateId == '' || !array_key_exists($privateId, $this->shippingMap)) { continue; } $savedata[$this->shippingMap[$privateId]] = $fields[$fieldId]->getValue(); if (strtolower($privateId) == 'country') { $country = $fields[$fieldId]->getValue(); } else if (strtolower($privateId) == 'state') { $state = $fields[$fieldId]->getValue(); } } /** * Find the country and state ID if we can */ $countryId = $stateId = 0; if ($country !== '') { $countryId = GetCountryByName($country); } if ($state !== '' && isId($countryId)) { $stateId = GetStateByName($state, $countryId); } $savedata['shipcountryid'] = (int)$countryId; $savedata['shipstateid'] = (int)$stateId; /** * Save our custom (non private) fields if we are allowed */ if (gzte11(ISC_MEDIUMPRINT)) { /** * Do we already have a form session ID for this address? */ $formSessionId = 0; if (isId($shippingId)) { $address = $this->shippingEntity->get($shippingId); if (is_array($address) && isset($address['shipformsessionid']) && isId($address['shipformsessionid'])) { $formSessionId = $address['shipformsessionid']; } } if (isId($formSessionId)) { $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ADDRESS, true, $formSessionId); } else { $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ADDRESS); if (isId($formSessionId)) { $savedata['shipformsessionid'] = $formSessionId; } } } if (isId($shippingId)) { return $this->shippingEntity->edit($savedata); } else { return $this->shippingEntity->add($savedata); } }
/** * 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); } }
/** * Show the create account form. If $AlreadyExists is true then * they've tried to create an account with an existing email address */ private function CreateAccountStep1($Error = "") { $fillPostedValues = false; if ($Error != "") { $fillPostedValues = true; $GLOBALS['HideCreateAccountIntroMessage'] = "none"; } $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ACCOUNT, $fillPostedValues); $fields += $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ADDRESS, $fillPostedValues); /** * Get any selected country and state */ $countryName = GetConfig('CompanyCountry'); $stateFieldId = 0; foreach (array_keys($fields) as $fieldId) { if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'state') { $stateFieldId = $fieldId; } else { if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'country' && $fields[$fieldId]->getValue() !== '') { $countryName = $fields[$fieldId]->getValue(); } } } /** * Compile the fields. Also set the country and state dropdowns while we are here */ $GLOBALS['CreateAccountEmailPassword'] = ''; $GLOBALS['CreateAccountDetails'] = ''; $GLOBALS['CreateAccountAccountFormFieldID'] = FORMFIELDS_FORM_ACCOUNT; $GLOBALS['CreateAccountShippingFormFieldID'] = FORMFIELDS_FORM_ADDRESS; $compiledFields = null; $accountFields = array(); $shippingFields = array(); /** * These are used for error reporting */ $emailAddress = ''; $phoneNo = ''; foreach (array_keys($fields) as $fieldId) { if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'emailaddress') { $emailAddress = $fields[$fieldId]->getValue(); } if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'phone') { $phoneNo = $fields[$fieldId]->getValue(); } if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'country') { $fields[$fieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); if ($countryName !== '') { $fields[$fieldId]->setValue($countryName); } $fields[$fieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $fieldId, 'stateId' => $stateFieldId)); } else { if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'state' && $countryName !== '') { $countryId = GetCountryByName($countryName); $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $fields[$fieldId]->setOptions($stateOptions); } } } /** * We don't want this in the address (its only for single page checkout) */ if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'savethisaddress' || isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'shiptoaddress') { continue; } /** * If this is a password field then remove that 'leave blank' label */ if ($fields[$fieldId]->getFieldType() == 'password') { $fields[$fieldId]->setLeaveBlankLabel(false); } /** * Separate out the fields */ if ($fields[$fieldId]->record['formfieldformid'] == FORMFIELDS_FORM_ACCOUNT) { $GLOBALS['CreateAccountEmailPassword'] .= $fields[$fieldId]->loadForFrontend(); } else { $GLOBALS['CreateAccountDetails'] .= $fields[$fieldId]->loadForFrontend(); } } if ($Error == "already_exists") { // The email address is taken, they have to choose another one $GLOBALS['ErrorMessage'] = sprintf(GetLang('AccountEmailTaken'), isc_html_escape($emailAddress)); } else { if ($Error == "invalid_number") { // The phone number is invalid $GLOBALS['ErrorMessage'] = sprintf(GetLang('AccountEnterValidPhone'), isc_html_escape($phoneNo)); } else { if ($Error == "invalid_passwords") { // The passwords do not match $GLOBALS['ErrorMessage'] = GetLang('AccountPasswordsDontMatch'); } else { if ($Error == "database_error") { // A database error occured while creating the account $GLOBALS['ErrorMessage'] = GetLang('AccountInternalError'); } else { if ($Error !== '') { // Some other error while validating the field data. Should already be escaped $GLOBALS['ErrorMessage'] = $Error; } else { $GLOBALS['HideCreateAccountErrorMessage'] = "none"; } } } } } // Get the id of the customer $GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER'); $customer_id = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerId(); /** * Load up any form field JS event data and any validation lang variables */ $GLOBALS['FormFieldRequiredJS'] = $GLOBALS['ISC_CLASS_FORM']->buildRequiredJS(); // Is captcha enabled? if (GetConfig('CaptchaEnabled') == false) { $GLOBALS['HideReviewCaptcha'] = "none"; } else { // Generate the captcha image $GLOBALS['ISC_CLASS_CAPTCHA'] = GetClass('ISC_CAPTCHA'); $GLOBALS['ISC_CLASS_CAPTCHA']->CreateSecret(); $GLOBALS['CaptchaImage'] = $GLOBALS['ISC_CLASS_CAPTCHA']->ShowCaptcha(); } $GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(GetConfig('StoreName') . " - " . GetLang('CreateAccount')); $GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("createaccount"); $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(); }
/** * 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']; }
/** * 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']; }
public function SetPanelSettings() { // this panel should only be shown for guests entering an address if(CustomerIsSignedIn()) { $this->DontDisplay = true; return; } $formHtml = ''; // Enter a billing address if($GLOBALS['ShippingFormAction'] == 'save_biller') { $formFieldType = FORMFIELDS_FORM_BILLING; $quoteAddress = getCustomerQuote()->getBillingAddress(); // load the email address field $GLOBALS['ISC_CLASS_FORM']->addFormFieldUsed($GLOBALS['ISC_CLASS_FORM']->getFormField(FORMFIELDS_FORM_ACCOUNT, '1', '', true)); // load html for email field $formHtml .= $GLOBALS['ISC_CLASS_FORM']->loadFormField(FORMFIELDS_FORM_ACCOUNT, '1'); $GLOBALS['CheckEmail'] = 'true'; } else { $formFieldType = FORMFIELDS_FORM_SHIPPING; $quoteAddress = getCustomerQuote()->setIsSplitShipping(false) ->getShippingAddress(); } $addressFormFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields($formFieldType, false); // Coming back here from an error, so use the $_POST values $savedFormFieldValues = array(); if(!empty($GLOBALS['ErrorMessage']) && !empty($_POST['FormField'][$formFieldType])) { $savedFormFieldValues = $_POST['FormField'][$formFieldType]; } // Use the address already saved in the quote if there is one else { // An array containing the methods available in $quoteAddress and the form field "private ID" $quoteAddressFields = array( 'EmailAddress' => 'getEmail', 'FirstName' => 'getFirstName', 'LastName' => 'getLastName', 'CompanyName' => 'getCompany', 'AddressLine1' => 'getAddress1', 'AddressLine2' => 'getAddress2', 'City' => 'getCity', 'Zip' => 'getZip', 'State' => 'getStateName', 'Country' => 'getCountryName', 'Phone' => 'getPhone', ); foreach($addressFormFields as $formFieldId => $formField) { $formFieldPrivateId = $formField->record['formfieldprivateid']; if(isset($quoteAddressFields[$formFieldPrivateId])) { $method = $quoteAddressFields[$formFieldPrivateId]; $savedFormFieldValues[$formFieldId] = $quoteAddress->$method(); } else { $customField = $quoteAddress->getCustomField($formFieldId); if($customField !== false) { $savedFormFieldValues[$formFieldId] = $customField; } } } } $countryFieldId = 0; $stateFieldId = 0; foreach($addressFormFields as $formFieldId => $formField) { $formFieldPrivateId = $formField->record['formfieldprivateid']; if(isset($savedFormFieldValues[$formFieldId])) { $formField->setValue($savedFormFieldValues[$formFieldId]); } if($formFieldPrivateId == 'Country') { $countryFieldId = $formFieldId; } else if($formFieldPrivateId == 'State') { $stateFieldId = $formFieldId; } } if($countryFieldId) { $addressFormFields[$countryFieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); if ($addressFormFields[$countryFieldId]->getValue() == '') { $addressFormFields[$countryFieldId]->setValue(GetConfig('CompanyCountry')); } if ($stateFieldId) { $addressFormFields[$countryFieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryFieldId, 'stateId' => $stateFieldId)); $countryId = GetCountryByName($addressFormFields[$countryFieldId]->getValue()); $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $addressFormFields[$stateFieldId]->setOptions($stateOptions); } else { // no states for our country, we need to mark this as not required $addressFormFields[$stateFieldId]->setRequired(false); } } } foreach($addressFormFields as $formField) { if (isc_strtolower($formField->record['formfieldprivateid']) == 'savethisaddress' || isc_strtolower($formField->record['formfieldprivateid']) == 'shiptoaddress') { continue; } $formHtml .= $formField->loadForFrontend(); $GLOBALS['ISC_CLASS_FORM']->addFormFieldUsed($formField); } $GLOBALS['ShipCustomFields'] = $formHtml; $GLOBALS['AddressFormFieldID'] = $formFieldType; $GLOBALS['FormFieldRequiredJS'] = $GLOBALS['ISC_CLASS_FORM']->buildRequiredJS(); }
/** * This was inside addOrder, moved out for use by editing and for split-shipping allocation * * @param int $formId one of FORMFIELD_ form-type constants * @param ISC_QUOTE_ADDRESS $quoteAddress * @return array of field=>value variables suitable for setting as template data */ public function populateQuoteAddressFormFields($formId, ISC_QUOTE_ADDRESS $quoteAddress = null) { require_once ISC_BASE_PATH . '/lib/addressvalidation.php'; if ($quoteAddress) { $quoteAddressFields = convertAddressArrayToFieldArray($quoteAddress->getAsArray()); } $countryFieldId = 0; $stateFieldId = 0; $zipFieldId = 0; $formFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields($formId); foreach($formFields as $fieldId => /** @var ISC_FORMFIELD_BASE */$field) { $field->setRequired(false); $formFieldPrivateId = $field->record['formfieldprivateid']; if($formFieldPrivateId && !gzte11(ISC_MEDIUMPRINT)) { unset($fieldId); } // for display purposes, pre-populate the form field with existing quote address info if ($quoteAddress && $quoteAddressFields) { if (!$formFieldPrivateId) { $customField = $quoteAddress->getCustomField($field->record['formfieldid']); if ($customField) { $field->setValue($customField['value']); } } else if (isset($quoteAddressFields[$formFieldPrivateId])) { $field->setValue($quoteAddressFields[$formFieldPrivateId], true); } } if($formFieldPrivateId == 'Country') { $field->setRequired(true); $countryFieldId = $fieldId; } else if($formFieldPrivateId == 'State') { $stateFieldId = $fieldId; } else if ($formFieldPrivateId == 'Zip') { $zipFieldId = $fieldId; $field->setRequired(true); } $GLOBALS['ISC_CLASS_FORM']->addFormFieldUsed($field); } // This is a massive hack, and a poorly designed feature. Seriously. if($countryFieldId) { $formFields[$countryFieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); if ($formFields[$countryFieldId]->getValue() == '') { $formFields[$countryFieldId]->setValue(GetConfig('CompanyCountry')); } if ($stateFieldId) { $formFields[$countryFieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryFieldId, 'stateId' => $stateFieldId)); $countryId = GetCountryByName($formFields[$countryFieldId]->getValue()); $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $formFields[$stateFieldId]->setOptions($stateOptions); } else { // no states for our country, we need to mark this as not required $formFields[$stateFieldId]->setRequired(false); } if ($formFields[$stateFieldId]->getValue() == '') { $formFields[$stateFieldId]->setValue(getConfig('CompanyState')); } } } if ($zipFieldId && getConfig('CompanyZip') && $formFields[$zipFieldId]->getValue() == '') { $formFields[$zipFieldId]->setValue(getConfig('CompanyZip')); } return $formFields; }
/** * 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; }
/** * Return the name of a country from its ID */ function GetCountryIdByName($country) { return GetCountryByName($country); }
/** * 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) { $address = array(); $errors = array(); // for the billing address we need to validate the email address $email = ''; if($type == 'billing' && !customerIsSignedIn()) { $emailField = $GLOBALS['ISC_CLASS_FORM']->getFormField(FORMFIELDS_FORM_ACCOUNT, '1', '', true); $email = $emailField->getValue(); if($email == '' || !is_email_address($email)) { $errors[] = GetLang('AccountEnterValidEmail'); return false; } // if guess checkout enabled and guess account creation on checkout is enabled and the entered email is already exist in the system // then we do email existance checking $customer = GetClass('ISC_CUSTOMER'); if(getConfig('GuestCheckoutEnabled') && getConfig('GuestCheckoutCreateAccounts') && $customer->AccountWithEmailAlreadyExists($email)) { $errors[] = sprintf(GetLang('AccountEmailTaken'), isc_html_escape($email)); return false; } $address['shipemail'] = $email; } require_once(ISC_BASE_PATH . '/lib/addressvalidation.php'); // parse the form fields and validate them $errmsg = ''; if($type == 'billing') { $formFieldType = FORMFIELDS_FORM_BILLING; } else { $formFieldType = FORMFIELDS_FORM_SHIPPING; } $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields($formFieldType, true); $countryFieldId = 0; $stateFieldId = 0; foreach($fields as $fieldId => $formField) { if($formField->record['formfieldprivateid'] == 'Country') { $countryFieldId = $fieldId; } else if($formField->record['formfieldprivateid'] == 'State') { $stateFieldId = $fieldId; } } // Mark the state field as being optional if there are no states in the // selected country. if ($countryFieldId && $stateFieldId) { $countryId = GetCountryByName($fields[$countryFieldId]->getValue()); $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $fields[$stateFieldId]->setOptions($stateOptions); } else { $fields[$stateFieldId]->setRequired(false); } } if (!validateFieldData($fields, $errmsg)) { $errors[] = $errmsg; return false; } $fieldMap = array( 'FirstName' => 'firstname', 'LastName' => 'lastname', 'CompanyName' => 'company', 'AddressLine1' => 'address1', 'AddressLine2' => 'address2', 'City' => 'city', 'State' => 'state', 'Country' => 'country', 'Zip' => 'zip', 'Phone' => 'phone', 'Email' => 'email', ); foreach($fields as $fieldId => $formField) { // This isn't a built in field, so save the value for later handling if(!$formField->record['formfieldprivateid']) { $address['customFormFields'][$fieldId] = $formField->getValue(); continue; } // Disregard any fields we don't know about else if(!isset($fieldMap[$formField->record['formfieldprivateid']])) { continue; } $key = 'ship' . $fieldMap[$formField->record['formfieldprivateid']]; $address[$key] = $formField->getValue(); } return $address; }
private function ParseAddress($record, $customerId, $index = '') { $shippingData = array(); $fillin = array('shipaddress1', 'shipaddress2', 'shipcity', 'shipstate', 'shipzip', 'shipcountry'); foreach ($fillin as $fillkey) { if (!isset($record[$fillkey . $index])) { $record[$fillkey . $index] = ''; } } if (isId($customerId)) { $shippingData["shipcustomerid"] = $customerId; } $shippingData['shipid'] = 0; if (!empty($record['shipid' . $index])) { $shippingData['shipid'] = $record['shipid' . $index]; } $shippingData['shipfirstname'] = $record['shipfirstname' . $index]; $shippingData['shiplastname'] = $record['shiplastname' . $index]; $shippingData['shipaddress1'] = $record['shipaddress1' . $index]; $shippingData['shipaddress2'] = $record['shipaddress2' . $index]; $shippingData['shipcity'] = $record['shipcity' . $index]; $shippingData['shipstate'] = $record['shipstate' . $index]; $shippingData['shipzip'] = $record['shipzip' . $index]; $shippingData['shipcountry'] = $record['shipcountry' . $index]; $shippingData['shipstateid'] = 0; $shippingData['shipcountryid'] = 0; $shippingData['shipdestination'] = ''; // Find the country and state $shippingData['shipcountryid'] = (int)GetCountryByName($record['shipcountry' . $index]); if(!$shippingData['shipcountryid']) { $shippingData['shipcountryid'] = (int)GetCountryIdByISO2($record['shipcountry' . $index]); } // Still nothing? 0 for the shipping country ID if(!$shippingData['shipcountryid']) { $shippingData['shipcountryid'] = 0; } if(isset($record['shipstate' . $index])) { $shippingData['shipstateid'] = GetStateByName($record['shipstate' . $index], $shippingData['shipcountryid']); } // Still nothing? 0 for the shipping state ID if(!$shippingData['shipstateid']) { $shippingData['shipstateid'] = 0; } if(!isset($record['shipphone' . $index]) && isset($record['custconphone' . $index])) { $shippingData['shipphone'] = $record['custconphone' . $index]; } else { $shippingData['shipphone'] = $record['shipphone' . $index]; } /** * 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' . $index]); if (!isId($shippingData['shipformsessionid'])) { unset($shippingData['shipformsessionid']); } } return $shippingData; }
/** * 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; }
/** * Parse the submitted field data into an associative array * * Method will parse the submitted field data and convert it into an associative array * that resembles the shipping_addresses table structure * * @access private * @param array $fields The field list to parse from * @param int $formSessionId The optional form session ID * @return array The parsed array on success, FALSE on failure */ private function parseFieldData($fields, $formSessionId = '') { if (!is_array($fields)) { return false; } $fieldMap = array('FirstName' => 'firstname', 'LastName' => 'lastname', 'CompanyName' => 'company', 'AddressLine1' => 'address1', 'AddressLine2' => 'address2', 'City' => 'city', 'State' => 'state', 'Country' => 'country', 'Zip' => 'zip', 'Phone' => 'phone'); $savedata = array(); $countryFieldId = ''; $stateFieldId = ''; foreach (array_keys($fields) as $fieldId) { if (!array_key_exists($fields[$fieldId]->record['formfieldprivateid'], $fieldMap)) { continue; } $key = 'ship' . $fieldMap[$fields[$fieldId]->record['formfieldprivateid']]; $savedata[$key] = isc_html_escape($fields[$fieldId]->getValue()); if ($key == 'shipcountry') { $countryFieldId = $fieldId; } else { if ($key == 'shipstate') { $stateFieldId = $fieldId; } } } $savedata['shipcustomerid'] = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerId(); /** * Fill in the country and state IDs */ $savedata['shipcountryid'] = GetCountryByName($fields[$countryFieldId]->getValue()); if (isId($savedata['shipcountryid'])) { $savedata['shipstateid'] = GetStateByName($fields[$stateFieldId]->getValue(), $savedata['shipcountryid']); } else { $savedata['shipstateid'] = 0; } /** * Now save the form session record */ $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ADDRESS, true, $formSessionId); if (isId($formSessionId)) { $savedata['shipformsessionid'] = $formSessionId; } return $savedata; }
/** * Parse the submitted field data into an associative array * * Method will parse the submitted field data and convert it into an associative array * that resembles the shipping_addresses table structure * * @access private * @param array $fields The field list to parse from * @param int $formSessionId The optional form session ID * @return array The parsed array on success, FALSE on failure */ function parseFieldData($fields, $formSessionId='') { if (!is_array($fields)) { return false; } $fieldMap = getAddressFormMapping(); $savedata = array(); $countryFieldId = ''; $stateFieldId = ''; foreach (array_keys($fields) as $fieldId) { if (!array_key_exists($fields[$fieldId]->record['formfieldprivateid'], $fieldMap)) { continue; } $key = 'ship' . $fieldMap[$fields[$fieldId]->record['formfieldprivateid']]; $savedata[$key] = $fields[$fieldId]->getValue(); if ($key == 'shipcountry') { $countryFieldId = $fieldId; } else if ($key == 'shipstate') { $stateFieldId = $fieldId; } } $savedata['shipcustomerid'] = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerId(); /** * Fill in the country and state IDs */ $savedata['shipcountryid'] = GetCountryByName($fields[$countryFieldId]->getValue()); if (isId($savedata['shipcountryid'])) { $savedata['shipstateid'] = GetStateByName($fields[$stateFieldId]->getValue(), $savedata['shipcountryid']); } else { $savedata['shipstateid'] = 0; } /** * Now save the form session record */ $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ADDRESS, true, $formSessionId); if (isId($formSessionId)) { $savedata['shipformsessionid'] = $formSessionId; } return $savedata; }