Ejemplo n.º 1
0
 private function _getDefaultFieldsContent()
 {
     global $cookie;
     $countryList = array();
     $countryList[] = array('id' => '0', 'name' => $this->l('Choose your country'));
     foreach (Country::getCountries(intval($cookie->id_lang)) as $country) {
         $countryList[] = array('id' => $country['id_country'], 'name' => $country['name']);
     }
     $stateList = array();
     $stateList[] = array('id' => '0', 'name' => $this->l('Choose your state (if applicable)'));
     foreach (State::getStates(intval($cookie->id_lang)) as $state) {
         $stateList[] = array('id' => $state['id_state'], 'name' => $state['name']);
     }
     $formFields = array('PS_SHOP_NAME' => array('title' => $this->l('Shop name:'), 'desc' => $this->l('Displayed in e-mails and page titles'), 'validation' => 'isGenericName', 'required' => true, 'size' => 30, 'type' => 'text'), 'PS_SHOP_EMAIL' => array('title' => $this->l('Shop e-mail:'), 'desc' => $this->l('Displayed in e-mails sent to customers'), 'validation' => 'isEmail', 'required' => true, 'size' => 30, 'type' => 'text'), 'PS_SHOP_DETAILS' => array('title' => $this->l('Registration:'), 'desc' => $this->l('Shop registration information (e.g., SIRET or RCS)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'textarea', 'cols' => 30, 'rows' => 5), 'PS_SHOP_ADDR1' => array('title' => $this->l('Shop address line 1:'), 'validation' => 'isAddress', 'size' => 30, 'type' => 'text'), 'PS_SHOP_ADDR2' => array('title' => $this->l('Address line 2'), 'validation' => 'isAddress', 'size' => 30, 'type' => 'text'), 'PS_SHOP_CODE' => array('title' => $this->l('Post/Zip code:'), 'validation' => 'isGenericName', 'size' => 6, 'type' => 'text'), 'PS_SHOP_CITY' => array('title' => $this->l('City:'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text'), 'PS_SHOP_COUNTRY_ID' => array('title' => $this->l('Country:'), 'validation' => 'isInt', 'size' => 30, 'type' => 'select', 'list' => $countryList, 'identifier' => 'id', 'cast' => 'intval'), 'PS_SHOP_STATE_ID' => array('title' => $this->l('State:'), 'validation' => 'isInt', 'size' => 30, 'type' => 'select', 'list' => $stateList, 'identifier' => 'id', 'cast' => 'intval'), 'PS_SHOP_PHONE' => array('title' => $this->l('Phone:'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text'), 'PS_SHOP_FAX' => array('title' => $this->l('Fax:'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text'));
     return $formFields;
 }
Ejemplo n.º 2
0
    public function displayForm($isMainTab = true)
    {
        global $currentIndex, $cookie;
        parent::displayForm();
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        $zones = Zone::getZones(true);
        $states = State::getStates((int) $cookie->id_lang);
        echo '
		<form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" method="post">
		' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '') . '
			<fieldset><legend><img src="../img/admin/dollar.gif" />' . $this->l('Taxes') . '</legend>
				<label>' . $this->l('Name:') . ' </label>
				<div class="margin-form">';
        foreach ($this->_languages as $language) {
            echo '
					<div id="name_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;">
						<input size="33" type="text" name="name_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'name', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /><sup> *</sup>
						<span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
					</div>';
        }
        $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'name', 'name');
        echo '	<p class="clear">' . $this->l('Tax name to display in cart and on invoice, e.g., VAT') . '</p>
				</div>
				<label>' . $this->l('Rate:') . ' </label>
				<div class="margin-form">
					<input type="text" size="4" maxlength="6" name="rate" value="' . htmlentities($this->getFieldValue($obj, 'rate'), ENT_COMPAT, 'UTF-8') . '" /> <sup>*</sup>
					<p class="clear">' . $this->l('Format: XX.XX or XX.XXX (e.g., 19.60 or 13.925)') . '</p>
				</div>
				<label>' . $this->l('Enable:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" /></label>
					<input type="radio" name="active" id="active_off" value="0" ' . (!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" /></label>
				</div>
				<div class="margin-form">
					<input type="submit" value="' . $this->l('   Save   ') . '" name="submitAdd' . $this->table . '" class="button" />
				</div>
				<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div>
			</fieldset>
		</form>';
    }
Ejemplo n.º 3
0
    public function __construct()
    {
        global $cookie;
        $this->table = 'address';
        $this->className = 'Address';
        $this->lang = false;
        $this->edit = true;
        $this->delete = true;
        $this->addressType = 'customer';
        if (!Tools::getValue('realedit')) {
            $this->deleted = true;
        }
        $this->_select = 'cl.`name` as country';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON 
		(cl.`id_country` = a.`id_country` AND cl.`id_lang` = ' . intval($cookie->id_lang) . ')';
        $countries = Country::getCountries(intval($cookie->id_lang));
        foreach ($countries as $country) {
            $this->countriesArray[$country['id_country']] = $country['name'];
        }
        $this->stateList = State::getStates(intval($cookie->id_lang));
        $this->fieldsDisplay = array('id_address' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'firstname' => array('title' => $this->l('First name'), 'width' => 80, 'filter_key' => 'a!firstname'), 'lastname' => array('title' => $this->l('Last name'), 'width' => 100, 'filter_key' => 'a!lastname'), 'address1' => array('title' => $this->l('Address'), 'width' => 200), 'postcode' => array('title' => $this->l('Post/Zip code'), 'align' => 'right', 'width' => 50), 'city' => array('title' => $this->l('City'), 'width' => 150), 'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'select' => $this->countriesArray, 'filter_key' => 'cl!id_country'));
        parent::__construct();
    }
Ejemplo n.º 4
0
 protected function _getDefaultFieldsContent()
 {
     $this->context = Context::getContext();
     $countryList = array();
     $countryList[] = array('id' => '0', 'name' => $this->l('Choose your country'));
     foreach (Country::getCountries($this->context->language->id) as $country) {
         $countryList[] = array('id' => $country['id_country'], 'name' => $country['name']);
     }
     $stateList = array();
     $stateList[] = array('id' => '0', 'name' => $this->l('Choose your state (if applicable)'));
     foreach (State::getStates($this->context->language->id) as $state) {
         $stateList[] = array('id' => $state['id_state'], 'name' => $state['name']);
     }
     $formFields = array('PS_SHOP_NAME' => array('title' => $this->l('Shop name'), 'hint' => $this->l('Displayed in emails and page titles.'), 'validation' => 'isGenericName', 'required' => true, 'type' => 'text', 'no_escape' => true), 'PS_SHOP_EMAIL' => array('title' => $this->l('Shop email'), 'hint' => $this->l('Displayed in emails sent to customers.'), 'validation' => 'isEmail', 'required' => true, 'type' => 'text'), 'PS_SHOP_DETAILS' => array('title' => $this->l('Registration number'), 'hint' => $this->l('Shop registration information (e.g. SIRET or RCS).'), 'validation' => 'isGenericName', 'type' => 'textarea', 'cols' => 30, 'rows' => 5), 'PS_SHOP_ADDR1' => array('title' => $this->l('Shop address line 1'), 'validation' => 'isAddress', 'type' => 'text'), 'PS_SHOP_ADDR2' => array('title' => $this->l('Shop address line 2'), 'validation' => 'isAddress', 'type' => 'text'), 'PS_SHOP_CODE' => array('title' => $this->l('Zip/postal code'), 'validation' => 'isGenericName', 'type' => 'text'), 'PS_SHOP_CITY' => array('title' => $this->l('City'), 'validation' => 'isGenericName', 'type' => 'text'), 'PS_SHOP_COUNTRY_ID' => array('title' => $this->l('Country'), 'validation' => 'isInt', 'type' => 'select', 'list' => $countryList, 'identifier' => 'id', 'cast' => 'intval', 'defaultValue' => (int) $this->context->country->id), 'PS_SHOP_STATE_ID' => array('title' => $this->l('State'), 'validation' => 'isInt', 'type' => 'select', 'list' => $stateList, 'identifier' => 'id', 'cast' => 'intval'), 'PS_SHOP_PHONE' => array('title' => $this->l('Phone'), 'validation' => 'isGenericName', 'type' => 'text'), 'PS_SHOP_FAX' => array('title' => $this->l('Fax'), 'validation' => 'isGenericName', 'type' => 'text'));
     return $formFields;
 }
 protected function generateStateData()
 {
     $delimiter = ';';
     $line = array();
     $titles = array();
     $id_lang = $this->use_lang;
     $new_path = new Sampledatainstall();
     $f = fopen($new_path->sendPath() . 'output/states.vsc', 'w');
     foreach ($this->states_fields as $field => $array) {
         $titles[] = $array['label'];
     }
     fputcsv($f, $titles, $delimiter, '"');
     $states = State::getStates($id_lang);
     if ($states) {
         foreach ($states as $state) {
             foreach ($this->states_fields as $field => $array) {
                 $line[$field] = !Tools::isEmpty($state[$field]) ? $state[$field] : '';
             }
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
     }
     fclose($f);
 }
Ejemplo n.º 6
0
 /**
  * @param int    $addressId
  * @param string $addressType
  *
  * @return ShopgateAddress
  */
 protected function _getAddress($addressId, $addressType)
 {
     $addressItem = new ShopgateAddress();
     /** @var AddressCore $addressCore */
     $addressCore = new Address($addressId);
     $addressItem->setId($addressCore->id);
     switch ($addressType) {
         case ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY:
             $addressItem->setIsDeliveryAddress(true);
             break;
         case ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_INVOICE:
             $addressItem->setIsInvoiceAddress(true);
             break;
     }
     $addressItem->setFirstName($addressCore->firstname);
     $addressItem->setLastName($addressCore->lastname);
     $addressItem->setCompany($addressCore->company);
     $addressItem->setStreet1($addressCore->address1);
     $addressItem->setStreet2($addressCore->address2);
     $addressItem->setZipcode($addressCore->postcode);
     $addressItem->setCity($addressCore->city);
     $addressItem->setCountry(Country::getIsoById($addressCore->id_country));
     $states = State::getStates($this->getPlugin()->getLanguageId());
     foreach ($states as $state) {
         /** @var StateCore $state */
         if ($state['id_country'] == $addressCore->id_state) {
             $addressItem->setState($state->iso_code);
         }
     }
     return $addressItem;
 }
Ejemplo n.º 7
0
 public function getPreviewAddress($log = false)
 {
     // for compatibility
     /** NO LONGER NECESSARY */
     /*
     if($this->name == 'localizedshipping')
     	$name = 'shp';
     else
     */
     $name = $this->name;
     if ($this->context->cookie->postcode && $this->context->cookie->id_country && $this->context->cookie->id_state) {
         $cookie_state = $this->context->cookie->id_state;
     } else {
         $cookie_state = $this->context->cookie->pc_dest_state;
     }
     $cookie_zip = $this->context->cookie->postcode ? $this->context->cookie->postcode : $this->context->cookie->pc_dest_zip;
     $cookie_country = $this->context->cookie->id_country ? $this->context->cookie->id_country : $this->context->cookie->pc_dest_country;
     if ($this->context->customer->logged) {
         if (isset($_POST[$name . '_dest_zip']) && $_POST[$name . '_dest_zip'] != "" || isset($_POST[$name . '_dest_country']) && $_POST[$name . '_dest_country'] != "" || isset($_POST[$name . '_dest_state']) && $_POST[$name . '_dest_state'] != "") {
             $dest_zip = Tools::getValue($name . '_dest_zip');
             $dest_state = Tools::getValue($name . '_dest_state');
             $dest_country = Tools::getValue($name . '_dest_country');
             $dest_city = Tools::getValue($name . '_dest_city') != $this->l('City') ? Tools::getValue($name . '_dest_city') : "";
             if ((int) $this->context->cart->id_address_delivery > 0) {
                 $address = new Address(intval($this->context->cart->id_address_delivery));
                 $address->postcode = $dest_zip;
                 $address->id_country = $dest_country;
                 $address->city = ($dest_city and strlen($dest_city)) ? $dest_city : 0;
                 if ((int) $dest_state > 0) {
                     $address->id_state = $dest_state;
                 }
                 $country = new Country($dest_country);
                 if (!$address->id_state && $country->contains_states) {
                     $id_state = 0;
                     $states = State::getStates($this->context->language->id, true);
                     foreach ($states as $state) {
                         $id_state = $state['id_state'];
                     }
                     $address->id_state = $id_state;
                 } else {
                     if ($address->id_state && !$country->contains_states) {
                         $address->id_state = 0;
                     }
                 }
                 $override_address_name = '_' . $name . '_override_address';
                 if ($this->{$override_address_name}) {
                     $address->update();
                 }
             }
             $state = new State($dest_state);
             $country = new Country($dest_country);
             $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
             $dest_country = $country->iso_code;
         } else {
             if ((int) $this->context->cart->id_address_delivery > 0) {
                 $address = new Address(intval($this->context->cart->id_address_delivery));
                 $dest_zip = $address->postcode;
                 $country = new Country($address->id_country);
                 $dest_country = $country->iso_code;
                 $dest_state = $address->id_state;
                 $dest_city = $address->city;
                 $state = new State($dest_state);
                 $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
             } else {
                 $dest_zip = $cookie_zip;
                 $dest_state = $cookie_state;
                 $dest_country = $cookie_country;
                 $dest_city = $this->context->cookie->pc_dest_city;
                 $country = new Country($dest_country);
                 $state = new State($dest_state);
                 $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
                 $dest_country = $country->iso_code;
             }
         }
     } else {
         /** IF CARRIER IS NOT ROYAL MAIL CARRIER */
         if ($this->name != 'royalmail') {
             if (isset($_POST[$name . '_dest_zip']) && $_POST[$name . '_dest_zip'] || isset($_POST[$name . '_dest_country']) && $_POST[$name . '_dest_country'] || isset($_POST[$name . '_dest_state']) && $_POST[$name . '_dest_state']) {
                 $dest_zip = Tools::getValue($name . '_dest_zip');
                 $dest_state = Tools::getValue($name . '_dest_state');
                 $dest_country = Tools::getValue($name . '_dest_country');
                 $dest_city = isset($_POST[$name . '_dest_city']) && $_POST[$name . '_dest_city'] != $this->l('City') ? $_POST[$name . '_dest_city'] : "";
             } else {
                 $dest_zip = $cookie_zip;
                 $dest_state = $cookie_state;
                 $dest_country = $cookie_country;
                 $dest_city = $this->context->cookie->pc_dest_city;
             }
         } else {
             if (isset($_POST[$name . '_dest_country']) && $_POST[$name . '_dest_country']) {
                 $dest_zip = Tools::getValue($name . '_dest_zip');
                 $dest_state = Tools::getValue($name . '_dest_state');
                 $dest_country = Tools::getValue($name . '_dest_country');
                 $dest_city = isset($_POST[$name . '_dest_city']) && $_POST[$name . '_dest_city'] != $this->l('City') ? $_POST[$name . '_dest_city'] : "";
             } else {
                 $dest_zip = $cookie_zip;
                 $dest_state = $cookie_state;
                 $dest_country = $cookie_country;
                 $dest_city = $this->context->cookie->pc_dest_city;
             }
         }
         $country = new Country($dest_country);
         $state = new State($dest_state);
         $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
         $dest_country = $country->iso_code;
     }
     $this->context->cookie->pc_dest_zip = strlen($dest_zip) ? $dest_zip : $cookie_zip;
     $this->context->cookie->pc_dest_state = strlen($dest_state) ? $dest_state : $cookie_state;
     if (strlen($dest_country)) {
         $id_country = Country::getByIso($dest_country);
         $this->context->cookie->pc_dest_country = $id_country ? $id_country : $cookie_country;
     }
     $this->context->cookie->pc_dest_city = strlen($dest_city) ? $dest_city : $this->context->cookie->pc_dest_city;
     $this->context->cookie->write();
     return array('dest_zip' => $dest_zip, 'dest_state' => $dest_state, 'dest_country' => $dest_country, 'dest_city' => $dest_city, 'id_zone' => $id_zone);
 }
Ejemplo n.º 8
0
 public function renderForm()
 {
     $this->fields_form = array('legend' => array('title' => 'Legend'), 'input' => array(array('type' => 'select', 'label' => $this->l('Country'), 'name' => 'id_country', 'options' => array('query' => Country::getCountries($this->context->language->id, true, true), 'id' => 'id_country', 'name' => 'name'), 'required' => true), array('type' => 'select', 'label' => $this->l('State'), 'name' => 'id_state', 'required' => true, 'options' => array('query' => State::getStates(), 'id' => 'id_state', 'name' => 'name')), array('type' => 'select', 'label' => 'Tariff Zone', 'name' => 'id_post_zone', 'options' => array('query' => array(array('id' => 1, 'value' => 'Zone 1'), array('id' => 2, 'value' => 'Zone 2'), array('id' => 3, 'value' => 'Zone 3'), array('id' => 4, 'value' => 'Zone 4'), array('id' => 5, 'value' => 'Zone 5')), 'id' => 'id', 'name' => 'value'), 'required' => true), array('type' => 'radio', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'class' => 't', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Enable delivery to this Country/State'))), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
     return parent::renderForm();
 }
Ejemplo n.º 9
0
    public function getContent()
    {
        $buffer = '';
        if (Tools::isSubmit('SubmitAvalaraTaxSettings')) {
            Configuration::updateValue('AVALARATAX_ACCOUNT_NUMBER', Tools::getValue('avalaratax_account_number'));
            Configuration::updateValue('AVALARATAX_LICENSE_KEY', Tools::getValue('avalaratax_license_key'));
            Configuration::updateValue('AVALARATAX_URL', Tools::getValue('avalaratax_url'));
            Configuration::updateValue('AVALARATAX_COMPANY_CODE', Tools::getValue('avalaratax_company_code'));
            $buffer .= $this->_displayConfirmation();
        } elseif (Tools::isSubmit('SubmitAvalaraTaxOptions')) {
            Configuration::updateValue('AVALARATAX_ADDRESS_VALIDATION', Tools::getValue('avalaratax_address_validation'));
            Configuration::updateValue('AVALARATAX_TAX_CALCULATION', Tools::getValue('avalaratax_tax_calculation'));
            Configuration::updateValue('AVALARATAX_TIMEOUT', (int) Tools::getValue('avalaratax_timeout'));
            Configuration::updateValue('AVALARATAX_ADDRESS_NORMALIZATION', Tools::getValue('avalaratax_address_normalization'));
            Configuration::updateValue('AVALARATAX_TAX_OUTSIDE', Tools::getValue('avalaratax_tax_outside'));
            Configuration::updateValue('AVALARA_CACHE_MAX_LIMIT', Tools::getValue('avalara_cache_max_limit') < 1 ? 1 : Tools::getValue('avalara_cache_max_limit') > 23 ? 23 : Tools::getValue('avalara_cache_max_limit'));
            $buffer .= $this->_displayConfirmation();
        } elseif (Tools::isSubmit('SubmitAvalaraTestConnection')) {
            $connectionTestResult = $this->_testConnection();
        } elseif (Tools::isSubmit('SubmitAvalaraAddressOptions')) {
            /* Validate address*/
            $address = new Address();
            $address->address1 = Tools::getValue('avalaratax_address_line1');
            $address->address2 = Tools::getValue('avalaratax_address_line2');
            $address->city = Tools::getValue('avalaratax_city');
            $address->id_state = State::getIdByIso(Tools::getValue('avalaratax_state'));
            $address->id_country = Tools::getValue('avalaratax_country');
            $address->postcode = Tools::getValue('avalaratax_zip_code');
            $normalizedAddress = $this->validateAddress($address);
            if (isset($normalizedAddress['ResultCode']) && $normalizedAddress['ResultCode'] == 'Success') {
                $buffer .= $this->_displayConfirmation($this->l('The address you submitted has been validated.'));
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE1', $normalizedAddress['Normalized']['Line1']);
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE2', $normalizedAddress['Normalized']['Line2']);
                Configuration::updateValue('AVALARATAX_CITY', $normalizedAddress['Normalized']['City']);
                Configuration::updateValue('AVALARATAX_STATE', $normalizedAddress['Normalized']['Region']);
                Configuration::updateValue('AVALARATAX_COUNTRY', $normalizedAddress['Normalized']['Country']);
                Configuration::updateValue('AVALARATAX_ZIP_CODE', $normalizedAddress['Normalized']['PostalCode']);
            } else {
                $message = $this->l('The following error was generated while validating your address:');
                if (isset($normalizedAddress['Exception']['FaultString'])) {
                    $message .= '<br /> - ' . Tools::safeOutput($normalizedAddress['Exception']['FaultString']);
                }
                if (isset($normalizedAddress['Messages']['Summary'])) {
                    foreach ($normalizedAddress['Messages']['Summary'] as $summary) {
                        $message .= '<br /> - ' . Tools::safeOutput($summary);
                    }
                }
                $buffer .= $this->_displayConfirmation($message, 'error');
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE1', Tools::getValue('avalaratax_address_line1'));
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE2', Tools::getValue('avalaratax_address_line2'));
                Configuration::updateValue('AVALARATAX_CITY', Tools::getValue('avalaratax_city'));
                Configuration::updateValue('AVALARATAX_STATE', Tools::getValue('avalaratax_state'));
                Configuration::updateValue('AVALARATAX_ZIP_CODE', Tools::getValue('avalaratax_zip_code'));
            }
        } elseif (Tools::isSubmit('SubmitAvalaraTaxClearCache')) {
            Db::getInstance()->Execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'avalara_product_cache`');
            Db::getInstance()->Execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'avalara_carrier_cache`');
            $buffer .= $this->_displayConfirmation('Cache cleared!');
        }
        $confValues = Configuration::getMultiple(array('AVALARATAX_ACCOUNT_NUMBER', 'AVALARATAX_LICENSE_KEY', 'AVALARATAX_URL', 'AVALARATAX_COMPANY_CODE', 'AVALARATAX_ADDRESS_VALIDATION', 'AVALARATAX_TAX_CALCULATION', 'AVALARATAX_TIMEOUT', 'AVALARATAX_ADDRESS_NORMALIZATION', 'AVALARATAX_TAX_OUTSIDE', 'AVALARATAX_COMMIT_ID', 'AVALARATAX_CANCEL_ID', 'AVALARATAX_REFUND_ID', 'AVALARATAX_POST_ID', 'AVALARA_CACHE_MAX_LIMIT', 'AVALARATAX_ADDRESS_LINE1', 'AVALARATAX_ADDRESS_LINE2', 'AVALARATAX_CITY', 'AVALARATAX_STATE', 'AVALARATAX_ZIP_CODE', 'AVALARATAX_COUNTRY'));
        $stateList = array();
        $stateList[] = array('id' => '0', 'name' => $this->l('Choose your state (if applicable)'), 'iso_code' => '--');
        foreach (State::getStates((int) $this->context->cookie->id_lang) as $state) {
            $stateList[] = array('id' => $state['id_state'], 'name' => $state['name'], 'iso_code' => $state['iso_code']);
        }
        $countryList = array();
        $countryList[] = array('id' => '0', 'name' => $this->l('Choose your country'), 'iso_code' => '--');
        foreach (Country::getCountries((int) $this->context->cookie->id_lang, false, null, false) as $country) {
            $countryList[] = array('id' => $country['id_country'], 'name' => $country['name'], 'iso_code' => $country['iso_code']);
        }
        $buffer .= '<style type="text/css">
			fieldset.avalaratax_fieldset td.avalaratax_column { padding: 0 18px; text-align: right; vertical-align: top;}
			fieldset.avalaratax_fieldset input[type=text] { width: 250px; }
			fieldset.avalaratax_fieldset input.avalaratax_button { margin-top: 10px; }
			fieldset.avalaratax_fieldset div#test_connection { margin-left: 18px; border: 1px solid #DFD5C3; padding: 5px; font-size: 11px; margin-bottom: 10px; width: 90%; }
			fieldset.avalaratax_fieldset a { color: #0000CC; font-weight: bold; text-decoration: underline; }
			.avalara-pagination {display: inline-block; float: right; }
			.avalara-pagination ul {list-style: none; display: inline-block; margin: 0; padding: 0;}
			.avalara-pagination ul li {margin-left: 10px; display: inline-block;}
			.clear {clear: both; margin: 0 auto;}
			.current-page {border: 1px solid #000; padding: 3px;}
			.orders-table {border-collapse:collapse;}
			.orders-table tr { vertical-align: top;}
			.orders-table tr td { border-top: 1px solid #000;}
		</style>
		<script type="text/javascript">
			$(function() {
				/* Add video */
				$(\'<div style="left: 567px; top: 11px; position: relative; width: 361px; height: 0px"><iframe width="360" height="215" src="http://www.youtube.com/embed/tm1tENVdcQ8" frameborder="0" allowfullscreen></iframe></div>\').prependTo(\'#content form:eq(0)\');
			});
		</script>

		<h2>' . Tools::safeOutput($this->displayName) . '</h2>
		<div class="hint clear" style="display:block;">
				<a style="float: right;" target="_blank" href="http://www.prestashop.com/en/industry-partners/management/avalara"><img alt="" src="../modules/avalaratax/avalaratax_logo.png"></a>
				<div style="width: 700px; margin: 0 auto; text-align: center"><h3 style="color: red">' . $this->l('This module is intended to work ONLY in United States of America and Canada') . '</h3></div>
				<h3>' . $this->l('How to configure Avalara Tax Module:') . '</h3>
				- ' . $this->l('Fill the Account Number, License Key, and Company Code fields with those provided by Avalara.') . ' <br />
				- ' . $this->l('Specify your origin address. This is FROM where you are shipping the products (It has to be a ') . '<b>' . $this->l('VALID UNITED STATES ADDRESS') . '</b>)<br /><br />
				<h3>' . $this->l('Module goal:') . '</h3>
				' . $this->l('This cloud-based service is the fastest, easiest, most accurate and affordable way to calculate sales and use tax; manage exemption certificates; file returns; and remit payments across North America and beyond.') . '<br /><br />
				<h3>' . $this->l('What modifications does the module do on my store?') . '</h3>
				- ' . $this->l('Tax.php, AddressController.php, and AuthController.php will be overriden.') . '<br />
				- ' . $this->l('[Payment Tab -> Taxes] and [Payment Tab -> Tax Rules] configurations will be overriden for the US.') . '<br />
				- ' . $this->l('On product details (product in edit mode) an optional "Tax Code" field will be added allowing you to specify a valid tax code for each of your products.') . '<br />
		</div>
		<br />
		<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
			<fieldset class="width2 avalaratax_fieldset">
				<legend><img src="../img/admin/cog.gif" alt="" />' . $this->l('Configuration') . '</legend>
				<h3>' . $this->l('AvaTax Credentials') . '</h3>';
        if (isset($connectionTestResult)) {
            $buffer .= '<div id="test_connection" style="background: ' . Tools::safeOutput($connectionTestResult[1]) . ';">' . $connectionTestResult[0] . '</div>';
        }
        $buffer .= '<table border="0" cellspacing="5">
					<tr>
						<td class="avalaratax_column">' . $this->l('Account Number') . '</td>
						<td><input type="text" name="avalaratax_account_number" value="' . (isset($confValues['AVALARATAX_ACCOUNT_NUMBER']) ? Tools::safeOutput($confValues['AVALARATAX_ACCOUNT_NUMBER']) : '') . '" /></td>
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('License Key') . '</td>
						<td><input type="text" name="avalaratax_license_key" value="' . (isset($confValues['AVALARATAX_LICENSE_KEY']) ? Tools::safeOutput($confValues['AVALARATAX_LICENSE_KEY']) : '') . '" /></td>
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('URL') . '</td>
						<td><input type="text" name="avalaratax_url" value="' . (isset($confValues['AVALARATAX_URL']) ? Tools::safeOutput($confValues['AVALARATAX_URL']) : '') . '" /></td>
					</tr>
					<tr>
						<td class="avalaratax_column" style="vertical-align: top; padding-top: 3px;">' . $this->l('Company Code') . '</td>
						<td><input type="text" name="avalaratax_company_code" value="' . (isset($confValues['AVALARATAX_COMPANY_CODE']) ? Tools::safeOutput($confValues['AVALARATAX_COMPANY_CODE']) : '') . '" /><br />
						<span style="color: #7F7F7F; font-size: 10px;">' . $this->l('Located in the top-right corner of your AvaTax Admin Console') . '</span></td>
					</tr>
				</table>
				<center><input type="submit" class="button avalaratax_button" name="SubmitAvalaraTaxSettings" value="' . $this->l('Save Settings') . '" /></center>
				<hr size="1" style="margin: 14px auto;" noshade />
				<center><img src="../img/admin/exchangesrate.gif" alt="" /> <input type="submit" id="avalaratax_test_connection" class="button avalaratax_button" name="SubmitAvalaraTestConnection" value="' . $this->l('Click here to Test Connection') . '" style="margin-top: 0;" /></center>
			</fieldset>
		</form>
		<br />
		<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
			<fieldset class="width2 avalaratax_fieldset">
				<legend><img src="../img/admin/cog.gif" alt="" />' . $this->l('Options') . '</legend>
				<table border="0">
					<tr>
						<td class="avalaratax_column">' . $this->l('Enable address validation') . '</td>
						<td><input type="checkbox" name="avalaratax_address_validation" value="1"' . (isset($confValues['AVALARATAX_ADDRESS_VALIDATION']) && $confValues['AVALARATAX_ADDRESS_VALIDATION'] ? ' checked="checked"' : '') . ' /></td>
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Enable tax calculation') . '</td>
						<td><input type="checkbox" name="avalaratax_tax_calculation" value="1" ' . (isset($confValues['AVALARATAX_TAX_CALCULATION']) && $confValues['AVALARATAX_TAX_CALCULATION'] ? ' checked="checked"' : '') . ' /></td>
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Enable address normalization in uppercase') . '</td>
						<td><input type="checkbox" name="avalaratax_address_normalization" value="1" ' . (isset($confValues['AVALARATAX_ADDRESS_NORMALIZATION']) && $confValues['AVALARATAX_ADDRESS_NORMALIZATION'] ? ' checked="checked"' : '') . ' /></td>
					</tr>
<tr>
						<td class="avalaratax_column">' . $this->l('Enable tax calculation outside of your state') . '</td>
						<td><input type="checkbox" name="avalaratax_tax_outside" value="1" ' . (isset($confValues['AVALARATAX_TAX_OUTSIDE']) && $confValues['AVALARATAX_TAX_OUTSIDE'] ? ' checked="checked"' : '') . ' /></td>
</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Request timeout') . '</td>
						<td><input type="text" name="avalaratax_timeout" value="' . (isset($confValues['AVALARATAX_TIMEOUT']) ? Tools::safeOutput($confValues['AVALARATAX_TIMEOUT']) : '') . '" style="width: 50px;" /> <span style="font-size: 11px;">' . $this->l('seconds') . '</span></td>
					</tr>
					<tr style="display: none;">

						<td class="avalaratax_column">' . $this->l('Refresh tax rate cache every: ') . '</td>
						<td><input type="text" name="avalara_cache_max_limit" value="' . (isset($confValues['AVALARA_CACHE_MAX_LIMIT']) ? Tools::safeOutput($confValues['AVALARA_CACHE_MAX_LIMIT']) : '') . '" style="width: 50px;" /> <span style="font-size: 11px;">' . $this->l('minutes') . '</span></td>
					</tr>

				</table>
				<center><input type="submit" class="button avalaratax_button" name="SubmitAvalaraTaxOptions" value="' . $this->l('Save Settings') . '" />
				<input type="submit" class="button avalaratax_button" name="SubmitAvalaraTaxClearCache" value="' . $this->l('Clear Cache') . '" style="display: none"/>
				</center>
				<h3 style="margin: 10px 0px 0px; padding-top: 3px;border-top: 1px solid #000;">' . $this->l('Default Post/Commit/Cancel/Refund Options') . '</h3>
				<span style="font-style: italic; font-size: 11px; color: #888;">' . $this->l('When an order\'s status is updated, the following options will be used to update Avalara\'s records.') . '</span><br /><br />';
        // Check if the order status exist
        $orderStatusList = array();
        foreach (Db::getInstance()->ExecuteS('SELECT `id_order_state`, `name` FROM `' . _DB_PREFIX_ . 'order_state_lang` WHERE `id_lang` = ' . (int) $this->context->cookie->id_lang) as $v) {
            $orderStatusList[$v['id_order_state']] = Tools::safeOutput($v['name']);
        }
        $buffer .= '<table>
					<th style="text-align: right; padding-right: 65px; border: 1px solid #000;">' . $this->l('Action') . '</th>
					<th style="text-align: left; border: 1px solid #000; padding: 0px 15px;">' . $this->l('Order status in your store') . '</th>
					<tr>
						<td class="avalaratax_column">' . $this->l('Post order to Avalara') . ':</td>
						<td>' . (isset($orderStatusList[Configuration::get('AVALARATAX_POST_ID')]) ? Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_POST_ID')]) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
						</td>
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Commit order to Avalara') . ':</td>
						<td>' . (isset($orderStatusList[Configuration::get('AVALARATAX_COMMIT_ID')]) ? Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_COMMIT_ID')]) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
						</td>
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Delete order from Avalara') . ':</td>
						<td>' . (isset($orderStatusList[Configuration::get('AVALARATAX_CANCEL_ID')]) ? Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_CANCEL_ID')]) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
						</td>
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Void order in Avalara') . ':</td>
						<td>' . (isset($orderStatusList[Configuration::get('AVALARATAX_REFUND_ID')]) ? Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_REFUND_ID')]) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
						</td>
					</tr>
				</table>
				<div class="clear"></div>
			</fieldset>
		</form>
		<br />
		<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
			<fieldset class="width2 avalaratax_fieldset">
				<legend><img src="../img/admin/delivery.gif" alt="" />' . $this->l('Default Origin Address') . '</legend>
				<table border="0">
					<tr>
						<td class="avalaratax_column">' . $this->l('Address Line 1') . '</td>
						<td><input type="text" name="avalaratax_address_line1" value="' . (isset($confValues['AVALARATAX_ADDRESS_LINE1']) ? Tools::safeOutput($confValues['AVALARATAX_ADDRESS_LINE1']) : '') . '" /><br />
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Address Line 2') . '</td>
						<td><input type="text" name="avalaratax_address_line2" value="' . (isset($confValues['AVALARATAX_ADDRESS_LINE2']) ? Tools::safeOutput($confValues['AVALARATAX_ADDRESS_LINE2']) : '') . '" /><br />
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('City') . '</td>
						<td><input type="text" name="avalaratax_city" value="' . (isset($confValues['AVALARATAX_CITY']) ? Tools::safeOutput($confValues['AVALARATAX_CITY']) : '') . '" /><br />
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('State') . '</td>
						<td>
							<select name="avalaratax_state" id="avalaratax_state">';
        foreach ($stateList as $state) {
            $buffer .= '<option value="' . substr(strtoupper($state['iso_code']), 0, 2) . '" ' . ($state['iso_code'] == $confValues['AVALARATAX_STATE'] ? ' selected="selected"' : '') . '>' . Tools::safeOutput($state['name']) . '</option>';
        }
        $buffer .= '</select>
						</td>
						<br />
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Zip Code') . '</td>
						<td><input type="text" name="avalaratax_zip_code" value="' . (isset($confValues['AVALARATAX_ZIP_CODE']) ? Tools::safeOutput($confValues['AVALARATAX_ZIP_CODE']) : '') . '" /><br />
					</tr>
					<tr>
						<td class="avalaratax_column">' . $this->l('Country') . '</td>
						<td>
							<select name="avalaratax_country" id="avalaratax_country">';
        foreach ($countryList as $country) {
            $buffer .= '<option value="' . substr(strtoupper($country['iso_code']), 0, 2) . '" ' . ($country['iso_code'] == $confValues['AVALARATAX_COUNTRY'] ? ' selected="selected"' : '') . '>' . Tools::safeOutput($country['name']) . '</option>';
        }
        return $buffer . '</select>
						</td>
					</tr>
				</table>
				<center><input type="submit" class="button avalaratax_button" name="SubmitAvalaraAddressOptions" value="' . $this->l('Save Settings') . '" /></center>
			</fieldset>
		</form>
		<br />
		<fieldset class="width2 avalaratax_fieldset">
		<legend><img src="../img/admin/statsettings.gif" alt="" />' . $this->l('AvaTax Admin Console') . '</legend>
			<p><a href="https://admin-avatax.avalara.net/" target="_blank">' . $this->l('Log-in to AvaTax Admin Console') . '</a></p>
		</fieldset><br />';
    }
Ejemplo n.º 10
0
    public function getContent()
    {
        $buffer = '';
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $this->context->controller->addJQueryPlugin('fancybox');
        } else {
            $buffer .= '<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/jquery/jquery.fancybox-1.3.4.js"></script>
		  	<link type="text/css" rel="stylesheet" href="' . __PS_BASE_URI__ . 'css/jquery.fancybox-1.3.4.css" />';
        }
        if (Tools::isSubmit('SubmitAvalaraTaxSettings')) {
            Configuration::updateValue('AVALARATAX_ACCOUNT_NUMBER', Tools::getValue('avalaratax_account_number'));
            Configuration::updateValue('AVALARATAX_LICENSE_KEY', Tools::getValue('avalaratax_license_key'));
            Configuration::updateValue('AVALARATAX_URL', Tools::getValue('avalaratax_url'));
            Configuration::updateValue('AVALARATAX_COMPANY_CODE', Tools::getValue('avalaratax_company_code'));
            $buffer .= $this->_displayConfirmation();
        } elseif (Tools::isSubmit('SubmitAvalaraTaxOptions')) {
            Configuration::updateValue('AVALARATAX_ADDRESS_VALIDATION', Tools::getValue('avalaratax_address_validation'));
            Configuration::updateValue('AVALARATAX_TAX_CALCULATION', Tools::getValue('avalaratax_tax_calculation'));
            Configuration::updateValue('AVALARATAX_TIMEOUT', (int) Tools::getValue('avalaratax_timeout'));
            Configuration::updateValue('AVALARATAX_ADDRESS_NORMALIZATION', Tools::getValue('avalaratax_address_normalization'));
            Configuration::updateValue('AVALARATAX_TAX_OUTSIDE', Tools::getValue('avalaratax_tax_outside'));
            Configuration::updateValue('AVALARA_CACHE_MAX_LIMIT', Tools::getValue('avalara_cache_max_limit') < 1 ? 1 : Tools::getValue('avalara_cache_max_limit') > 23 ? 23 : Tools::getValue('avalara_cache_max_limit'));
            $buffer .= $this->_displayConfirmation();
        } elseif (Tools::isSubmit('SubmitAvalaraTestConnection')) {
            $connectionTestResult = $this->_testConnection();
        } elseif (Tools::isSubmit('SubmitAvalaraAddressOptions')) {
            /* Validate address*/
            $address = new Address();
            $address->address1 = Tools::getValue('avalaratax_address_line1');
            $address->address2 = Tools::getValue('avalaratax_address_line2');
            $address->city = Tools::getValue('avalaratax_city');
            $address->id_state = State::getIdByIso(Tools::getValue('avalaratax_state'));
            $address->id_country = Tools::getValue('avalaratax_country');
            $address->postcode = Tools::getValue('avalaratax_zip_code');
            $normalizedAddress = $this->validateAddress($address);
            if (isset($normalizedAddress['ResultCode']) && $normalizedAddress['ResultCode'] == 'Success') {
                $buffer .= $this->_displayConfirmation($this->l('The address you submitted has been validated.'));
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE1', $normalizedAddress['Normalized']['Line1']);
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE2', $normalizedAddress['Normalized']['Line2']);
                Configuration::updateValue('AVALARATAX_CITY', $normalizedAddress['Normalized']['City']);
                Configuration::updateValue('AVALARATAX_STATE', $normalizedAddress['Normalized']['Region']);
                Configuration::updateValue('AVALARATAX_COUNTRY', $normalizedAddress['Normalized']['Country']);
                Configuration::updateValue('AVALARATAX_ZIP_CODE', $normalizedAddress['Normalized']['PostalCode']);
            } else {
                $message = $this->l('The following error was generated while validating your address:');
                if (isset($normalizedAddress['Exception']['FaultString'])) {
                    $message .= '<br /> - ' . Tools::safeOutput($normalizedAddress['Exception']['FaultString']);
                }
                if (isset($normalizedAddress['Messages']['Summary'])) {
                    foreach ($normalizedAddress['Messages']['Summary'] as $summary) {
                        $message .= '<br /> - ' . Tools::safeOutput($summary);
                    }
                }
                $buffer .= $this->_displayConfirmation($message, 'error');
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE1', Tools::getValue('avalaratax_address_line1'));
                Configuration::updateValue('AVALARATAX_ADDRESS_LINE2', Tools::getValue('avalaratax_address_line2'));
                Configuration::updateValue('AVALARATAX_CITY', Tools::getValue('avalaratax_city'));
                Configuration::updateValue('AVALARATAX_STATE', Tools::getValue('avalaratax_state'));
                Configuration::updateValue('AVALARATAX_ZIP_CODE', Tools::getValue('avalaratax_zip_code'));
            }
        } elseif (Tools::isSubmit('SubmitAvalaraTaxClearCache')) {
            Db::getInstance()->Execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'avalara_product_cache`');
            Db::getInstance()->Execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'avalara_carrier_cache`');
            $buffer .= $this->_displayConfirmation('Cache cleared!');
        }
        $confValues = Configuration::getMultiple(array('AVALARATAX_ACCOUNT_NUMBER', 'AVALARATAX_LICENSE_KEY', 'AVALARATAX_URL', 'AVALARATAX_COMPANY_CODE', 'AVALARATAX_ADDRESS_VALIDATION', 'AVALARATAX_TAX_CALCULATION', 'AVALARATAX_TIMEOUT', 'AVALARATAX_ADDRESS_NORMALIZATION', 'AVALARATAX_TAX_OUTSIDE', 'AVALARATAX_COMMIT_ID', 'AVALARATAX_CANCEL_ID', 'AVALARATAX_REFUND_ID', 'AVALARATAX_POST_ID', 'AVALARA_CACHE_MAX_LIMIT', 'AVALARATAX_ADDRESS_LINE1', 'AVALARATAX_ADDRESS_LINE2', 'AVALARATAX_CITY', 'AVALARATAX_STATE', 'AVALARATAX_ZIP_CODE', 'AVALARATAX_COUNTRY'));
        $stateList = array();
        $stateList[] = array('id' => '0', 'name' => $this->l('Choose your state (if applicable)'), 'iso_code' => '--');
        foreach (State::getStates((int) $this->context->cookie->id_lang) as $state) {
            $stateList[] = array('id' => $state['id_state'], 'name' => $state['name'], 'iso_code' => $state['iso_code']);
        }
        $countryList = array();
        $countryList[] = array('id' => '0', 'name' => $this->l('Choose your country'), 'iso_code' => '--');
        foreach (Country::getCountries((int) $this->context->cookie->id_lang, false, null, false) as $country) {
            $countryList[] = array('id' => $country['id_country'], 'name' => $country['name'], 'iso_code' => $country['iso_code']);
        }
        $buffer .= '<link href="' . $this->_path . 'css/avalara.css" rel="stylesheet" type="text/css">
		<script type="text/javascript">
			/* Fancybox */
			$(\'a.avalara-video-btn\').live(\'click\', function(){
			    $.fancybox({
			        \'type\' : \'iframe\',
			        \'href\' : this.href.replace(new RegExp("watch\\?v=", "i"), \'embed\') + \'?rel=0&autoplay=1\',
			        \'swf\': {\'allowfullscreen\':\'true\', \'wmode\':\'transparent\'},
			        \'overlayShow\' : true,
			        \'centerOnScroll\' : true,
			        \'speedIn\' : 100,
			        \'speedOut\' : 50,
			        \'width\' : 853,
			        \'height\' : 480
			    });
			    return false;
			});
		</script>
		<script type="text/javascript">
			$(document).ready(function(){
			    var height1 = 0;
			    var height = 0;
			     $(\'.field-height1\').each(function(){
				if (height1 < $(this).height())
				    height1 = $(this).height();
			    });
			    
			    $(\'.field-height\').each(function(){
				if (height < $(this).height())
				    height = $(this).height();
			    });
			
				$(\'.field-height1\').css({\'height\' : $(\'.field-height1\').css(\'height\', height1+\'px\')});
			    $(\'.field-height\').css({\'height\' : $(\'.field-height\').css(\'height\', height+\'px\')});

updateAvalaraTaxState($(\'#avalaratax_country\').val());

    $(\'#avalaratax_country\').change(function(){
updateAvalaraTaxState($(this).val());
    });


			});
function updateAvalaraTaxState(iso_code)
{

var default_state = "' . $confValues['AVALARATAX_STATE'] . '";

$(\'#avalaratax_state\').html(\'\');
	$.ajax({
	    type : \'GET\',
	    url : \'../modules/avalaratax/states.php?country_iso_code=\'+iso_code,
	    dataType: \'JSON\',
	    success: function(data)
	    {
		if (data != 0)
		{
		    $.each(data[iso_code], function(i, item){
if (default_state == item.state_iso_code)
			$(\'#avalaratax_state\').append(\'<option  selected="selected" value="\'+item.state_iso_code+\'">\'+item.name+\'</option>\');
else
			$(\'#avalaratax_state\').append(\'<option  value="\'+item.state_iso_code+\'">\'+item.name+\'</option>\');
			$(\'#avalaratax_state\').show();
			$(\'#avalaratax_label_state\').show();
		    });
		}
		else
		{
		    $(\'#avalaratax_state\').hide();
		    $(\'#avalaratax_label_state\').hide();
		}
	    }
	});

}

		</script>
		<div class="avalara-wrap">
			<p class="avalara-intro"><a href="http://www.avalara.com/e-commerce/prestashop" class="avalara-logo" target="_blank"><img src="' . $this->_path . 'img/avalara_logo.png" alt="Avalara" border="0" /></a><a href="http://www.avalara.com/e-commerce/prestashop" class="avalara-link" target="_blank">' . $this->l('Create an account') . '</a>' . $this->l('Avalara and PrestaShop have partnered to provide the easiest way for you to accurately calculate and fill sales tax.') . '</p>
			<div class="clear"></div>
			<div class="avalara-content">
				<div class="avalara-video">
					<h3>' . $this->l('No one likes dealing with sales tax.') . '</h3>
					<p>' . $this->l('Sales tax isn\'t core to your business and should be automated. You may be doing it wrong, exposing your business to unnecessary audit risks, and don\'t even know it.') . '</p>
					<a href="http://www.youtube.com/embed/tm1tENVdcQ8" class="avalara-video-btn"><img src="' . $this->_path . 'img/avalara-video-screen.jpg" alt="Avalara Video" /><img src="' . $this->_path . 'img/btn-video.png" alt="" class="video-icon" /></a>
				</div>
				<h3>' . $this->l('Doing sales tax right is simple with Avalara.') . '</h3>
				<p>' . $this->l('We do all of the research and automate the process for you, ensuring that the system is up-to-date with the most recent sales tax and VAT rates and rules in every state and country, so you don’t have to.  As a cloud-based service, AvaTax eliminates ongoing maintenance and support.  It provides you with a complete solution to manage your sales tax needs.') . '</p>
				<img src="' . $this->_path . 'img/avatax_badge.png" alt="AvaTax Certified" class="avatax-badge" />
				<ul>
					<li>' . $this->l('Address Validation included') . '</li>
					<li>' . $this->l('Rooftop Accurate Calculations') . '</li>
					<li>' . $this->l('Product and Service Taxability Rules') . '</li>
					<li>' . $this->l('Exemption Certificate Management') . '</li>
					<li>' . $this->l('Out-of-the-Box Sales Tax Reporting') . '</li>
				</ul>
				<a href="http://www.avalara.com/e-commerce/prestashop" class="avalara-link" target="_blank">' . $this->l('Create an account') . '</a>
			</div>
			<fieldset class="field-height1 right-fieldset">
			<legend><img src="' . $this->_path . 'img/icon-console.gif" alt="" />' . $this->l('AvaTax Admin Console') . '</legend>
				<p><a href="https://admin-avatax.avalara.net/" target="_blank">' . $this->l('Log-in to AvaTax Admin Console') . '</a></p>
				<a href="https://admin-avatax.avalara.net/" target="_blank"><img src="' . $this->_path . 'img/avatax-logo.png" alt="AvaTax" class="avatax-logo" /></a>
			</fieldset>
			<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" class="left-form">
				<fieldset class="field-height1">
					<legend><img src="' . $this->_path . 'img/icon-config.gif" alt="" />' . $this->l('Configuration') . '</legend>
					<h4>' . $this->l('AvaTax Credentials') . '</h4>';
        if (isset($connectionTestResult)) {
            $buffer .= '<div id="test_connection" style="background: ' . Tools::safeOutput($connectionTestResult[1]) . ';">' . $connectionTestResult[0] . '</div>';
        }
        $buffer .= '<label>' . $this->l('Account Number') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_account_number" value="' . (isset($confValues['AVALARATAX_ACCOUNT_NUMBER']) ? Tools::safeOutput($confValues['AVALARATAX_ACCOUNT_NUMBER']) : '') . '" />
					</div>
					<label>' . $this->l('License Key') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_license_key" value="' . (isset($confValues['AVALARATAX_LICENSE_KEY']) ? Tools::safeOutput($confValues['AVALARATAX_LICENSE_KEY']) : '') . '" />
					</div>
					<label>' . $this->l('URL') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_url" value="' . (isset($confValues['AVALARATAX_URL']) ? Tools::safeOutput($confValues['AVALARATAX_URL']) : '') . '" />
					</div>
					<label>' . $this->l('Company Code') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_company_code" value="' . (isset($confValues['AVALARATAX_COMPANY_CODE']) ? Tools::safeOutput($confValues['AVALARATAX_COMPANY_CODE']) : '') . '" /> ' . $this->l('Located in the top-right corner of your AvaTax Admin Console') . '
					</div>
					<div class="margin-form">
						<input type="submit" class="button" name="SubmitAvalaraTaxSettings" value="' . $this->l('Save Settings') . '" /><img src="' . $this->_path . 'img/icon-connection.gif" alt="" class="icon-connection" /><input type="submit" id="avalaratax_test_connection" class="button" name="SubmitAvalaraTestConnection" value="' . $this->l('Click here to Test Connection') . '" />
					</div>
				</fieldset>
			</form>
			<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" class="form-half reset-label">
				<fieldset class="field-height MR7">
					<legend><img src="' . $this->_path . 'img/icon-options.gif" alt="" />' . $this->l('Options') . '</legend>
					<label>' . $this->l('Enable address validation') . '</label>
					<div class="margin-form">
						<input type="checkbox" name="avalaratax_address_validation" value="1"' . (isset($confValues['AVALARATAX_ADDRESS_VALIDATION']) && $confValues['AVALARATAX_ADDRESS_VALIDATION'] ? ' checked="checked"' : '') . ' />
						(' . $this->l('Not compatible with One Page Checkout') . ')
					</div>
					<label>' . $this->l('Enable tax calculation') . '</label>
					<div class="margin-form">
						<input type="checkbox" name="avalaratax_tax_calculation" value="1" ' . (isset($confValues['AVALARATAX_TAX_CALCULATION']) && $confValues['AVALARATAX_TAX_CALCULATION'] ? ' checked="checked"' : '') . ' />
					</div>
					<label>' . $this->l('Enable address normalization in uppercase') . '</label>
					<div class="margin-form">
						<input type="checkbox" name="avalaratax_address_normalization" value="1" ' . (isset($confValues['AVALARATAX_ADDRESS_NORMALIZATION']) && $confValues['AVALARATAX_ADDRESS_NORMALIZATION'] ? ' checked="checked"' : '') . ' />
					</div>
					<label>' . $this->l('Enable tax calculation outside of your state') . '</label>
					<div class="margin-form">
						<input type="checkbox" name="avalaratax_tax_outside" value="1" ' . (isset($confValues['AVALARATAX_TAX_OUTSIDE']) && $confValues['AVALARATAX_TAX_OUTSIDE'] ? ' checked="checked"' : '') . ' />
					</div>
					<label>' . $this->l('Request timeout') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_timeout" value="' . (isset($confValues['AVALARATAX_TIMEOUT']) ? Tools::safeOutput($confValues['AVALARATAX_TIMEOUT']) : '') . '" style="width: 40px;" /> ' . $this->l('seconds') . '
					</div>
					<div style="display: none;"
						<label>' . $this->l('Refresh tax rate cache every: ') . '</label>
						<div class="margin-form">
							<input type="text" name="avalara_cache_max_limit" value="' . (isset($confValues['AVALARA_CACHE_MAX_LIMIT']) ? Tools::safeOutput($confValues['AVALARA_CACHE_MAX_LIMIT']) : '') . '" style="width: 40px;" /> ' . $this->l('minutes') . '
						</div>
					</div>
					<div class="margin-form">
						<input type="submit" class="button avalaratax_button" name="SubmitAvalaraTaxOptions" value="' . $this->l('Save Settings') . '" />
						<input type="submit" class="button avalaratax_button" name="SubmitAvalaraTaxClearCache" value="' . $this->l('Clear Cache') . '" style="display: none;"/>
					</div>
					<div class="sep"></div>
					<h4>' . $this->l('Default Post/Commit/Cancel/Refund Options') . '</h4>
					<span class="avalara-info">' . $this->l('When an order\'s status is updated, the following options will be used to update Avalara\'s records.') . '</span>';
        // Check if the order status exist
        $orderStatusList = array();
        foreach (Db::getInstance()->ExecuteS('SELECT `id_order_state`, `name` FROM `' . _DB_PREFIX_ . 'order_state_lang` WHERE `id_lang` = ' . (int) $this->context->cookie->id_lang) as $v) {
            $orderStatusList[$v['id_order_state']] = Tools::safeOutput($v['name']);
        }
        $buffer .= '<table class="avalara-table" cellspacing="0" cellpadding="0" width="100%">
						<th>' . $this->l('Action') . '</th>
						<th>' . $this->l('Order status in your store') . '</th>
						<tr>
							<td class="avalaratax_column">' . $this->l('Post order to Avalara') . ':</td>
							<td>' . (isset($orderStatusList[Configuration::get('AVALARATAX_POST_ID')]) ? html_entity_decode(Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_POST_ID')])) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
							</td>
						</tr>
						<tr>
							<td class="avalaratax_column">' . $this->l('Commit order to Avalara') . ':</td>
							<td>' . (isset($orderStatusList[Configuration::get('AVALARATAX_COMMIT_ID')]) ? html_entity_decode(Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_COMMIT_ID')])) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
							</td>
						</tr>
						<tr>
							<td class="avalaratax_column">' . $this->l('Delete order from Avalara') . ':</td>
							<td>' . (isset($orderStatusList[Configuration::get('AVALARATAX_CANCEL_ID')]) ? html_entity_decode(Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_CANCEL_ID')])) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
							</td>
						</tr>
						<tr>
							<td class="avalaratax_column last">' . $this->l('Void order in Avalara') . ':</td>
							<td class="last">' . (isset($orderStatusList[Configuration::get('AVALARATAX_REFUND_ID')]) ? html_entity_decode(Tools::safeOutput($orderStatusList[Configuration::get('AVALARATAX_REFUND_ID')])) : '<div style="color: red">' . $this->l('[ERROR] A default value was not found. Please, restore PrestaShop\'s default statuses.') . '</div>') . '
							</td>
						</tr>
					</table>
				</fieldset>
			</form>
			<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" class="form-half">
				<fieldset class="field-height ML7">
					<legend><img src="' . $this->_path . 'img/icon-address.gif" alt="" />' . $this->l('Default Origin Address') . '</legend>
					<label>' . $this->l('Address Line 1') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_address_line1" value="' . (isset($confValues['AVALARATAX_ADDRESS_LINE1']) ? Tools::safeOutput($confValues['AVALARATAX_ADDRESS_LINE1']) : '') . '" />
					</div>
					<label>' . $this->l('Address Line 2') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_address_line2" value="' . (isset($confValues['AVALARATAX_ADDRESS_LINE2']) ? Tools::safeOutput($confValues['AVALARATAX_ADDRESS_LINE2']) : '') . '" />
					</div>
					<label>' . $this->l('City') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_city" value="' . (isset($confValues['AVALARATAX_CITY']) ? Tools::safeOutput($confValues['AVALARATAX_CITY']) : '') . '" />
					</div>
					<label>' . $this->l('Zip Code') . '</label>
					<div class="margin-form">
						<input type="text" name="avalaratax_zip_code" value="' . (isset($confValues['AVALARATAX_ZIP_CODE']) ? Tools::safeOutput($confValues['AVALARATAX_ZIP_CODE']) : '') . '" />
					</div>
					<label>' . $this->l('Country') . '</label>
					<div class="margin-form">
						<select name="avalaratax_country" id="avalaratax_country">';
        foreach ($countryList as $country) {
            $buffer .= '<option value="' . substr(strtoupper($country['iso_code']), 0, 2) . '" ' . ($country['iso_code'] == $confValues['AVALARATAX_COUNTRY'] ? ' selected="selected"' : '') . '>' . Tools::safeOutput($country['name']) . '</option>';
        }
        $buffer .= '</select>
					</div>
					<label id="avalaratax_label_state" >' . $this->l('State') . '</label>
					<div class="margin-form">
						<select name="avalaratax_state" id="avalaratax_state">';
        foreach ($stateList as $state) {
            $buffer .= '<option value="' . substr(strtoupper($state['iso_code']), 0, 2) . '" ' . ($state['iso_code'] == $confValues['AVALARATAX_STATE'] ? ' selected="selected"' : '') . '>' . Tools::safeOutput($state['name']) . '</option>';
        }
        return $buffer . '</select>
					</div>
					<div class="margin-form">
						<input type="submit" class="button" name="SubmitAvalaraAddressOptions" value="' . $this->l('Save Settings') . '" />
					</div>
				</fieldset>
			</form>
			<div class="clear"></div>
		</div>';
    }
 private function fetchCountries()
 {
     // $countryList = array();
     // $countryList[] = array('id' => '0', 'name' => $this->l('Choose your country'));
     // foreach (Country::getCountries($this->context->language->id) as $country) {
     //     $countryList[] = array('id' => $country['id_country'], 'name' => $country['name']);
     // }
     // $this->context->smarty->assign( array('countries' => $countryList));
     $cityList = array();
     $cityList[] = array('id' => '0', 'name' => $this->l('Scegli il comune'));
     foreach (AphCity::getCities() as $city) {
         if ($city['id_country'] == $this->id_country) {
             $cityList[] = array('id' => $city['id_city'], 'name' => $city['name']);
         }
     }
     $this->context->smarty->assign(array('cities' => $cityList));
     $statesList = array();
     $statesList[] = array('id' => '0', 'name' => $this->l('Scegli la provincia'));
     foreach (State::getStates($this->context->language->id) as $state) {
         if ($state['id_country'] == $this->id_country) {
             $statesList[] = array('id' => $state['id_state'], 'name' => $state['name']);
         }
     }
     $this->context->smarty->assign(array('states' => $statesList));
 }
Ejemplo n.º 12
0
 function changeStates($id)
 {
     global $cookie;
     $tax = new $this->className($id);
     if (!Validate::isLoadedObject($tax)) {
         die(Tools::displayError('object cannot be loaded'));
     }
     $states = State::getStates(intval($cookie->id_lang), true);
     foreach ($states as $state) {
         if ($tax->getState($state['id_state'])) {
             if (!isset($_POST['state_' . $state['id_state']]) or !$_POST['state_' . $state['id_state']]) {
                 $tax->deleteState($state['id_state']);
             }
         } elseif (isset($_POST['state_' . $state['id_state']]) and $_POST['state_' . $state['id_state']]) {
             $tax->addState($state['id_state']);
         }
     }
 }