public function SetPanelSettings()
 {
     $selectedCountry = GetConfig('CompanyCountry');
     $selectedState = 0;
     if (isset($GLOBALS['SavedAddress']) && is_array($GLOBALS['SavedAddress'])) {
         $address = $GLOBALS['SavedAddress'];
         $selectedCountry = $address['shipcountry'];
         $addressVars = array('account_email' => 'AccountEmail', 'shipfirstname' => 'AddressFirstName', 'shiplastname' => 'AddressLastName', 'shipcompany' => 'AddressCompany', 'shipaddress1' => 'AddressLine1', 'shipaddress2' => 'AddressLine2', 'shipcity' => 'AddressCity', 'shipstate' => 'AddressState', 'shipzip' => 'AddressZip', 'shipphone' => 'AddressPhone');
         if (isset($address['shipstateid'])) {
             $selectedState = $address['shipstateid'];
         }
         foreach ($addressVars as $addressField => $formField) {
             if (isset($address[$addressField])) {
                 $GLOBALS[$formField] = isc_html_escape($address[$addressField]);
             }
         }
     }
     $country_id = GetCountryIdByName($selectedCountry);
     $GLOBALS['CountryList'] = GetCountryList(GetConfig('CompanyCountry'), true);
     $GLOBALS['StateList'] = GetStateListAsOptions($country_id, $selectedState);
     // If there are no states for the country then
     // hide the dropdown and show the textbox instead
     if (GetNumStatesInCountry($country_id) == 0) {
         $GLOBALS['HideStateList'] = "none";
     } else {
         $GLOBALS['HideStateBox'] = "none";
     }
 }
예제 #2
0
 /**
  * Get the sales tax information regarding the passed billing & shipping details.
  *
  * @param mixed Either an integer with the billing address or an array of details about the address.
  * @param mixed Either an integer with the shipping address or an array of details about the address.
  * @return array Array of information containing the tax data. (name, rate, based on etc)
  */
 public function GetSalesTaxRate($billingAddress, $shippingAddress = 0)
 {
     // Setup the array which will be returned
     $taxData = array("tax_name" => "", "tax_rate" => 0, "tax_based_on" => "", "tax_id" => 0);
     // If tax is being applied globally, just return that
     if (GetConfig('TaxTypeSelected') == 2) {
         $basedOn = 'subtotal';
         if (GetConfig('DefaultTaxRateBasedOn')) {
             $basedOn = GetConfig('DefaultTaxRateBasedOn');
         }
         $taxData['tax_name'] = GetConfig('DefaultTaxRateName');
         $taxData['tax_rate'] = GetConfig('DefaultTaxRate');
         $taxData['tax_based_on'] = $basedOn;
         return $taxData;
     }
     $GLOBALS['ISC_CLASS_ACCOUNT'] = GetClass('ISC_ACCOUNT');
     $countryIds = array();
     $stateIds = array();
     if (!is_array($billingAddress)) {
         $billingAddress = $GLOBALS['ISC_CLASS_ACCOUNT']->GetShippingAddress($billingAddress);
     }
     if (!is_array($shippingAddress) && $shippingAddress > 0) {
         $shippingAddress = $GLOBALS['ISC_CLASS_ACCOUNT']->GetShippingAddress($shippingAddress);
     }
     // A billing address is required for every order. If we don't have one then there's no point in proceeding
     if (!is_array($billingAddress)) {
         return $taxData;
     }
     if (!isset($billingAddress['shipcountryid'])) {
         $billingAddress['shipcountryid'] = GetCountryIdByName($billingAddress['shipcountry']);
     }
     if (!isset($billingAddress['shipstateid'])) {
         $billingAddress['shipstateid'] = GetStateByName($billingAddress['shipstate'], $billingAddress['shipcountryid']);
     }
     if (is_array($shippingAddress)) {
         if (!isset($shippingAddress['shipcountryid'])) {
             $shippingAddress['shipcountryid'] = GetCountryIdByName($shippingAddress['shipcountry']);
         }
         if (!isset($shippingAddress['shipstateid'])) {
             $shippingAddress['shipstateid'] = GetStateByName($shippingAddress['shipstate'], $shippingAddress['shipcountryid']);
         }
     }
     // Do we have a matching state based tax rule?
     if ($billingAddress['shipstateid'] || is_array($shippingAddress) && $shippingAddress['shipstateid']) {
         $query = "\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM [|PREFIX|]tax_rates\n\t\t\t\t\tWHERE (1=0\n\t\t\t\t";
         if ($billingAddress['shipstateid']) {
             $query .= " OR (taxaddress='billing' AND taxratecountry='" . (int) $billingAddress['shipcountryid'] . "' AND taxratestates LIKE '%%," . (int) $billingAddress['shipstateid'] . ",%%')";
         }
         if (is_array($shippingAddress) && $shippingAddress['shipstateid']) {
             $query .= " OR (taxaddress='shipping' AND taxratecountry='" . (int) $shippingAddress['shipcountryid'] . "' AND taxratestates LIKE '%%," . (int) $shippingAddress['shipstateid'] . ",%%')";
         }
         $query .= ") AND taxratestatus='1'";
         $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
         $row = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
         if (is_array($row)) {
             $taxData = array('tax_name' => $row['taxratename'], 'tax_rate' => $row['taxratepercent'], 'tax_based_on' => $row['taxratebasedon'], 'tax_id' => $row['taxrateid']);
             return $taxData;
         }
     }
     // Maybe we've got a matching country based rule
     $query = "\n\t\t\t\tSELECT *\n\t\t\t\tFROM [|PREFIX|]tax_rates\n\t\t\t\tWHERE (1=0 OR (taxratecountry='" . (int) $billingAddress['shipcountryid'] . "' AND taxaddress='billing')\n\t\t\t";
     if (is_array($shippingAddress) && $shippingAddress['shipcountryid']) {
         $query .= " OR (taxratecountry='" . (int) $shippingAddress['shipcountryid'] . "' AND taxaddress='shipping')";
     }
     $query .= ") AND taxratestatus='1' AND taxratestates = ',0,'";
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $row = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
     if (is_array($row)) {
         $taxData = array('tax_name' => $row['taxratename'], 'tax_rate' => $row['taxratepercent'], 'tax_based_on' => $row['taxratebasedon'], 'tax_id' => $row['taxrateid']);
         return $taxData;
     }
     // Otherwise, if we still have nothing, perhaps we have a rule that applies to all countries
     $query = "\n\t\t\t\tSELECT *\n\t\t\t\tFROM [|PREFIX|]tax_rates\n\t\t\t\tWHERE taxratecountry='0' AND taxratestatus='1'\n\t\t\t";
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $row = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
     if (is_array($row)) {
         $taxData = array('tax_name' => $row['taxratename'], 'tax_rate' => $row['taxratepercent'], 'tax_based_on' => $row['taxratebasedon'], 'tax_id' => $row['taxrateid']);
         return $taxData;
     }
     // Still here? Just return nothing!
     return $taxData;
 }
예제 #3
0
	/**
	 * Set up everything pertaining to the display of the 'Estimate Shipping'
	 * feature, as well as the shipping cost of all items in the cart if it is
	 * known.
	 */
	public function setUpShippingAndHandling()
	{
		$GLOBALS['HideShoppingCartShippingCost'] = 'none';
		$GLOBALS['HideShoppingCartHandlingCost'] = 'none';
		$GLOBALS['HideShoppingCartShippingEstimator'] = 'display: none';

		$this->quote->setIsSplitShipping(false);

		$handling = $this->quote->getHandlingCost($this->displayIncludingTax);
		if($handling > 0) {
			$handlingFormatted = currencyConvertFormatPrice($handling);
			$GLOBALS['HandlingCost'] = $handlingFormatted;
			$GLOBALS['HideShoppingCartHandlingCost'] = '';
		}

		// All products in the cart are digital downloads so the shipping doesn't apply
		if($this->quote->isDigital()) {
			return;
		}

		// If we're still here, shipping applies to this order
		$GLOBALS['HideShoppingCartShippingEstimator'] = '';

		$selectedCountry = GetCountryIdByName(GetConfig('CompanyCountry'));
		$selectedState = 0;
		$selectedStateName = '';

		// Retain the country, stae and zip code selections if we have them
		$shippingAddress = $this->quote->getShippingAddress(0);
		if($shippingAddress->getCountryId()) {
			$selectedCountry = $shippingAddress->getCountryId();
			$selectedState = $shippingAddress->getStateId();
			$GLOBALS['ShippingZip'] = $shippingAddress->getZip();
		}

		$GLOBALS['ShippingCountryList'] = GetCountryList($selectedCountry);
		$GLOBALS['ShippingStateList'] = GetStateListAsOptions($selectedCountry, $selectedState);
		$GLOBALS['ShippingStateName'] = isc_html_escape($selectedStateName);

		// If there are no states for the country then hide the dropdown and show the textbox instead
		if (GetNumStatesInCountry($selectedCountry) == 0) {
			$GLOBALS['ShippingHideStateList'] = "none";
		}
		else {
			$GLOBALS['ShippingHideStateBox'] = "none";
		}

		// Show the stored shipping estimate if we have one
		if($shippingAddress->hasShippingMethod()) {
			$GLOBALS['HideShoppingCartShippingCost'] = '';
			$cost = $shippingAddress->getNonDiscountedShippingCost($this->displayIncludingTax);

			if($cost == 0) {
				$GLOBALS['ShippingCost'] = getLang('Free');
			}
			else {
				$GLOBALS['ShippingCost'] = currencyConvertFormatPrice($cost);
			}

			$GLOBALS['ShippingProvider'] = isc_html_escape($shippingAddress->getShippingProvider());
		}
	}
예제 #4
0
 /**
  * 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();
 }
예제 #5
0
 /**
  * Display a list of states for a given country
  *
  * @return void
  **/
 private function GetCountryStates()
 {
     $country = $_REQUEST['c'];
     if (IsId($country)) {
         $countryId = $country;
     } else {
         $countryId = GetCountryIdByName($country);
     }
     if (isset($_REQUEST['s']) && GetStateByName($_REQUEST['s'], $countryId)) {
         $state = $_REQUEST['s'];
     } else {
         $state = '';
     }
     if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'options') {
         echo GetStateListAsOptions($country, $state, false, '', '', false, true);
     } else {
         echo GetStateList((int) $country);
     }
 }
예제 #6
0
		/**
		* Sets the origin location of the shipping module to the location of the vendor
		*
		* @param int The vendor ID to load the location details for
		*/
		public function SetOriginByVendorId($vendorId)
		{
			if ($vendorId) {
				$query = "SELECT * FROM [|PREFIX|]vendors WHERE vendorid = '" . (int)$vendorId . "'";
				$vendorResult = $GLOBALS['ISC_CLASS_DB']->Query($query);
				if ($vendorData = $GLOBALS['ISC_CLASS_DB']->Fetch($vendorResult)) {
					$this->SetOriginCountry(GetCountryIdByName($vendorData['vendorcountry']));
					$this->SetOriginState($vendorData['vendorstate']);
					$this->SetOriginZip($vendorData['vendorzip']);
					$this->SetOriginCity($vendorData['vendorcity']);
				}
			}
		}
예제 #7
0
	/**
	 * Get the country ID
	 *
	 * Method will return the country ID if found
	 *
	 * @access protected
	 * @param string $countryName The country name / ISO3 name / ISO2 name
	 * @param string $properCountryName The referenced variable to set the proper country name if the record exists
	 * @return int The country ID on success, FALSE if not found
	 */
	protected function getCountryId($countryName, &$properCountryName=null)
	{
		if (trim($countryName) == '') {
			return false;
		}

		if (strlen($countryName) == 2) {
			$countryId = GetCountryIdByISO2($countryName);
		} else if (strlen($countryName) == 3) {
			$countryId = GetCountryIdByISO3($countryName);
		} else {
			$countryId = GetCountryIdByName($countryName);
		}

		if (!$countryId || trim($countryId) == '') {
			return false;
		}

		$properCountryName = GetCountryById($countryId);

		return (int)$countryId;
	}
예제 #8
0
/**
 *	Get a list of states as <option> tags
 */
function GetStateListAsOptions($country, $selectedState = 0, $IncludeFirst = true, $FirstText = "ChooseAState", $FirstValue = "0", $FirstSelected = false, $useNamesAsValues = false)
{
    if (!is_numeric($country)) {
        $country = GetCountryIdByName($country);
    }
    $list = "";
    $query = sprintf("select stateid, statename from [|PREFIX|]country_states where statecountry='%d' order by statename asc", $GLOBALS['ISC_CLASS_DB']->Quote($country));
    $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
    // Should we add a blank option?
    if ($IncludeFirst) {
        if ($FirstSelected) {
            $sel = 'selected="selected"';
        } else {
            $sel = "";
        }
        $list = sprintf("<option %s value='%s'>%s</option>", $sel, $FirstValue, GetLang($FirstText));
    }
    while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
        if (is_numeric($selectedState)) {
            // Match $selectedState by country id
            if ($row['stateid'] == $selectedState) {
                $sel = 'selected="selected"';
            } else {
                $sel = "";
            }
        } else {
            if (is_array($selectedState)) {
                // A list has been passed in
                if (in_array($row['stateid'], $selectedState) || in_array($row['statename'], $selectedState)) {
                    $sel = 'selected="selected"';
                } else {
                    $sel = "";
                }
            } else {
                // Just one state has been passed in
                if (strtolower($row['statename']) == strtolower($selectedState)) {
                    $sel = 'selected="selected"';
                } else {
                    $sel = "";
                }
            }
        }
        if ($useNamesAsValues) {
            $value = isc_html_escape($row['statename']);
        } else {
            $value = $row['stateid'];
        }
        $list .= sprintf("<option value='%s' %s>%s</option>", $value, $sel, $row['statename']);
    }
    return $list;
}
 /**
  * Calculate the shipping for an order that's being edited/created.
  */
 private function OrderCalculateShipping()
 {
     if (!isset($_REQUEST['orderSession'])) {
         exit;
     }
     $orderClass = GetClass('ISC_ADMIN_ORDERS');
     $orderClass->GetCartApi($_REQUEST['orderSession']);
     $cartProducts = $orderClass->GetCartApi()->GetProductsInCart();
     $cartClass = GetClass('ISC_CART');
     $address = array('shipzip' => @$_REQUEST['ordshipzip'], 'shipstate' => @$_REQUEST['ordshipstate'], 'shipcountry' => @$_REQUEST['ordshipcountry'], 'shipcountryid' => GetCountryIdByName(@$_REQUEST['ordshipcountry']));
     $address['shipstateid'] = GetStateByName($address['shipstate'], $address['shipcountryid']);
     $shippingMethods = $cartClass->GetAvailableShippingMethodsForProducts($address, $cartProducts, $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId());
     $orderClass->GetCartApi()->Set('SHIPPING_QUOTES', $shippingMethods);
     $existingShippingMethod = $orderClass->GetCartApi()->Get('SHIPPING_METHOD');
     $GLOBALS['ShippingMethods'] = '';
     foreach ($shippingMethods as $quoteId => $quote) {
         $checked = '';
         if (is_array($existingShippingMethod) && $quote['description'] == $existingShippingMethod['methodName']) {
             $hasChecked = true;
             $checked = 'checked="checked"';
         }
         $GLOBALS['MethodChecked'] = $checked;
         $GLOBALS['MethodName'] = isc_html_escape($quote['description']);
         $GLOBALS['MethodCost'] = FormatPrice($quote['price']);
         $GLOBALS['MethodId'] = $quoteId;
         $GLOBALS['ShippingMethods'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderShippingMethodChoice');
     }
     $GLOBALS['HideNoShipingMethods'] = 'display: none';
     if (!empty($shippingMethods)) {
         $GLOBALS['HideNoShippingMethods'] = '';
     }
     $existingOrder = $orderClass->GetCartApi()->Get('EXISTING_ORDER');
     $order = GetOrder($existingOrder);
     if ($existingOrder !== false && $order['ordshipmethod']) {
         $checked = '';
         if (!isset($hasChecked) && (!is_array($existingShippingMethod) || $order['ordshipmethod'] == $existingShippingMethod['methodName'])) {
             $checked = 'checked="checked"';
         }
         $GLOBALS['MethodChecked'] = $checked;
         $GLOBALS['MethodName'] = sprintf(GetLang('ExistingShippingMethod'), isc_html_escape($order['ordshipmethod']));
         $GLOBALS['MethodCost'] = FormatPrice($order['ordshipcost']);
         $GLOBALS['MethodId'] = 'existing';
         $GLOBALS['ShippingMethods'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderShippingMethodChoice') . $GLOBALS['ShippingMethods'];
     }
     $GLOBALS['CustomChecked'] = '';
     $GLOBALS['HideCustom'] = 'display: none';
     if (is_array($existingShippingMethod) && $existingShippingMethod['methodModule'] == 'custom') {
         $GLOBALS['CustomChecked'] = 'checked="checked"';
         $GLOBALS['CustomName'] = isc_html_escape($existingShippingMethod['methodName']);
         $GLOBALS['CustomPrice'] = FormatPrice($existingShippingMethod['methodCost'], false, false);
         $GLOBALS['HideCustom'] = '';
     }
     /* The below patch is added to check the custom shipping if no other shipping method exist - vikas - starts */
     if ($GLOBALS['ShippingMethods'] == "") {
         $GLOBALS['CustomChecked'] = 'checked="checked"';
         $GLOBALS['HideCustom'] = '';
     }
     // below custom name has been added as client told to make it readonly.
     if (!isset($GLOBALS['CustomName'])) {
         $GLOBALS['CustomName'] = "Custom";
     }
     /* - ends -*/
     echo $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderShippingMethodWindow');
     exit;
 }
예제 #10
0
	/**
	 * 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');
	}
예제 #11
0
	/**
	* 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');
	}
예제 #12
0
 public function SetupPreCheckoutShipping()
 {
     $subtotal = $GLOBALS['CartSubTotal'];
     $_SESSION['CHECKOUT']['SUBTOTAL_COST'] = $GLOBALS['CartSubTotal'];
     // Hide everything by default
     $GLOBALS['HideCartFreeShippingPanel'] = 'none';
     $GLOBALS['HideCartDiscountRulePanel'] = 'none';
     $GLOBALS['HideShoppingCartShippingCost'] = 'none';
     $GLOBALS['HideShoppingCartHandlingCost'] = 'none';
     $GLOBALS['HideShoppingCartShippingEstimator'] = 'display: none';
     $GLOBALS['HideShoppingCartImmediateDownload'] = 'none';
     // All products in the cart are digital downloads so the shipping doesn't apply
     if ($this->api->AllProductsInCartAreIntangible()) {
         // Show the 'immediate download' text
         $GLOBALS['HideShoppingCartImmediateDownload'] = '';
         // If we have a handling fee set up for digital orders then we need to show it too
         if (GetConfig('DigitalOrderHandlingFee') > 0) {
             $_SESSION['CHECKOUT']['HANDLING_COST'] = GetConfig('DigitalOrderHandlingFee');
             $GLOBALS['HandlingCost'] = CurrencyConvertFormatPrice(GetConfig('DigitalOrderHandlingFee'));
             $GLOBALS['CartSubTotal'] += GetConfig('DigitalOrderHandlingFee');
             $GLOBALS['HideShoppingCartHandlingCost'] = '';
         }
         return;
     }
     $freeShippingQualified = false;
     $cartProducts = $this->api->GetProductsInCart();
     $freeShippingProductCount = 0;
     foreach ($cartProducts as $product) {
         if ($product['data']['prodtype'] == PT_PHYSICAL && $product['data']['prodfreeshipping'] == 1) {
             ++$freeShippingProductCount;
         }
     }
     $discountMessages = $this->api->Get('DISCOUNT_MESSAGES');
     if (!is_array($discountMessages)) {
         $discountMessages = array();
     }
     $GLOBALS['CartRuleMessage'] = '';
     foreach ($discountMessages as $message) {
         $GLOBALS['CartRuleMessage'] .= '<p class="InfoMessage">' . GetLang('DiscountCongratulations') . ' ';
         $GLOBALS['CartRuleMessage'] .= $message;
         $GLOBALS['CartRuleMessage'] .= '</p>';
     }
     // If all of the products in the cart have free shipping, then we automatically qualify
     if ($freeShippingProductCount == count($cartProducts) || $this->api->GetCartFreeShipping()) {
         $GLOBALS['ShippingCost'] = GetLang('Free');
         $freeShippingQualified = true;
         $GLOBALS['HideCartFreeShippingPanel'] = "";
         $GLOBALS['FreeShippingMessage'] = GetLang('OrderQualifiesForFreeShipping');
         return;
     }
     // Show the estimation box
     $GLOBALS['HideShoppingCartShippingEstimator'] = '';
     // If we have a shipping zone already stored, we can show a little more
     if (isset($_SESSION['OFFERCART']['SHIPPING']['ZONE'])) {
         $zone = GetShippingZoneById($_SESSION['OFFERCART']['SHIPPING']['ZONE']);
         // The zone no longer exists
         if (!isset($zone['zoneid'])) {
             unset($_SESSION['OFFERCART']['SHIPPING']);
             return;
         }
         // If the contents of the cart have changed since their last known values (based off a unique hash of the cart contents)
         // then invalidate the shipping costs
         if (isset($_SESSION['OFFERCART']['SHIPPING']['CART_HASH']) && $this->api->GenerateCartHash() != $_SESSION['OFFERCART']['SHIPPING']['CART_HASH']) {
             // Remove any existing shipping costs
             $this->InvalidateCartShippingCosts();
         }
         // If we have a shipping cost saved, store it too
         if (isset($_SESSION['OFFERCART']['SHIPPING']['SHIPPING_COST'])) {
             $GLOBALS['HideShoppingCartShippingCost'] = '';
             if ($_SESSION['OFFERCART']['SHIPPING']['SHIPPING_COST'] == 0) {
                 $GLOBALS['ShippingCost'] = GetLang('Free');
             } else {
                 $GLOBALS['ShippingCost'] = CurrencyConvertFormatPrice($_SESSION['OFFERCART']['SHIPPING']['SHIPPING_COST']);
                 $subtotal += $_SESSION['OFFERCART']['SHIPPING']['SHIPPING_COST'];
                 $GLOBALS['ShippingProvider'] = isc_html_escape($_SESSION['OFFERCART']['SHIPPING']['SHIPPING_PROVIDER']);
             }
         }
         // If there is a handling fee, we need to show it too
         if (isset($_SESSION['OFFERCART']['SHIPPING']['HANDLING_FEE']) && $_SESSION['OFFERCART']['SHIPPING']['HANDLING_FEE'] > 0) {
             $GLOBALS['HideShoppingCartHandlingCost'] = '';
             $GLOBALS['HandlingCost'] = CurrencyConvertFormatPrice($_SESSION['OFFERCART']['SHIPPING']['HANDLING_FEE']);
             $subtotal += $_SESSION['OFFERCART']['SHIPPING']['HANDLING_FEE'];
         }
         // This zone has free shipping set up. Do we qualify?
         if ($zone['zonefreeshipping'] == 1) {
             $GLOBALS['HideCartFreeShippingPanel'] = "";
             // We don't have enough to qualify - but still show the "spend x more for free shipping" message
             if ($GLOBALS['CartSubTotal'] < $zone['zonefreeshippingtotal']) {
                 $diff = CurrencyConvertFormatPrice($zone['zonefreeshippingtotal'] - $GLOBALS['CartSubTotal']);
                 if ($zone['zonehandlingfee'] > 0 && !$zone['zonehandlingseparate']) {
                     $GLOBALS['FreeShippingMessage'] = sprintf(GetLang('SpendXMoreXShipping'), $diff, CurrencyConvertFormatPrice($zone['zonehandlingfee']));
                 } else {
                     $GLOBALS['FreeShippingMessage'] = sprintf(GetLang('SpendXMoreFreeShipping'), $diff);
                 }
             } else {
                 // Setup the shipping message - if a handling fee is to be applied, then they actually qualify for $X shipping, not free shipping
                 if ($zone['zonehandlingfee'] > 0 && !$zone['zonehandlingseparate']) {
                     $GLOBALS['FreeShippingMessage'] = sprintf(GetLang('OrderQualifiesForXShipping'), CurrencyConvertFormatPrice($zone['zonehandlingfee']));
                 } else {
                     $GLOBALS['FreeShippingMessage'] = GetLang('OrderQualifiesForFreeShipping');
                 }
             }
         }
     }
     $selectedCountry = GetCountryIdByName(GetConfig('CompanyCountry'));
     $selectedState = 0;
     $selectedStateName = '';
     $zipCode = '';
     // Retain the country, stae and zip code selections if we have them
     if (isset($_SESSION['OFFERCART']['SHIPPING']['COUNTRY_ID'])) {
         $selectedCountry = (int) $_SESSION['OFFERCART']['SHIPPING']['COUNTRY_ID'];
         if (isset($_SESSION['OFFERCART']['SHIPPING']['STATE_ID'])) {
             $selectedState = (int) $_SESSION['OFFERCART']['SHIPPING']['STATE_ID'];
         }
         if (isset($_SESSION['OFFERCART']['SHIPPING']['STATE'])) {
             $selectedStateName = $_SESSION['OFFERCART']['SHIPPING']['STATE'];
         }
         if (isset($_SESSION['OFFERCART']['SHIPPING']['ZIP_CODE'])) {
             $GLOBALS['ShippingZip'] = isc_html_escape($_SESSION['OFFERCART']['SHIPPING']['ZIP_CODE']);
         }
     }
     $GLOBALS['ShippingCountryList'] = GetCountryList($selectedCountry);
     $GLOBALS['ShippingStateList'] = GetStateListAsOptions($selectedCountry, $selectedState);
     $GLOBALS['ShippingStateName'] = isc_html_escape($selectedStateName);
     // If there are no states for the country then hide the dropdown and show the textbox instead
     if (GetNumStatesInCountry($selectedCountry) == 0) {
         $GLOBALS['ShippingHideStateList'] = "none";
     } else {
         $GLOBALS['ShippingHideStateBox'] = "none";
     }
     //			if (isset($_SESSION['the_offered_price']))
     //			{
     //				$GLOBALS['CartSubTotal'] = $_SESSION['the_offered_price'];
     //			}
     //			else
     //			{
     $GLOBALS['CartSubTotal'] = $subtotal;
     //			}
 }
예제 #13
0
 /**
  * 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');
 }