/** * Generate the shipping address form * * Method will generate the shipping address form based upon the section $section * * @access private * @param string $section the different section to generate ('address' or 'custom') * @param bool $preservePost TRUE to alse preserver the post, FALSE not to. Default is FALSE * @param int $shippingId The optional shipping address ID. Default is 0 (no database record) */ private function generateAddressFields($section, $preservePost=false, $shippingId=0) { $section = strtolower($section); if ($section !== 'address' && $section !== 'custom') { return ''; } $formSessionId = 0; $address = false; if (isId($shippingId) && !$preservePost) { $address = $this->shippingEntity->get($shippingId); if (!$address) { return ''; } if ($section == 'custom' && isId($address['shipformsessionid'])) { $formSessionId = $address['shipformsessionid']; } } $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ADDRESS, $preservePost, $formSessionId); if ($section == 'address') { /** * Are we reading from the database? */ if (isId($shippingId) && !$preservePost) { foreach (array_keys($fields) as $fieldId) { $privateId = $fields[$fieldId]->record['formfieldprivateid']; if ($privateId == '' | !array_key_exists($privateId, $this->shippingMap) || !array_key_exists($this->shippingMap[$privateId], $address)) { continue; } $fields[$fieldId]->setValue($address[$this->shippingMap[$privateId]]); } } /** * We'll need to add in the country and state options plus the country event */ $countryId = $stateId = 0; $selectedCountry = ''; foreach (array_keys($fields) as $fieldId) { if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'country') { $fields[$fieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); $countryId = $fieldId; $selectedCountry = $fields[$fieldId]->getValue(); } else if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'state') { $stateId = $fieldId; } } /** * Do we have a selected country? */ if ($selectedCountry == '' && GetConfig('CompanyCountry') !== '') { $selectedCountry = GetConfig('CompanyCountry'); $fields[$countryId]->setValue($selectedCountry); } /** * Add the event */ $fields[$countryId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryId, 'stateId' => $stateId)); /** * Now add in the state options if we can */ if ($selectedCountry !== '') { $countryRecordId = GetCountryByName($selectedCountry); if (isId($countryRecordId)) { $stateOptions = GetStateListAsIdValuePairs($countryRecordId); if (is_array($stateOptions) && !empty($stateOptions)) { $fields[$stateId]->setOptions($stateOptions); } } } } /** * OK, now generate them all */ $html = ''; foreach (array_keys($fields) as $fieldId) { $privateId = $fields[$fieldId]->record['formfieldprivateid']; if ($section == 'address' && $privateId == '') { continue; } if ($section == 'custom' && $privateId !== '') { continue; } /** * We don't want these fields */ if ($section == 'address' && (strtolower($privateId) == 'savethisaddress' || strtolower($privateId) == 'shiptoaddress')) { continue; } $html .= $fields[$fieldId]->loadForFrontend() . "\n"; } return $html; }
/** * Set up all of the template variables and predefined values for showing the form to edit an * existing order or create a new order. Will also set up the post variables as values if this * is a post request. * * @param array Optionally, if editing an order, the existing order to use for the default values. */ private function SetupOrderManagementForm($order = array()) { $GLOBLS['CurrentTab'] = 0; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $postData = $_POST; } else { $postData = $order; } $orderFields = array('OrderBillFirstName' => 'ordbillfirstname', 'OrderBillLastName' => 'ordbilllastname', 'OrderBillCompany' => 'ordbillcompany', 'OrderBillPhone' => 'ordbillphone', 'OrderBillStreet1' => 'ordbillstreet1', 'OrderBillStreet2' => 'ordbillstreet2', 'OrderBillSuburb' => 'ordbillsuburb', 'OrderBillZip' => 'ordbillzip', 'OrderShipFirstName' => 'ordshipfirstname', 'OrderShipLastName' => 'ordshiplastname', 'OrderShipCompany' => 'ordshipcompany', 'OrderShipPhone' => 'ordshipphone', 'OrderShipStreet1' => 'ordshipstreet1', 'OrderShipStreet2' => 'ordshipstreet2', 'OrderShipSuburb' => 'ordshipsuburb', 'OrderShipZip' => 'ordshipzip', 'CustomerEmail' => 'custconemail', 'CustomerPassword' => 'custpassword', 'CustomerPassword2' => 'custpassword2', 'CustomerStoreCredit' => 'custstorecredit', 'CustomerGroup' => 'custgroupid', 'CustomerType' => 'customerType', 'OrderComments' => 'ordcustmessage', 'OrderNotes' => 'ordnotes', 'OrderId' => 'orderid', 'OrderTrackingNo' => 'ordtrackingno', 'AnonymousEmail' => 'anonymousemail', 'OrderBillEmail' => 'ordbillemail', 'OrderShipEmail' => 'ordshipemail'); /* Added below condition for applying store credit permission - vikas */ $loggeduser = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetUser(); if ($loggeduser['userstorecreditperm'] == 0) { $GLOBALS['StoreCreditDisable'] = " disabled=\"\" "; } $GLOBALS['HideSelectedCustomer'] = 'display: none'; $GLOBALS['HideCustomerSearch'] = ''; $GLOBALS['HideAddressSelects'] = 'display: none'; if (isset($postData['ordcustid']) && $postData['ordcustid'] > 0) { $GLOBALS['CurrentTab'] = 1; $GLOBALS['CustomerType'] = 'existing'; $query = "\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM [|PREFIX|]customers WHERE customerid='" . (int) $postData['ordcustid'] . "'\n\t\t\t\t"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); $existingCustomer = $GLOBALS['ISC_CLASS_DB']->Fetch($result); if ($existingCustomer['customerid']) { $GLOBALS['HideSelectedCustomer'] = ''; $GLOBALS['HideCustomerSearch'] = 'display: none'; $GLOBALS['HideHistoryLink'] = 'display: none'; $GLOBALS['CustomerId'] = $existingCustomer['customerid']; $GLOBALS['CustomerFirstName'] = isc_html_escape($existingCustomer['custconfirstname']); $GLOBALS['CustomerLastName'] = isc_html_escape($existingCustomer['custconlastname']); $GLOBALS['CustomerPhone'] = ''; if ($existingCustomer['custconphone']) { $GLOBALS['CustomerPhone'] = isc_html_escape($existingCustomer['custconphone']) . '<br />'; } $GLOBALS['CustomerEmail'] = ''; if ($existingCustomer['custconemail']) { $GLOBALS['CustomerEmail'] = '<a href="mailto:' . isc_html_escape($existingCustomer['custconemail']) . '">' . isc_html_escape($existingCustomer['custconemail']) . '</a><br />'; } $GLOBALS['CustomerCompany'] = ''; if ($existingCustomer['custconcompany']) { $GLOBALS['CustomerCompany'] = isc_html_escape($existingCustomer['custconcompany']) . '<br />'; } // Grab the addresses $addresses = $this->LoadCustomerAddresses($existingCustomer['customerid']); $GLOBALS['AddressJson'] = 'OrderManager.LoadInAddresses(' . isc_json_encode($addresses) . ');'; if (!empty($addresses)) { $GLOBALS['HideAddressSelects'] = ''; $GLOBALS['DisableAddressSelects'] = 'disabled="disabled"'; } $GLOBALS['SelectedCustomer'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrdersCustomerSearchResult'); } //alandy_2011-6-23 add. /* if($postData['orderid']>0){ $query = " SELECT ordbillemail,ordshipemail FROM [|PREFIX|]orders WHERE ordcustid='".(int)$postData['ordcustid']."' and orderid=".$postData['orderid']." "; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while($rs=$GLOBALS['ISC_CLASS_DB']->Fetch($result)){ if(!empty($rs['ordbillemail'])){ $GLOBALS['GuestCustomerEmail']=$rs['ordbillemail']; }else{ $GLOBALS['GuestCustomerEmail']=$rs['ordshipemail']; } } } */ } else { if (isset($postData['ordcustid']) && $postData['ordcustid'] == 0) { if (!isset($postData['customerType'])) { $GLOBALS['CurrentTab'] = 2; } else { if ($postData['customerType'] == 'anonymous') { $GLOBALS['CurrentTab'] = 2; } else { $GLOBALS['CurrenTab'] = 1; } } } } /** * Customer and order custom fields */ $GLOBALS['OrderCustomFormFieldsAccountFormId'] = FORMFIELDS_FORM_ACCOUNT; $GLOBALS['OrderCustomFormFieldsBillingFormId'] = FORMFIELDS_FORM_BILLING; $GLOBALS['OrderCustomFormFieldsShippingFormId'] = FORMFIELDS_FORM_SHIPPING; $GLOBALS['CustomFieldsAccountLeftColumn'] = ''; $GLOBALS['CustomFieldsAccountRightColumn'] = ''; $GLOBALS['CustomFieldsBillingColumn'] = ''; $GLOBALS['CustomFieldsShippingColumn'] = ''; $formIdx = array(FORMFIELDS_FORM_ACCOUNT, FORMFIELDS_FORM_BILLING, FORMFIELDS_FORM_SHIPPING); $fieldMap = array('FirstName' => 'firstname', 'LastName' => 'lastname', 'Company' => 'company', 'Phone' => 'phone', 'AddressLine1' => 'street1', 'AddressLine2' => 'street2', 'City' => 'suburb', 'Zip' => 'zip', 'Country' => 'country', 'State' => 'state'); /** * Now process the forms */ foreach ($formIdx as $formId) { $formSessionId = 0; if ($formId == FORMFIELDS_FORM_ACCOUNT) { /** * We are only using the real custom fields for the account section, so check here */ if (!gzte11(ISC_MEDIUMPRINT)) { continue; } if (isset($existingCustomer['custformsessionid'])) { $formSessionId = $existingCustomer['custformsessionid']; } } else { if (isset($postData['ordformsessionid'])) { $formSessionId = $postData['ordformsessionid']; } } /** * This part here gets all the existing fields */ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields($formId, true); } else { if (isId($formSessionId)) { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields($formId, false, $formSessionId); } else { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields($formId); } } /** * Get any selected country and state. This needs to be separate as we physically * print out each form field at a time so we need this information before hand */ if ($formId !== FORMFIELDS_FORM_ACCOUNT) { $countryId = GetCountryIdByName(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') { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $country = $fields[$fieldId]->getValue(); } if ($formId == FORMFIELDS_FORM_BILLING) { $country = @$order['ordbillcountry']; } else { $country = @$order['ordshipcountry']; } if (trim($country) !== '') { $countryId = GetCountryIdByName($country); } } } } } /** * Now we construct and build each form field */ $column = 0; foreach (array_keys($fields) as $fieldId) { if ($formId == FORMFIELDS_FORM_ACCOUNT) { if ($fields[$fieldId]->record['formfieldprivateid'] !== '' || !gzte11(ISC_MEDIUMPRINT)) { continue; } $fieldHTML = $fields[$fieldId]->loadForFrontend(); if ($column % 2 > 0) { $varname = 'CustomFieldsAccountLeftColumn'; } else { $varname = 'CustomFieldsAccountRightColumn'; } } else { /** * We are using all the custom fields for the billing/shipping are, so check here */ if (!gzte11(ISC_MEDIUMPRINT) && $fields[$fieldId]->record['formfieldprivateid'] == '') { continue; } if ($formId == FORMFIELDS_FORM_BILLING) { $varname = 'CustomFieldsBillingColumn'; } else { $varname = 'CustomFieldsShippingColumn'; } /** * Set the value for the private fields if this is NOT a post */ if ($_SERVER['REQUEST_METHOD'] !== 'POST' && $fields[$fieldId]->record['formfieldprivateid'] !== '') { $key = @$fieldMap[$fields[$fieldId]->record['formfieldprivateid']]; if (trim($key) !== '') { if ($formId == FORMFIELDS_FORM_BILLING) { $key = 'ordbill' . $key; } else { $key = 'ordship' . $key; } if (array_key_exists($key, $order)) { $fields[$fieldId]->setValue($order[$key]); } } } /** * Add in any of the country/state lists if needed */ if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'country') { $fields[$fieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); if ($fields[$fieldId]->getValue() == '') { $fields[$fieldId]->setValue(GetConfig('CompanyCountry')); } $fields[$fieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $fieldId, 'stateId' => $stateFieldId, 'inOrdersAdmin' => true)); } else { if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'state' && isId($countryId)) { $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $fields[$fieldId]->setOptions($stateOptions); } } } /** * We also do not what these fields */ if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'savethisaddress' || isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'shiptoaddress') { continue; } } $GLOBALS[$varname] .= $fields[$fieldId]->loadForFrontend() . "\n"; $column++; } } /** * Add this to generate our JS event script */ $GLOBALS['FormFieldEventData'] = $GLOBALS['ISC_CLASS_FORM']->buildRequiredJS(); /** * Do we display the customer custom fields? */ if (!gzte11(ISC_MEDIUMPRINT)) { $GLOBALS['HideCustomFieldsAccountLeftColumn'] = 'none'; $GLOBALS['HideCustomFieldsAccountRightColumn'] = 'none'; } else { if ($GLOBALS['CustomFieldsAccountLeftColumn'] == '') { $GLOBALS['HideCustomFieldsAccountLeftColumn'] = 'none'; } if ($GLOBALS['CustomFieldsAccountRightColumn'] == '') { $GLOBALS['HideCustomFieldsAccountRightColumn'] = 'none'; } } $defaultValues = array('custgroupid' => 0, 'ordstatus' => 7); foreach ($defaultValues as $postField => $default) { if (!isset($postData[$postField])) { $postData[$postField] = $default; } } foreach ($orderFields as $templateField => $orderField) { if (!isset($postData[$orderField])) { $GLOBALS[$templateField] = ''; } else { $GLOBALS[$templateField] = isc_html_escape($postData[$orderField]); } } if (empty($GLOBALS["AnonymousEmail"])) { $GLOBALS["AnonymousEmail"] = $postData['ordbillemail']; } if (isset($postData['ordbillsaveAddress'])) { $GLOBALS['OrderBillSaveAddress'] = 'checked="checked"'; } if (isset($postData['ordshipsaveAddress'])) { $GLOBALS['OrderShipSaveAddress'] = 'checked="checked"'; } if (isset($postData['shippingUseBilling'])) { $GLOBALS['ShippingUseBillingChecked'] = 'checked="checked"'; } if (isset($postData['billingUseShipping'])) { $GLOBALS['BillingUseShippingChecked'] = 'checked="checked"'; } $GLOBALS['OrderStatusOptions'] = $this->GetOrderStatusOptions($postData['ordstatus']); /* * To hide Pay and save button in edit mode -- Baskaran */ if ($postData['ordstatus'] == '11') { $GLOBALS['PayandSaveDisplay'] = 'none'; } else { $GLOBALS['PayandSaveDisplay'] = ''; } $customerClass = GetClass('ISC_ADMIN_CUSTOMERS'); $GLOBALS['CustomerGroupOptions'] = $customerClass->GetCustomerGroupsAsOptions($postData['custgroupid']); $GLOBALS['PaymentMethodsList'] = $this->GetPaymentProviderList($postData); if (!empty($order)) { $GLOBALS['HideEmailInvoice'] = 'display: none'; } else { if (isset($postData['emailinvoice'])) { $GLOBALS['EmailInvoiceChecked'] = 'checked="checked"'; } } $GLOBALS['Message'] = GetFlashMessageBoxes(); }
/** * 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(); }
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; }
/** * Displays a template details form specific for an eBay site and selected category options * * @param int $siteId The eBay site to display a template for * @param array $categoryOptions The primary category options to customize the form * @param int $templateId Optional template Id to use to fill the form with * @return string The form HTML */ public function getTemplateForm($siteId, $categoryOptions, $templateId = 0) { // Load eBay XML cache $xmlContent = str_replace('xmlns=', 'ns=', $this->ReadCache($siteId)); $getEbayDetailsXml = new SimpleXMLElement($xmlContent); $currencyId = $this->getCurrencyFromSiteId($siteId); $currency = GetCurrencyById($currencyId); $this->template->assign('currency', $currency); $this->template->assign('currencyToken', $currency['currencystring']); $this->template->assign('options', $categoryOptions); $this->template->assign('auctionDurations', $this->getDurationOptions($categoryOptions['auction_durations'])); $this->template->assign('fixedDurations', $this->getDurationOptions($categoryOptions['fixed_durations'])); $paymentMethods = $categoryOptions['payment_methods']; asort($paymentMethods); $this->template->assign('paymentMethods', $this->getPaymentMethodOptions($paymentMethods)); // location details $this->template->assign('countries', GetCountryListAsIdValuePairs()); // shipping details // Options for shipping services $shippingServiceObj = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ShippingServiceDetails'); $shippingServices = $this->getShippingAsOptions($shippingServiceObj); // Options for handling time $handlingTimeObject = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/DispatchTimeMaxDetails'); $handlingTimeArray = $this->convertEbayObjectToArray('DispatchTimeMax', 'Description', $handlingTimeObject); // remove the 0 days option as handling time is now required with ebay and 0 isnt valid unset($handlingTimeArray[0]); ksort($handlingTimeArray); $this->template->assign('handlingTimes', $handlingTimeArray); // Retrieving shipping cost type $this->template->assign('domesticShippingCostTypes', $shippingServices['Domestic']['ServiceTypes']); $this->template->assign('internationalShippingCostTypes', $shippingServices['International']['ServiceTypes']); // Shipping service Flat $domesticFlatServices = $shippingServices['Domestic']['Services']['Flat']; // is Pickup offered as a service? remove it from our service list and set it as a template var if (isset($domesticFlatServices['Other']['Pickup'])) { $this->template->assign('domesticPickupAllowed', true); unset($domesticFlatServices['Other']['Pickup']); } $this->template->assign('DomesticShippingServFlat', $domesticFlatServices); $this->template->assign('InternationalShippingServFlat', $shippingServices['International']['Services']['Flat']); // Shipping service Calculated if (!empty($shippingServices['Domestic']['Services']['Calculated'])) { $this->template->assign('DomesticShippingServCalculated', $shippingServices['Domestic']['Services']['Calculated']); } if (!empty($shippingServices['International']['Services']['Calculated'])) { $this->template->assign('InternationalShippingServCalculated', $shippingServices['International']['Services']['Calculated']); } // Shipping Service Package Details - only used for calculated shipping cost type $shippingPackageObj = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ShippingPackageDetails'); $shippingPackageArr = $this->convertEbayObjectToArray('ShippingPackage', 'Description', $shippingPackageObj); $this->template->assign('DomesticShippingPackage', $shippingPackageArr); $this->template->assign('InternationalShippingPackage', $shippingPackageArr); // ship to locations $shippingLocationObj = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ShippingLocationDetails'); $shippingLocationArr = $this->convertEbayObjectToArray('ShippingLocation', 'Description', $shippingLocationObj); asort($shippingLocationArr); $this->template->assign('ShipToLocations', $shippingLocationArr); // additional shipping details $salesTaxStatesObject = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/TaxJurisdiction'); $salesTaxStatesArray = $this->convertEbayObjectToArray('JurisdictionID', 'JurisdictionName', $salesTaxStatesObject); $this->template->assign('hasSalesTaxStates', !empty($salesTaxStatesArray)); asort($salesTaxStatesArray); $this->template->assign('salesTaxStates', $salesTaxStatesArray); // refund details $refundObject = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ReturnPolicyDetails/Refund'); if ($refundObject) { $this->template->assign('refundOptions', $this->convertEbayObjectToArray('RefundOption', 'Description', $refundObject)); } $this->template->assign('refundSupported', (bool)$refundObject); $returnsWithinObject = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ReturnPolicyDetails/ReturnsWithin'); if ($returnsWithinObject) { $this->template->assign('returnsWithinOptions', $this->convertEbayObjectToArray('ReturnsWithinOption', 'Description', $returnsWithinObject)); } $this->template->assign('returnsWithinSupported', (bool)$returnsWithinObject); $returnCostPaidByObject = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ReturnPolicyDetails/ShippingCostPaidBy'); if ($returnCostPaidByObject) { $this->template->assign('returnCostPaidByOptions', $this->convertEbayObjectToArray('ShippingCostPaidByOption', 'Description', $returnCostPaidByObject)); } $this->template->assign('returnCostPaidBySupported', (bool)$returnCostPaidByObject); $returnDescriptionObject = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ReturnPolicyDetails/Description'); $this->template->assign('returnDescriptionSupported', (bool)$returnDescriptionObject); // hit counter $availableHitCounters = array ('NoHitCounter','HiddenStyle','BasicStyle','RetroStyle'); $hitCounters = array(); foreach ($availableHitCounters as $counter) { $hitCounters[$counter] = GetLang($counter); } $this->template->assign('hitCounters', $hitCounters); // Paid upgrade options // Gallery Style $availableGalleryOptions = array ('None', 'Gallery', 'Plus', 'Featured'); $galleryOptions = array(); foreach ($availableGalleryOptions as $galleryOption) { $galleryOptions[$galleryOption] = GetLang('EbayGallery' . $galleryOption); } $this->template->assign('galleryOptions', $galleryOptions); // Listing enhancement $listingFeaturesObject = $getEbayDetailsXml->xpath('/GeteBayDetailsResponse/ListingFeatureDetails'); $supportedListingFeatures = array('BoldTitle','Border','FeaturedFirst','FeaturedPlus','GiftIcon','Highlight','HomePageFeatured','ProPack'); $listingFeatures = array(); if (isset($listingFeaturesObject[0])) { foreach ($listingFeaturesObject[0] as $featureCode => $availability) { //@ToDo add support for PowerSellerOnly and TopRatedSellerOnly options if (!in_array($featureCode, $supportedListingFeatures) || $availability != 'Enabled') { continue; } $listingFeatures[$featureCode] = GetLang($featureCode); } } $this->template->assign('listingFeatures', $listingFeatures); // any defaults we should set $this->template->assign('quantityOption', 'one'); $this->template->assign('useItemPhoto', true); $this->template->assign('locationCountry', GetCountryIdByName(GetConfig('CompanyCountry'))); $this->template->assign('locationZip', GetConfig('CompanyZip')); $this->template->assign('locationCityState', GetConfig('CompanyCity') . ', ' . GetConfig('CompanyState')); $this->template->assign('reservePriceOption', 'ProductPrice'); $this->template->assign('reservePriceCustom', $categoryOptions['minimum_reserve_price']); $this->template->assign('startPriceOption', 'ProductPrice'); $this->template->assign('startPriceCustom', 0.01); $this->template->assign('buyItNowPriceOption', 'ProductPrice'); $this->template->assign('buyItNowPriceCalcPrice', 10); $this->template->assign('buyItNowPriceCustom', 0.01); $this->template->assign('fixedBuyItNowPriceOption', 'ProductPrice'); $this->template->assign('fixedBuyItNowPriceCustom', 0.01); $this->template->assign('auctionDuration', 'Days_7'); $this->template->assign('fixedDuration', 'Days_7'); $this->template->assign('useDomesticShipping', false); $this->template->assign('useInternationalShipping', false); $this->template->assign('useSalesTax', false); $this->template->assign('hitCounter', 'BasicStyle'); $this->template->assign('galleryOption', 'Gallery'); $this->template->assign('domesticFlatCount', 0); $this->template->assign('domesticCalcCount', 0); $this->template->assign('internationalFlatCount', 0); $this->template->assign('internationalCalcCount', 0); // assign template specific variables if ($templateId) { $template = new ISC_ADMIN_EBAY_TEMPLATE($templateId); $this->template->assign('currency', $template->getCurrency()); // quantity if ($template->getQuantityToSell() == 1) { $quantityOption = 'one'; } else { $quantityOption = 'more'; $this->template->assign('moreQuantity', $template->getQuantityToSell()); } $this->template->assign('quantityOption', $quantityOption); // item photo $this->template->assign('useItemPhoto', $template->getUseItemPhoto()); // lot size $this->template->assign('lotSize', $template->getLotSize()); // location details $this->template->assign('locationCountry', GetCountryIdByISO2($template->getItemLocationCountry())); $this->template->assign('locationZip', $template->getItemLocationZip()); $this->template->assign('locationCityState', $template->getItemLocationCityState()); // selling method $this->template->assign('sellingMethod', $template->getSellingMethod()); if ($template->getSellingMethod() == self::CHINESE_AUCTION_LISTING) { // reserve price $this->template->assign('useReservePrice', $template->getReservePriceUsed()); $reservePriceOption = 'ProductPrice'; if ($template->getReservePriceUsed()) { $reservePriceOption = $template->getReservePriceOption(); if ($reservePriceOption == 'PriceExtra') { $this->template->assign('reservePriceCalcPrice', $template->getReservePriceCalcPrice()); $this->template->assign('reservePriceCalcOption', $template->getReservePriceCalcOption()); $this->template->assign('reservePriceCalcOperator', $template->getReservePriceCalcOperator()); } elseif ($reservePriceOption == 'CustomPrice') { $this->template->assign('reservePriceCustom', $template->getReservePriceCustomPrice()); } } $this->template->assign('reservePriceOption', $reservePriceOption); // start price $startPriceOption = $template->getStartPriceOption(); if ($startPriceOption == 'PriceExtra') { $this->template->assign('startPriceCalcPrice', $template->getStartPriceCalcPrice()); $this->template->assign('startPriceCalcOption', $template->getStartPriceCalcOption()); $this->template->assign('startPriceCalcOperator', $template->getStartPriceCalcOperator()); } elseif ($startPriceOption == 'CustomPrice') { $this->template->assign('startPriceCustom', $template->getStartPriceCustomPrice()); } $this->template->assign('startPriceOption', $startPriceOption); // buy it now price $this->template->assign('useBuyItNowPrice', $template->getBuyItNowPriceUsed()); $buyItNowPriceOption = 'ProductPrice'; if ($template->getBuyItNowPriceUsed()) { $buyItNowPriceOption = $template->getBuyItNowPriceOption(); if ($buyItNowPriceOption == 'PriceExtra') { $this->template->assign('buyItNowPriceCalcPrice', $template->getBuyItNowPriceCalcPrice()); $this->template->assign('buyItNowPriceCalcOption', $template->getBuyItNowPriceCalcOption()); $this->template->assign('buyItNowPriceCalcOperator', $template->getBuyItNowPriceCalcOperator()); } elseif ($buyItNowPriceOption == 'CustomPrice') { $this->template->assign('buyItNowPriceCustom', $template->getBuyItNowPriceCustomPrice()); } } $this->template->assign('buyItNowPriceOption', $buyItNowPriceOption); $this->template->assign('auctionDuration', $template->getListingDuration()); } else { // Fixed Price Item $fixedBuyItNowPriceOption = $template->getStartPriceOption(); if ($fixedBuyItNowPriceOption == 'PriceExtra') { $this->template->assign('fixedBuyItNowPriceCalcPrice', $template->getStartPriceCalcPrice()); $this->template->assign('fixedBuyItNowPriceCalcOption', $template->getStartPriceCalcOption()); $this->template->assign('fixedBuyItNowPriceCalcOperator', $template->getStartPriceCalcOperator()); } elseif ($fixedBuyItNowPriceOption == 'CustomPrice') { $this->template->assign('fixedBuyItNowPriceCustom', $template->getStartPriceCustomPrice()); } $this->template->assign('fixedBuyItNowPriceOption', $fixedBuyItNowPriceOption); $this->template->assign('fixedDuration', $template->getListingDuration()); } // payment details $this->template->assign('selectedPaymentMethods', $template->getPaymentMethods()); $this->template->assign('paypalEmailAddress', $template->getPayPalEmailAddress()); // domestic shipping $this->template->assign('useDomesticShipping', $template->getUseDomesticShipping()); if ($template->getUseDomesticShipping()) { $settings = $template->getDomesticShippingSettings(); $shippingType = $settings['cost_type']; $this->template->assign('domesticShippingCostType', $shippingType); $services = $template->getDomesticShippingServices(); // flat options if ($shippingType == 'Flat') { $this->template->assign('domesticFlatShippingServices', $services); $this->template->assign('domesticFlatCount', count($services)); } // calculated options else { $service = current($services); $this->template->assign('domesticPackageType', $settings['package_type']); $this->template->assign('domesticCalculatedShippingServices', $services); $this->template->assign('domesticCalcCount', count($services)); } $this->template->assign('domesticFreeShipping', $settings['is_free_shipping']); $this->template->assign('domesticGetItFast', $settings['get_it_fast']); $this->template->assign('domesticLocalPickup', $settings['offer_pickup']); $this->template->assign('domesticHandlingCost', $settings['handling_cost']); } // international shipping $this->template->assign('useInternationalShipping', $template->getUseInternationalShipping()); if ($template->getUseInternationalShipping()) { $settings = $template->getInternationalShippingSettings(); $shippingType = $settings['cost_type']; $this->template->assign('internationalShippingCostType', $shippingType); $services = $template->getInternationalShippingServices(); // flat options if ($shippingType == 'Flat') { $this->template->assign('internationalFlatShippingServices', $services); $this->template->assign('internationalFlatCount', count($services)); } // calculated options else { $service = current($services); $this->template->assign('internationalPackageType', $settings['package_type']); $this->template->assign('internationalCalculatedShippingServices', $services); $this->template->assign('internationalCalcCount', count($services)); } $this->template->assign('internationalFreeShipping', $settings['is_free_shipping']); $this->template->assign('internationalHandlingCost', $settings['handling_cost']); } // other shipping $this->template->assign('handlingTime', $template->getHandlingTime()); $this->template->assign('useSalesTax', $template->getUseSalesTax()); $this->template->assign('salesTaxState', $template->getSalesTaxState()); $this->template->assign('salesTaxPercent', $template->getSalesTaxPercent()); $this->template->assign('salesTaxIncludesShipping', $template->getShippingIncludedInTax()); // other details $this->template->assign('checkoutInstructions', $template->getCheckoutInstructions()); $this->template->assign('acceptReturns', $template->getReturnsAccepted()); $this->template->assign('returnOfferedAs', $template->getReturnOfferedAs()); $this->template->assign('returnsPeriod', $template->getReturnsPeriod()); $this->template->assign('returnCostPaidBy', $template->getReturnCostPaidBy()); $this->template->assign('additionalPolicyInfo', $template->getAdditionalPolicyInfo()); $this->template->assign('hitCounter', $template->getCounterStyle()); $this->template->assign('galleryOption', $template->getGalleryType()); $this->template->assign('selectedListingFeatures', $template->getListingFeatures()); } return $this->template->render('ebay.template.form.details.tpl'); }
/** * Generate the choose an address form for the express checkout for either a billing or shipping address. * * @param string The type of address fields to generate (either billing or shipping) * @return string The generated address form. */ public function ExpressCheckoutChooseAddress($addressType, $buildRequiredJS=false) { $templateAddressType = $addressType; if($templateAddressType == 'account') { $templateAddressType = 'billing'; } $templateUpperAddressType = ucfirst($templateAddressType); $GLOBALS['AddressList'] = ''; $GLOBALS['AddressType'] = $templateAddressType; $GLOBALS['UpperAddressType'] = $templateUpperAddressType; $GLOBALS['HideCreateAddress'] = 'display: none'; $GLOBALS['HideChooseAddress'] = 'display: none'; $GLOBALS['CreateAccountForm'] = ''; $country_id = GetCountryIdByName(GetConfig('CompanyCountry')); $selectedCountry = GetConfig('CompanyCountry'); $selectedState = 0; if ($addressType == 'shipping') { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_SHIPPING); } else if (!CustomerIsSignedIn() && $addressType == 'account') { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ACCOUNT); $fields += $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_BILLING); } else { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_BILLING); } // If the customer isn't signed in, then by default we show the create form if(!CustomerIsSignedIn() ) { $GLOBALS['HideCreateAddress'] = ''; } // If the customer is logged in, load up their existing addresses else { $GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER'); $shippingAddresses = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerShippingAddresses(); // If the customer doesn't have any addresses, show the creation form if(empty($shippingAddresses)) { $GLOBALS['HideChooseAddress'] = 'display: none'; $GLOBALS['HideCreateAddress'] = ''; } else { $GLOBALS['HideChooseAddress'] = ''; $addressMap = array( 'shipfullname', 'shipcompany', 'shipaddress1', 'shipaddress2', 'shipcity', 'shipstate', 'shipzip', 'shipcountry' ); foreach($shippingAddresses as $address) { $formattedAddress = ''; foreach($addressMap as $field) { if(!$address[$field]) { continue; } $formattedAddress .= $address[$field] .', '; } $GLOBALS['AddressSelected'] = ''; if(isset($_SESSION['CHECKOUT']['SelectAddress'])) { if($_SESSION['CHECKOUT']['SelectAddress'] == $address['shipid']) { $GLOBALS['AddressSelected'] = ' selected="selected"'; } } else if(!$GLOBALS['AddressList']) { $GLOBALS['AddressSelected'] = ' selected="selected"'; } $GLOBALS['AddressId'] = $address['shipid']; $GLOBALS['AddressLine'] = isc_html_escape(trim($formattedAddress, ', ')); $GLOBALS['AddressList'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('ExpressCheckoutAddress'); } } } if($addressType == 'billing') { $quoteAddress = getCustomerQuote()->getBillingAddress(); } else { $quoteAddress = getCustomerQuote()->setIsSplitShipping(false) ->getShippingAddress(); } $selectedCountry = $quoteAddress->getCountryName(); $selectedState = $quoteAddress->getStateName(); $country_id = $quoteAddress->getCountryId(); $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($fields as $fieldId => $formField) { $formFieldPrivateId = $formField->record['formfieldprivateid']; // Hide the leave blank label for passwords on checkout if($formField->getFieldType() == 'password') { $formField->setLeaveBlankLabel(false); } if(isset($quoteAddressFields[$formFieldPrivateId])) { $method = $quoteAddressFields[$formFieldPrivateId]; $formField->setValue($quoteAddress->$method()); } else { $value = $quoteAddress->getCustomField($fieldId); if($value !== false) { $formField->setValue($value); } } } $GLOBALS['HideSaveAddress'] = 'display: none'; $GLOBALS['SaveAddressChecked'] = ''; // If the customer is signed in, or creating an account they can save addresses if(customerIsSignedIn() || $addressType == 'account') { $GLOBALS['HideSaveAddress'] = ''; if($quoteAddress->getSaveAddress() === true || $quoteAddress->getSaveAddress() === null) { $GLOBALS['SaveAddressChecked'] = 'checked="checked"'; } } if($addressType == 'billing' || $addressType == 'account') { $GLOBALS['BillToAddressButton'] = GetLang('BillToThisAddress'); if($this->getQuote()->isDigital()) { $GLOBALS['UseAddressTitle'] = isc_html_escape(GetLang('BillToThisAddress')); $GLOBALS['HideShippingOptions'] = 'display: none'; } else { $GLOBALS['UseAddressTitle'] = isc_html_escape(GetLang('BillAndShipToAddress')); } $GLOBALS['UseExistingAddress'] = GetLang('UseExistingBillingAddress'); $GLOBALS['AddNewAddress'] = GetLang('UseNewBillingAddress'); $GLOBALS['ShipToBillingName'] = 'ship_to_billing'; $GLOBALS['ShipToAddressChecked'] = 'checked="checked"'; } else { $GLOBALS['BillToAddressButton'] = GetLang('ShipToThisAddress'); $GLOBALS['UseAddressTitle'] = isc_html_escape(GetLang('ShipToThisAddress')); $GLOBALS['UseExistingAddress'] = GetLang('UseExistingShippingAddress'); $GLOBALS['AddNewAddress'] = GetLang('UseNewShippingAddress'); $GLOBALS['ShipToBillingName'] = 'bill_to_shipping'; $GLOBALS['HideShippingOptions'] = 'display: none'; } // We need to loop here so we can get the field Id for the state $countryId = GetCountryIdByName($selectedCountry); $stateFieldId = 0; $countryFieldId = 0; foreach($fields as $fieldId => $formField) { if (strtolower($formField->record['formfieldprivateid']) == 'state') { $stateFieldId = $fieldId; } else if (strtolower($formField->record['formfieldprivateid']) == 'country') { $countryFieldId = $fieldId; } } // Compile the fields. Also set the country and state dropdowns while we are here $GLOBALS['CompiledFormFields'] = ''; // If checking out as a guest, the email address field also needs to be shown if($addressType == 'billing' && !customerIsSignedIn()) { $emailField = $GLOBALS['ISC_CLASS_FORM']->getFormField(FORMFIELDS_FORM_ACCOUNT, '1', '', true); $emailField->setValue($quoteAddress->getEmail()); $GLOBALS['ISC_CLASS_FORM']->addFormFieldUsed($emailField); $GLOBALS['CompiledFormFields'] .= $emailField->loadForFrontend(); } foreach($fields as $fieldId => $formField) { // lowercase the formfieldprivateid for conditional matching below $formFieldPrivateId = strtolower($formField->record['formfieldprivateid']); if ($formFieldPrivateId == 'country') { $formField->setOptions(GetCountryListAsIdValuePairs()); if ($selectedCountry !== '') { $formField->setValue($selectedCountry); } /** * This is the event handler for changing the states where a country is selected */ $formField->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryFieldId, 'stateId' => $stateFieldId)); } else if ($formFieldPrivateId == 'state' && isId($countryId)) { $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $formField->setOptions($stateOptions); } else { // no states for our country, we need to mark this as not required $formField->setRequired(false); } } $GLOBALS['CompiledFormFields'] .= $fields[$fieldId]->loadForFrontend() . "\n"; } $GLOBALS['CompiledFormFieldJavascript'] = "\n\n" . $GLOBALS['ISC_CLASS_FORM']->buildRequiredJS(true); return $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('ExpressCheckoutChooseAddress'); }
/** * Generate the choose an address form for the express checkout for either a billing or shipping address. * * @param string The type of address fields to generate (either billing or shipping) * @return string The generated address form. */ public function ExpressCheckoutChooseAddress($addressType) { $templateAddressType = ucfirst($addressType); $GLOBALS['AddressList'] = ''; $GLOBALS['ISC_CLASS_MAKEAOFFER'] = GetClass('ISC_MAKEAOFFER'); $GLOBALS['AddressType'] = $addressType; $GLOBALS['UpperAddressType'] = $templateAddressType; $GLOBALS['HideCreateAddress'] = 'display: none'; $GLOBALS['HideChooseAddress'] = 'display: none'; $GLOBALS['CreateAccountForm'] = ''; $country_id = GetCountryIdByName(GetConfig('CompanyCountry')); $selectedCountry = GetConfig('CompanyCountry'); $selectedState = 0; if ($addressType == 'shipping') { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_SHIPPING); $formId = FORMFIELDS_FORM_SHIPPING; } else { if (!CustomerIsSignedIn()) { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ACCOUNT); $fields += $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_BILLING); $formId = FORMFIELDS_FORM_ACCOUNT; } else { $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_BILLING); $formId = FORMFIELDS_FORM_BILLING; } } // If the customer isn't signed in, then by default we show the create form if (!CustomerIsSignedIn()) { $GLOBALS['HideCreateAddress'] = ''; $address = array(); if ($addressType == 'billing' && isset($_SESSION['CHECKOUT']['BILLING_ADDRESS'])) { $address = $_SESSION['CHECKOUT']['BILLING_ADDRESS']; } else { if ($addressType == 'shipping') { if (isset($_SESSION['CHECKOUT']['SHIPPING_ADDRESS'])) { $address = $_SESSION['CHECKOUT']['SHIPPING_ADDRESS']; } else { if (isset($_SESSION['CHECKOUT']['BILLING_ADDRESS'])) { $address = $_SESSION['CHECKOUT']['BILLING_ADDRESS']; } } } } // if billing address is saved in session, use the session billing address to prefill the address form if (!empty($address)) { if (isset($address['shipcountry'])) { $selectedCountry = $address['shipcountry']; } if (isset($address['shipstateid'])) { $selectedState = $address['shipstateid']; } if (isset($address['shipcountryid'])) { $country_id = $address['shipcountryid']; } $addressMap = array('EmailAddress' => 'shipemail', 'FirstName' => 'shipfirstname', 'LastName' => 'shiplastname', 'CompanyName' => 'shipcompany', 'AddressLine1' => 'shipaddress1', 'AddressLine2' => 'shipaddress2', 'City' => 'shipcity', 'State' => 'shipstate', 'Zip' => 'shipzip', 'Phone' => 'shipphone'); $fieldMap = array(); foreach (array_keys($fields) as $fieldId) { if ($fields[$fieldId]->record['formfieldprivateid'] == '') { continue; } $fieldMap[$fields[$fieldId]->record['formfieldprivateid']] = $fieldId; } foreach ($addressMap as $formField => $addressField) { if (!isset($address[$addressField]) || !isset($fieldMap[$formField])) { continue; } $fields[$fieldMap[$formField]]->SetValue($address[$addressField]); } } /** * Turn off the 'leave password blank' label for the passwords if we are not * logged in (creating a new account) */ foreach (array_keys($fields) as $fieldId) { if ($fields[$fieldId]->getFieldType() == 'password') { $fields[$fieldId]->setLeaveBlankLabel(false); } } } else { $GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER'); $shippingAddresses = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerShippingAddresses(); // If the customer doesn't have any addresses, show the creation form if (empty($shippingAddresses)) { $GLOBALS['HideChooseAddress'] = 'display: none'; $GLOBALS['HideCreateAddress'] = ''; } else { $GLOBALS['HideChooseAddress'] = ''; $addressMap = array('shipfullname', 'shipcompany', 'shipaddress1', 'shipaddress2', 'shipcity', 'shipstate', 'shipzip', 'shipcountry'); foreach ($shippingAddresses as $address) { $formattedAddress = ''; foreach ($addressMap as $field) { if (!$address[$field]) { continue; } $formattedAddress .= $address[$field] . ', '; } $GLOBALS['AddressSelected'] = ''; if (isset($_SESSION['CHECKOUT']['SelectAddress'])) { if ($_SESSION['CHECKOUT']['SelectAddress'] == $address['shipid']) { $GLOBALS['AddressSelected'] = ' selected="selected"'; } } else { if (!$GLOBALS['AddressList']) { $GLOBALS['AddressSelected'] = ' selected="selected"'; } } $GLOBALS['AddressId'] = $address['shipid']; $GLOBALS['AddressLine'] = isc_html_escape(trim($formattedAddress, ', ')); $GLOBALS['AddressList'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('ExpressCheckoutAddress'); } } } if ($addressType == 'billing') { if (!CustomerIsSignedIn()) { $GLOBALS['CreateAccountForm'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('ExpressCheckoutCreateAccount'); } $GLOBALS['BillToAddressButton'] = GetLang('BillToThisAddress'); if ($GLOBALS['ISC_CLASS_MAKEAOFFER']->api->AllProductsInCartAreIntangible()) { $GLOBALS['UseAddressTitle'] = GetLang('BillToThisAddress'); $GLOBALS['HideShippingOptions'] = 'display: none'; } else { $GLOBALS['UseAddressTitle'] = GetLang('BillAndShipToAddress'); } $GLOBALS['UseExistingAddress'] = GetLang('UseExistingBillingAddress'); $GLOBALS['AddNewAddress'] = GetLang('UseNewBillingAddress'); $GLOBALS['ShipToBillingName'] = 'ship_to_billing'; } else { $GLOBALS['BillToAddressButton'] = GetLang('ShipToThisAddress'); $GLOBALS['UseAddressTitle'] = GetLang('ShipToThisAddress'); $GLOBALS['UseExistingAddress'] = GetLang('UseExistingShippingAddress'); $GLOBALS['AddNewAddress'] = GetLang('UseNewShippingAddress'); $GLOBALS['ShipToBillingName'] = 'bill_to_shipping'; $GLOBALS['HideShippingOptions'] = 'display: none'; } // We need to loop here so we can get the field Id for the state $countryId = GetCountryIdByName($selectedCountry); $stateFieldId = 0; $countryFieldId = 0; foreach (array_keys($fields) as $fieldId) { if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'state') { $stateFieldId = $fieldId; } else { if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'country') { $countryFieldId = $fieldId; } } } // Compile the fields. Also set the country and state dropdowns while we are here $GLOBALS['CompiledFormFields'] = ''; foreach (array_keys($fields) as $fieldId) { if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'country') { $fields[$fieldId]->setOptions(GetCountryListAsIdValuePairs()); if ($selectedCountry !== '') { $fields[$fieldId]->setValue($selectedCountry); } /** * This is the event handler for changing the states where a country is selected */ $fields[$fieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryFieldId, 'stateId' => $stateFieldId)); } else { if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'state' && isId($countryId)) { $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $fields[$fieldId]->setOptions($stateOptions); } /** * Put an event handler on the 'ship to this address' so we can change the button value if * this is the billing form, else remove it as it is the shipping form */ } else { if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'shiptoaddress') { if ($addressType == 'shipping') { continue; } else { $fields[$fieldId]->addEventHandler('change', 'FormFieldEvent.CheckBoxShipToAddress'); } } } } /** * Set the 'save address' and 'ship to' checkboxes to checked */ if (strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'savethisaddress' || strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'shiptoaddress') { $fields[$fieldId]->setValueByIndex(array(0)); } $GLOBALS['CompiledFormFields'] .= $fields[$fieldId]->loadForFrontend() . "\n"; } return $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('ExpressCheckoutChooseAddress'); }
/** * Generate a table-based grid of shipping zones. * * @param int Passed by reference, the number of shipping zones we'll be showing. * @return string The built HTML for the grid containing the shipping zones. */ public function ManageShippingZonesGrid(&$numZones) { $page = 0; $start = 0; $numZones = 0; $GLOBALS['ZonesGrid'] = ''; $GLOBALS['Nav'] = ''; if(isset($_REQUEST['page'])) { $page = (int)$_REQUEST['page']; } else { $page = 1; } // Where are we starting at? if($page == 1) { $start = 0; } else { $start = ($page * ISC_SHIPPING_ZONES_PER_PAGE) - (ISC_SHIPPING_ZONES_PER_PAGE); } // Get the names of the countries we support $countryList = GetCountryListAsIdValuePairs(); if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() > 0) { $vendorRestriction = " AND zonevendorid='".(int)$GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()."'"; } else if(isset($_REQUEST['vendorId'])) { $vendorRestriction = " AND zonevendorid='".(int)$_REQUEST['vendorId']."'"; } else { $vendorRestriction = " AND zonevendorid='0'"; } // Fetch the list of shipping zones $query = " SELECT COUNT(zoneid) FROM [|PREFIX|]shipping_zones WHERE 1=1 ".$vendorRestriction." "; $numZones = $GLOBALS['ISC_CLASS_DB']->FetchOne($query); // If there aren't any zones set up, just return nothing here if($numZones == 0) { return ''; } $query = " SELECT * FROM [|PREFIX|]shipping_zones WHERE 1=1 ".$vendorRestriction." ORDER BY zonedefault DESC, zonename ASC "; $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit($start, ISC_SHIPPING_ZONES_PER_PAGE); $result = $GLOBALS["ISC_CLASS_DB"]->Query($query); $numPages = ceil($numZones / ISC_SHIPPING_ZONES_PER_PAGE); // Add the "(Page x of n)" label if($numZones > ISC_SHIPPING_ZONES_PER_PAGE) { $GLOBALS['Nav'] = "(".GetLang('Page')." ".$page." of ".$numPages.") "; $GLOBALS['Nav'] .= BuildPagination($numZones, ISC_SHIPPING_ZONES_PER_PAGE, $page, "index.php?ToDo=viewShippingSettings¤tTab=1".$GLOBALS['VendorIdAdd']); } else { $GLOBALS['Nav'] = ""; $GLOBALS['HidePaging'] = 'display: none'; } $zones = array(); while($zone = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $GLOBALS['ZoneId'] = $zone['zoneid']; $GLOBALS['ZoneName'] = isc_html_escape($zone['zonename']); $GLOBALS['ZoneLocations'] = ''; if($zone['zonedefault'] == 1) { $GLOBALS['ZoneClass'] = 'GridRowSel'; $GLOBALS['ZoneDeleteCheckbox'] = " disabled='disabled'"; $GLOBALS['ZoneName'] .= " <span style='margin-left: font-size: 11px; font-weight: bold;'>(".GetLang('ShippingZoneEverywhereElse')." - <a href='#' onclick='alert(\"".GetLang('ShippingZoneEverywhereElseHelp')."\"); this.blur();'>".GetLang('WhatDoesThisMean')."</a>)</span>"; $GLOBALS['ZoneType'] = GetLang('ZoneTypeGlobal'); $GLOBALS['ZoneStatus'] = ' '; $GLOBALS['HideDeleteZone'] = 'display: none'; } else { $GLOBALS['HideDeleteZone'] = ''; $GLOBALS['ZoneClass'] = 'GridRow'; $GLOBALS['ZoneDeleteCheckbox'] = ''; if($zone['zonetype'] == "state") { $GLOBALS['ZoneType'] = GetLang('ZoneTypeState'); } else if($zone['zonetype'] == "zip") { $GLOBALS['ZoneType'] = GetLang('ZoneTypeZip'); } else { $GLOBALS['ZoneType'] = GetLang('ZoneTypeCountry'); } if($zone['zoneenabled'] == 1) { $statusImage = 'tick.gif'; } else { $statusImage = 'cross.gif'; } $GLOBALS['ZoneStatus'] = "<a href='index.php?ToDo=toggleShippingZoneStatus&zoneId=".$zone['zoneid']."'><img src='images/".$statusImage."' alt='' border='0' /></a>"; } $gridRow = $this->template->render('shippingzones.manage.row.tpl'); if($zone['zoneid'] == 1) { $GLOBALS['ZonesGrid'] = $gridRow . $GLOBALS['ZonesGrid']; } else { $GLOBALS['ZonesGrid'] .= $gridRow; } } return $this->template->render('shippingzones.manage.grid.tpl'); }
protected function _CommitCoupon($CouponId = 0) { $name = trim($_POST['couponname']); $type = $_POST['coupontype']; // dollar or percent $amount = DefaultPriceFormat($_POST['couponamount']); $appliesTo = $_POST['usedfor']; if($appliesTo == "categories") { $appliesValues = $_POST['catids']; // nothing selected then default to all categories if (empty($appliesValues)) { $appliesValues = array('0'); } } else { $appliesValues = explode(",", $_POST['prodids']); } if (!empty($_POST['couponexpires'])) { $expires = ConvertDateToTime($_POST['couponexpires']); } else { $expires = 0; } if (!isset($_POST['couponcode']) || empty($_POST['couponcode'])) { $code = GenerateCouponCode(); } else { $code = trim($_POST['couponcode']); } if (isset($_POST['couponenabled'])) { $enabled = 1; } else { $enabled = 0; } $minPurchase = DefaultPriceFormat($_POST['couponminpurchase']); $maxUses = 0; $maxUsesPerCus = 0; if (isset($_POST['couponmaxuses'])) { $maxUses = (int)$_POST['couponmaxuses']; } if (isset($_POST['couponmaxusespercus'])) { $maxUsesPerCus = (int)$_POST['couponmaxusespercus']; } $locationRestricted = 0; if (!empty ($_POST['YesLimitByLocation'])) { $locationRestricted = 1; } $shippingMethodRestricted = 0; if (!empty ($_POST['YesLimitByShipping'])) { $shippingMethodRestricted = 1; } $coupon = array( 'couponname' => $name, 'coupontype' => $type, 'couponamount' => $amount, 'couponminpurchase' => $minPurchase, 'couponexpires' => $expires, 'couponenabled' => $enabled, 'couponcode' => $code, 'couponappliesto' => $appliesTo, 'couponmaxuses' => $maxUses, 'couponmaxusespercus' => $maxUsesPerCus, 'location_restricted' => $locationRestricted, 'shipping_method_restricted' => $shippingMethodRestricted, ); // update existing coupon if ($CouponId) { $result = $GLOBALS['ISC_CLASS_DB']->UpdateQuery("coupons", $coupon, "couponid = '" . $GLOBALS['ISC_CLASS_DB']->Quote($CouponId) . "'"); if (!$result) { return "Failed to update coupon"; } //delete existing values $query = "DELETE FROM [|PREFIX|]coupon_values WHERE couponid = '" . $GLOBALS['ISC_CLASS_DB']->Quote($CouponId) . "'"; $GLOBALS['ISC_CLASS_DB']->Query($query); } else { // create new coupon $CouponId = $GLOBALS['ISC_CLASS_DB']->InsertQuery("coupons", $coupon); if (!isId($CouponId)) { return "Failed to create coupon"; } } // add applies to values if (!empty($appliesValues)) { foreach ($appliesValues as $value) { $couponvalue = array( 'couponid' => $CouponId, 'valueid' => $value ); $GLOBALS['ISC_CLASS_DB']->InsertQuery("coupon_values", $couponvalue); } } // Location restriction // Remove all the existing ones if exist $GLOBALS['ISC_CLASS_DB']->DeleteQuery('coupon_locations', "WHERE coupon_id = " . $GLOBALS['ISC_CLASS_DB']->Quote($CouponId)); if ($locationRestricted) { $selectedType = $_POST['LocationType']; if ($selectedType == 'country') { $countryList = GetCountryListAsIdValuePairs(); foreach($_POST['LocationTypeCountries'] as $countryId) { if(empty ($countryList[$countryId])) { continue; } $newLocation = array( 'coupon_id' => (int)$CouponId, 'selected_type' => $selectedType, 'value' => $countryList[$countryId], 'value_id' => $countryId, 'country_id' => 0, ); $GLOBALS['ISC_CLASS_DB']->InsertQuery('coupon_locations', $newLocation); } } else if ($selectedType == 'state') { $countryList = GetCountryListAsIdValuePairs(); $stateList = array(); foreach($_POST['LocationTypeStatesSelect'] as $stateRecord) { $state = explode('-', $stateRecord, 2); if(!isset($stateList[$state[0]])) { // Load the states in this country as we haven't done that before $stateList[$state[0]] = array(); $query = "SELECT * FROM [|PREFIX|]country_states WHERE statecountry='".(int)$state[0]."'"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while($stateResult = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $stateList[$stateResult['statecountry']][$stateResult['stateid']] = $stateResult['statename']; } } // Start storing what we received if(isset($stateList[$state[0]][$state[1]])) { $stateName = $stateList[$state[0]][$state[1]]; } else { $stateName = ''; } $newLocation = array( 'coupon_id' => (int)$CouponId, 'selected_type' => $selectedType, 'value' => $stateName, 'value_id' => (int)$state[1], 'country_id' => (int)$state[0], ); $GLOBALS['ISC_CLASS_DB']->InsertQuery('coupon_locations', $newLocation); } } else if ($selectedType == 'zip') { $zipCodes = explode("\n", $_POST['LocationTypeZipPostCodes']); foreach($zipCodes as $zipCode) { $zipCode = trim($zipCode); if(!$zipCode) { continue; } $newLocation = array( 'coupon_id' => (int)$CouponId, 'selected_type' => $selectedType, 'value' => $zipCode, 'value_id' => '0', 'country_id' => (int)$_POST['LocationTypeZipCountry'], ); $GLOBALS['ISC_CLASS_DB']->InsertQuery('coupon_locations', $newLocation); } } } // Shipping Method restriction // Remove all the existing ones if exist $GLOBALS['ISC_CLASS_DB']->DeleteQuery('coupon_shipping_methods', "WHERE coupon_id = " . $GLOBALS['ISC_CLASS_DB']->Quote($CouponId)); if ($shippingMethodRestricted) { foreach ($_POST['LocationTypeShipping'] as $shipper) { $newShippingMethod = array( 'coupon_id' => (int)$CouponId, 'module_id' => $shipper, ); $GLOBALS['ISC_CLASS_DB']->InsertQuery('coupon_shipping_methods', $newShippingMethod); } } // Log this action $GLOBALS['ISC_CLASS_LOG']->LogAdminAction($CouponId, $_POST['couponcode']); return $CouponId; }
/** * Map the address form fields * * Method will map each database record element in $data to the corresponding field * in $fields and set its value. Will also add in the country and state options * * @access private * @param array &$fields The referenced field list * @param array $data The optional database record to map against * @return bool TRUE if the mapping was successful, FALSE if not */ private function mapFieldData(&$fields, $data = array()) { if (!is_array($fields) || !is_array($data)) { return false; } $fieldMap = array('FirstName' => 'firstname', 'LastName' => 'lastname', 'CompanyName' => 'company', 'AddressLine1' => 'address1', 'AddressLine2' => 'address2', 'City' => 'city', 'State' => 'state', 'Country' => 'country', 'Zip' => 'zip', 'Phone' => 'phone'); $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']]; if (array_key_exists($key, $data)) { $fields[$fieldId]->setValue($data[$key]); } if ($key == 'shipcountry') { $countryFieldId = $fieldId; } else { if ($key == 'shipstate') { $stateFieldId = $fieldId; } } } if ($countryFieldId) { $fields[$countryFieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); if ($fields[$countryFieldId]->getValue() == '') { $fields[$countryFieldId]->setValue(GetConfig('CompanyCountry')); } if (isId($stateFieldId)) { $fields[$countryFieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryFieldId, 'stateId' => $stateFieldId)); $countryId = GetCountryByName($fields[$countryFieldId]->getValue()); $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $fields[$stateFieldId]->setOptions($stateOptions); } } } return true; }
/** * Map the address form fields * * Method will map each database record element in $data to the corresponding field * in $fields and set its value. Will also add in the country and state options * * @access private * @param array &$fields The referenced field list * @param array $data The optional database record to map against * @return bool TRUE if the mapping was successful, FALSE if not */ function mapFieldData(&$fields, $data=array()) { if (!is_array($fields) || !is_array($data)) { return false; } $fieldMap = getAddressFormMapping(); $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']]; if (array_key_exists($key, $data)) { $fields[$fieldId]->setValue($data[$key]); } if ($key == 'shipcountry') { $countryFieldId = $fieldId; } else if ($key == 'shipstate') { $stateFieldId = $fieldId; } } if ($countryFieldId) { $fields[$countryFieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); if ($fields[$countryFieldId]->getValue() == '') { $fields[$countryFieldId]->setValue(GetConfig('CompanyCountry')); } if (isId($stateFieldId)) { $fields[$countryFieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryFieldId, 'stateId' => $stateFieldId)); $countryId = GetCountryByName($fields[$countryFieldId]->getValue()); $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $fields[$stateFieldId]->setOptions($stateOptions); } else { // no states for our country, we need to mark this as not required $fields[$stateFieldId]->setRequired(false); } } } return true; }