예제 #1
0
    function getContent()
    {
        $configKeys = array('EBAY_SECURITY_TOKEN', 'PS_LANG_DEFAULT');
        // Load prestashop ebay's configuration
        $configs = Configuration::getMultiple($configKeys);
        $profile_configs = $this->ebay_profile->getMultiple(array('EBAY_DELIVERY_TIME', 'EBAY_ZONE_NATIONAL', 'EBAY_ZONE_INTERNATIONAL'));
        // Check if the module is configured
        if (!$this->ebay_profile->getConfiguration('EBAY_PAYPAL_EMAIL')) {
            $template_vars = array('error_form_shipping' => 'true');
            return $this->display('error_paypal_email.tpl', $template_vars);
        }
        $nb_shipping_zones_excluded = DB::getInstance()->getValue('SELECT COUNT(*) 
			FROM ' . _DB_PREFIX_ . 'ebay_shipping_zone_excluded
			WHERE `id_ebay_profile` = ' . (int) $this->ebay_profile->id);
        if (!$nb_shipping_zones_excluded) {
            EbayShippingZoneExcluded::loadEbayExcludedLocations($this->ebay_profile->id);
        }
        $module_filters = version_compare(_PS_VERSION_, '1.4.5', '>=') ? Carrier::CARRIERS_MODULE : 2;
        //INITIALIZE CACHE
        $psCarrierModule = $this->ebay_profile->getCarriers($configs['PS_LANG_DEFAULT'], false, false, false, null, $module_filters);
        $url_vars = array('id_tab' => '3', 'section' => 'shipping');
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $url_vars['controller'] = Tools::getValue('controller');
        } else {
            $url_vars['tab'] = Tools::getValue('tab');
        }
        $zones = Zone::getZones(true);
        foreach ($zones as &$zone) {
            $zone['carriers'] = Carrier::getCarriers($this->context->language->id, false, false, $zone['id_zone']);
        }
        $template_vars = array('eBayCarrier' => EbayShippingService::getCarriers($this->ebay_profile->ebay_site_id), 'psCarrier' => $this->ebay_profile->getCarriers($configs['PS_LANG_DEFAULT']), 'psCarrierModule' => $psCarrierModule, 'existingNationalCarrier' => EbayShipping::getNationalShippings($this->ebay_profile->id), 'existingInternationalCarrier' => EbayShippingInternationalZone::getExistingInternationalCarrier($this->ebay_profile->id), 'deliveryTime' => $profile_configs['EBAY_DELIVERY_TIME'], 'prestashopZone' => Zone::getZones(), 'excludeShippingLocation' => EbayShippingZoneExcluded::cacheEbayExcludedLocation($this->ebay_profile->id), 'internationalShippingLocations' => EbayShippingLocation::getInternationalShippingLocations(), 'deliveryTimeOptions' => EbayDeliveryTimeOptions::getDeliveryTimeOptions(), 'formUrl' => $this->_getUrl($url_vars), 'ebayZoneNational' => isset($profile_configs['EBAY_ZONE_NATIONAL']) ? $profile_configs['EBAY_ZONE_NATIONAL'] : false, 'ebayZoneInternational' => isset($profile_configs['EBAY_ZONE_INTERNATIONAL']) ? $profile_configs['EBAY_ZONE_INTERNATIONAL'] : false, 'ebay_token' => $configs['EBAY_SECURITY_TOKEN'], 'id_ebay_profile' => $this->ebay_profile->id, 'newPrestashopZone' => $zones);
        return $this->display('shipping.tpl', $template_vars);
    }
    public function renderForm()
    {
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        $address_layout = AddressFormat::getAddressCountryFormat($obj->id);
        if ($value = Tools::getValue('address_layout')) {
            $address_layout = $value;
        }
        $default_layout = '';
        $default_layout_tab = array(array('firstname', 'lastname'), array('company'), array('vat_number'), array('address1'), array('address2'), array('postcode', 'city'), array('Country:name'), array('phone'), array('phone_mobile'));
        foreach ($default_layout_tab as $line) {
            $default_layout .= implode(' ', $line) . "\r\n";
        }
        $this->fields_form = array('legend' => array('title' => $this->l('Countries'), 'image' => '../img/admin/world.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Country:'), 'name' => 'name', 'lang' => true, 'size' => 30, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}', 'desc' => $this->l('Country name')), array('type' => 'text', 'label' => $this->l('ISO code:'), 'name' => 'iso_code', 'size' => 4, 'maxlength' => 3, 'class' => 'uppercase', 'required' => true, 'desc' => $this->l('Two -- or three -- letter ISO code (e.g. U.S. for United States)') . '.
							<a href="http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm" target="_blank">' . $this->l('Official list here') . '
							</a>.'), array('type' => 'text', 'label' => $this->l('Call prefix:'), 'name' => 'call_prefix', 'size' => 4, 'maxlength' => 3, 'class' => 'uppercase', 'required' => true, 'desc' => $this->l('International call prefix, (e.g. 1 for United States)')), array('type' => 'select', 'label' => $this->l('Default currency:'), 'name' => 'id_currency', 'options' => array('query' => Currency::getCurrencies(), 'id' => 'id_currency', 'name' => 'name', 'default' => array('label' => $this->l('Default store currency'), 'value' => 0))), array('type' => 'select', 'label' => $this->l('Zone:'), 'name' => 'id_zone', 'options' => array('query' => Zone::getZones(), 'id' => 'id_zone', 'name' => 'name'), 'desc' => $this->l('Geographical region')), array('type' => 'radio', 'label' => $this->l('Need zip/postal code:'), 'name' => 'need_zip_code', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'need_zip_code_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'need_zip_code_off', 'value' => 0, 'label' => $this->l('No')))), array('type' => 'text', 'label' => $this->l('Zip/post code format:'), 'name' => 'zip_code_format', 'class' => 'uppercase', 'required' => true, 'desc' => $this->l('Zip Code format (L for a letter, N for a number and C for the ISO code). For example, NNNNN for the United States. No verification if undefined.')), array('type' => 'address_layout', 'label' => $this->l('Address format:'), 'name' => 'address_layout', 'address_layout' => $address_layout, 'encoding_address_layout' => urlencode($address_layout), 'encoding_default_layout' => urlencode($default_layout), 'display_valid_fields' => $this->displayValidFields()), array('type' => 'radio', 'label' => $this->l('Address Standardization:'), 'name' => 'standardization', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'standardization_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'standardization_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'radio', 'label' => $this->l('Active:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, '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('Display this country to your customers (the selected country will always be displayed in the Back Office)')), array('type' => 'radio', 'label' => $this->l('Contains following  states:'), 'name' => 'contains_states', 'required' => false, 'class' => 't', 'values' => array(array('id' => 'contains_states_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" />' . $this->l('Yes')), array('id' => 'contains_states_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" />' . $this->l('No')))), array('type' => 'radio', 'label' => $this->l('Do you need a tax identification number?'), 'name' => 'need_identification_number', 'required' => false, 'class' => 't', 'values' => array(array('id' => 'need_identification_number_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" />' . $this->l('Yes')), array('id' => 'need_identification_number_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" />' . $this->l('No')))), array('type' => 'radio', 'label' => $this->l('Display tax label (e.g. "Tax incl."):'), 'name' => 'display_tax_label', 'required' => false, 'class' => 't', 'values' => array(array('id' => 'display_tax_label_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" />' . $this->l('Yes')), array('id' => 'display_tax_label_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" />' . $this->l('No'))))));
        if (Shop::isFeatureActive()) {
            $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
        }
        $this->fields_form['submit'] = array('title' => $this->l('Save   '), 'class' => 'button');
        if ($this->object->iso_code == 'US') {
            $this->object->standardization = Configuration::get('PS_TAASC');
        }
        return parent::renderForm();
    }
 public function xdInstall()
 {
     foreach ($this->Options->getValue('carrierList') as $carrier_key => $carrier_name) {
         $carrierId = \Configuration::get($carrier_key);
         $deleted = false;
         if ($carrierId > 0) {
             $carrier = new \Carrier($carrierId);
             $deleted = $carrier->deleted;
         }
         if ($carrierId < 1 || $deleted) {
             // Create carrier
             $carrier = new \Carrier();
             $carrier->name = $carrier_name;
             $carrier->id_tax_rules_group = 0;
             $carrier->active = 1;
             $carrier->deleted = 0;
             foreach (\Language::getLanguages(true) as $language) {
                 // TODO Carrier delay
                 $carrier->delay[(int) $language['id_lang']] = ' ';
             }
             $carrier->shipping_handling = 0;
             $carrier->range_behavior = 1;
             $carrier->is_module = 1;
             $carrier->shipping_external = 1;
             $carrier->external_module_name = $this->moduleInstance->name;
             $carrier->need_range = 1;
             if (!$carrier->add()) {
                 return false;
             }
             // Associate carrier to all groups
             $groups = \Group::getGroups(true);
             foreach ($groups as $group) {
                 \Db::getInstance()->insert('carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']));
             }
             // Create price range
             $rangePrice = new \RangePrice();
             $rangePrice->id_carrier = $carrier->id;
             $rangePrice->delimiter1 = '0';
             $rangePrice->delimiter2 = '10000';
             $rangePrice->add();
             // Create weight range
             $rangeWeight = new \RangeWeight();
             $rangeWeight->id_carrier = $carrier->id;
             $rangeWeight->delimiter1 = '0';
             $rangeWeight->delimiter2 = '10000';
             $rangeWeight->add();
             // Associate carrier to all zones
             $zones = \Zone::getZones(true);
             foreach ($zones as $zone) {
                 \Db::getInstance()->insert('carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']));
                 \Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
                 \Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
             }
             copy(self::$instanceBaseDir . '/img/logo.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
             \Configuration::updateValue($carrier_key, $carrier->id);
         }
     }
     return true;
 }
 public function getSettingsPage()
 {
     $configuration_obj = new DpdPolandConfiguration();
     $payment_modules = array();
     foreach (DpdPoland::getPaymentModules() as $payment_module) {
         $module = Module::getInstanceByName($payment_module['name']);
         if (!Validate::isLoadedObject($module)) {
             continue;
         }
         $payment_modules[] = array('displayName' => $module->displayName, 'name' => $payment_module['name']);
     }
     $this->context->smarty->assign(array('saveAction' => $this->module_instance->module_url, 'settings' => $configuration_obj, 'payer_numbers' => DpdPolandPayerNumber::getPayerNumbers(), 'payment_modules' => $payment_modules, 'zones' => Zone::getZones(), 'carrier_zones' => array('classic' => $this->getZonesForCarrier(DpdPolandConfiguration::CARRIER_CLASSIC_ID), 'standard' => $this->getZonesForCarrier(DpdPolandConfiguration::CARRIER_STANDARD_ID), 'standard_cod' => $this->getZonesForCarrier(DpdPolandConfiguration::CARRIER_STANDARD_COD_ID))));
     if (version_compare(_PS_VERSION_, '1.6', '>=')) {
         return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'admin/configuration_16.tpl');
     }
     return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'admin/configuration.tpl');
 }
예제 #5
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>';
    }
예제 #6
0
 public function renderForm()
 {
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $address_layout = AddressFormat::getAddressCountryFormat($obj->id);
     if ($value = Tools::getValue('address_layout')) {
         $address_layout = $value;
     }
     $default_layout = '';
     $default_layout_tab = array(array('firstname', 'lastname'), array('company'), array('vat_number'), array('address1'), array('address2'), array('postcode', 'city'), array('Country:name'), array('phone'), array('phone_mobile'));
     foreach ($default_layout_tab as $line) {
         $default_layout .= implode(' ', $line) . "\r\n";
     }
     $this->fields_form = array('legend' => array('title' => $this->l('Countries'), 'icon' => 'icon-globe'), 'input' => array(array('type' => 'text', 'label' => $this->l('Country'), 'name' => 'name', 'lang' => true, 'required' => true, 'hint' => $this->l('Country name') . ' - ' . $this->l('Invalid characters:') . ' &lt;&gt;;=#{} '), array('type' => 'text', 'label' => $this->l('ISO code'), 'name' => 'iso_code', 'maxlength' => 3, 'class' => 'uppercase', 'required' => true, 'hint' => $this->l('Two -- or three -- letter ISO code (e.g. "us for United States).')), array('type' => 'text', 'label' => $this->l('Call prefix'), 'name' => 'call_prefix', 'maxlength' => 3, 'class' => 'uppercase', 'required' => true, 'hint' => $this->l('International call prefix, (e.g. 1 for United States).')), array('type' => 'select', 'label' => $this->l('Default currency'), 'name' => 'id_currency', 'options' => array('query' => Currency::getCurrencies(), 'id' => 'id_currency', 'name' => 'name', 'default' => array('label' => $this->l('Default store currency'), 'value' => 0))), array('type' => 'select', 'label' => $this->l('Zone'), 'name' => 'id_zone', 'options' => array('query' => Zone::getZones(), 'id' => 'id_zone', 'name' => 'name'), 'hint' => $this->l('Geographical region.')), array('type' => 'switch', 'label' => $this->l('Does it need Zip/postal code?'), 'name' => 'need_zip_code', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'need_zip_code_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'need_zip_code_off', 'value' => 0, 'label' => $this->l('No')))), array('type' => 'text', 'label' => $this->l('Zip/postal code format'), 'name' => 'zip_code_format', 'required' => true, 'desc' => $this->l('Indicate the format of the postal code: use L for a letter, N for a number, and C for the country\'s ISO 3166-1 alpha-2 code. For example, NNNNN for the United States, France, Poland and many other; LNNNNLLL for Argentina, etc. If you do not want PrestaShop to verify the postal code for this country, leave it blank.')), array('type' => 'address_layout', 'label' => $this->l('Address format'), 'name' => 'address_layout', 'address_layout' => $address_layout, 'encoding_address_layout' => urlencode($address_layout), 'encoding_default_layout' => urlencode($default_layout), 'display_valid_fields' => $this->displayValidFields()), array('type' => 'switch', 'label' => $this->l('Active'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'hint' => $this->l('Display this country to your customers (the selected country will always be displayed in the Back Office).')), array('type' => 'switch', 'label' => $this->l('Contains states'), 'name' => 'contains_states', 'required' => false, 'values' => array(array('id' => 'contains_states_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" />' . $this->l('Yes')), array('id' => 'contains_states_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" />' . $this->l('No')))), array('type' => 'switch', 'label' => $this->l('Do you need a tax identification number?'), 'name' => 'need_identification_number', 'required' => false, 'values' => array(array('id' => 'need_identification_number_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" />' . $this->l('Yes')), array('id' => 'need_identification_number_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" />' . $this->l('No')))), array('type' => 'switch', 'label' => $this->l('Display tax label (e.g. "Tax incl.")'), 'name' => 'display_tax_label', 'required' => false, 'values' => array(array('id' => 'display_tax_label_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" />' . $this->l('Yes')), array('id' => 'display_tax_label_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" />' . $this->l('No'))))));
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso');
     }
     $this->fields_form['submit'] = array('title' => $this->l('Save'));
     return parent::renderForm();
 }
예제 #7
0
    /**
     * Set necessaries values to the created carrier
     *
     * @param $id_carrier
     * @param $dlv_mode
     * @return bool
     */
    private function addDefaultCarrierValue($id_carrier, $dlv_mode)
    {
        $weight_coef = $this->account_shop['MR_WEIGHT_COEFFICIENT'];
        // Default Range value depending of the delivery mode
        $range_weight = array('24R' => array(0, 20000 / $weight_coef), 'DRI' => array(20000 / $weight_coef, 130000 / $weight_coef), 'LD1' => array(0, 60000 / $weight_coef), 'LDS' => array(30000 / $weight_coef, 130000 / $weight_coef));
        // Set range weight for a dlv_mode
        if (!Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'range_weight`
					(`id_carrier`, `delimiter1`, `delimiter2`)
					VALUES (' . (int) $id_carrier . ', ' . $range_weight[$dlv_mode][0] . ', ' . $range_weight[$dlv_mode][1] . ')')) {
            $this->_postErrors[] = $this->l('Range weight can\'t be added');
            return false;
        }
        $range_weight_id = Db::getInstance()->Insert_ID();
        // Set a range price
        if (!Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'range_price`
					 (`id_carrier`, `delimiter1`, `delimiter2`)
					 VALUES (' . (int) $id_carrier . ', 0.000000, 10000.000000)')) {
            $this->_postErrors[] = $this->l('Range price can\'t be added');
            return false;
        }
        $range_price_id = Db::getInstance()->Insert_ID();
        $groups = Group::getGroups(Configuration::get('PS_LANG_DEFAULT'));
        foreach ($groups as $group) {
            if (!Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_group`
						(id_carrier, id_group)
						VALUES(' . (int) $id_carrier . ', ' . (int) $group['id_group'] . ')')) {
                $this->_postErrors[] = $this->l('Default zone can\'t be added');
                return false;
            }
        }
        // Set default zone
        $zones = Zone::getZones();
        foreach ($zones as $zone) {
            if (!Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone`
						(id_carrier, id_zone)
						VALUES(' . (int) $id_carrier . ', ' . (int) $zone['id_zone'] . ')') || !Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'delivery`
						(id_carrier, id_range_price, id_range_weight, id_zone, price)
						VALUES(' . (int) $id_carrier . ', ' . (int) $range_price_id . ', NULL,' . (int) $zone['id_zone'] . ', 0.00)') || !Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'delivery`
						(id_carrier, id_range_price, id_range_weight, id_zone, price)
						VALUES(' . (int) $id_carrier . ', NULL, ' . (int) $range_weight_id . ',' . (int) $zone['id_zone'] . ', 0.00)')) {
                $this->_postErrors[] = $this->l('Carrier zone or delivery data can\'t be added');
                return false;
            }
        }
        return true;
    }
예제 #8
0
 public function changeZones($id)
 {
     $carrier = new $this->className($id);
     if (!Validate::isLoadedObject($carrier)) {
         die(Tools::displayError('The object cannot be loaded.'));
     }
     $zones = Zone::getZones(false);
     foreach ($zones as $zone) {
         if (count($carrier->getZone($zone['id_zone']))) {
             if (!isset($_POST['zone_' . $zone['id_zone']]) || !$_POST['zone_' . $zone['id_zone']]) {
                 $carrier->deleteZone($zone['id_zone']);
             }
         } else {
             if (isset($_POST['zone_' . $zone['id_zone']]) && $_POST['zone_' . $zone['id_zone']]) {
                 $carrier->addZone($zone['id_zone']);
             }
         }
     }
 }
예제 #9
0
 public static function createSoColissimoCarrier($config)
 {
     $carrier = new Carrier();
     $carrier->name = $config['name'];
     $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
     $carrier->id_zone = $config['id_zone'];
     $carrier->url = $config['url'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'fr') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'en') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
     }
     if ($carrier->add()) {
         Configuration::updateValue('SOCOLISSIMO_CARRIER_ID', (int) $carrier->id);
         $groups = Group::getgroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '10000';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '10000';
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_zone VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $zone['id_zone'] . '\')');
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'delivery VALUE (\'\',\'' . (int) $carrier->id . '\',\'' . (int) $rangePrice->id . '\',NULL,\'' . (int) $zone['id_zone'] . '\',\'1\')');
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'delivery VALUE (\'\',\'' . (int) $carrier->id . '\',NULL,\'' . (int) $rangeWeight->id . '\',\'' . (int) $zone['id_zone'] . '\',\'1\')');
         }
         //copy logo
         if (!copy(dirname(__FILE__) . '/socolissimo.jpg', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
 public function changeZones($id)
 {
     $return = true;
     $carrier = new Carrier($id);
     if (!Validate::isLoadedObject($carrier)) {
         die($this->trans('The object cannot be loaded.', array(), 'Admin.Notifications.Error'));
     }
     $zones = Zone::getZones(false);
     foreach ($zones as $zone) {
         if (count($carrier->getZone($zone['id_zone']))) {
             if (!isset($_POST['zone_' . $zone['id_zone']]) || !$_POST['zone_' . $zone['id_zone']]) {
                 $return &= $carrier->deleteZone((int) $zone['id_zone']);
             }
         } elseif (isset($_POST['zone_' . $zone['id_zone']]) && $_POST['zone_' . $zone['id_zone']]) {
             $return &= $carrier->addZone((int) $zone['id_zone']);
         }
     }
     return $return;
 }
예제 #11
0
    public function displayForm()
    {
        global $currentIndex, $cookie;
        $obj = $this->loadObject(true);
        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 class="width3"><legend><img src="../img/admin/world.gif" />' . $this->l('States') . '</legend>
				<label>' . $this->l('Name:') . ' </label>
				<div class="margin-form">
					<input type="text" size="30" maxlength="32" name="name" value="' . htmlentities($this->getFieldValue($obj, 'name'), ENT_COMPAT, 'UTF-8') . '" /> <sup>*</sup>
					<p style="clear: both;">' . $this->l('State name to display in addresses and on invoices') . '</p>
				</div>
				<label>' . $this->l('ISO code:') . ' </label>
				<div class="margin-form">
					<input type="text" size="5" maxlength="4" name="iso_code" value="' . htmlentities($this->getFieldValue($obj, 'iso_code'), ENT_COMPAT, 'UTF-8') . '" style="text-transform: uppercase;" /> <sup>*</sup>
					<p>' . $this->l('1 to 4 letter ISO code') . ' (<a href="http://simple.wikipedia.org/wiki/List_of_U.S._states" target="_blank">' . $this->l('official list here') . '</a>)</p>
				</div>
				<label>' . $this->l('Country:') . ' </label>
				<div class="margin-form">
					<select name="id_country">';
        $countries = Country::getCountries(intval($cookie->id_lang), false, true);
        foreach ($countries as $country) {
            echo '<option value="' . intval($country['id_country']) . '"' . ($this->getFieldValue($obj, 'id_country') == $country['id_country'] ? ' selected="selected"' : '') . '>' . $country['name'] . '</option>';
        }
        echo '
					</select>
					<p>' . $this->l('Country where state, region or city is located') . '</p>
				</div>
				<label>' . $this->l('Zone:') . ' </label>
				<div class="margin-form">
					<select name="id_zone">';
        $zones = Zone::getZones();
        foreach ($zones as $zone) {
            echo '<option value="' . intval($zone['id_zone']) . '"' . ($this->getFieldValue($obj, 'id_zone') == $zone['id_zone'] ? ' selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        echo '
					</select>
					<p>' . $this->l('Geographical zone where this state is located') . '<br />' . $this->l('Used for shipping') . '</p>
				</div>
				<label>' . $this->l('Tax behavior:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="tax_behavior" id="product_tax" value="' . PS_PRODUCT_TAX . '" ' . ((!$obj->id or $this->getFieldValue($obj, 'tax_behavior') == PS_PRODUCT_TAX) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="product_tax">' . $this->l('Product tax') . '</label>
					<input type="radio" name="tax_behavior" id="state_tax" value="' . PS_STATE_TAX . '" ' . (($this->getFieldValue($obj, 'tax_behavior') == PS_STATE_TAX and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="state_tax">' . $this->l('State tax') . '</label>
					<input type="radio" name="tax_behavior" id="both_tax" value="' . PS_BOTH_TAX . '" ' . (($this->getFieldValue($obj, 'tax_behavior') == PS_BOTH_TAX and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="both_tax">' . $this->l('Both product & state tax') . '</label>
					<p>' . $this->l('Chose how tax will be applied for this state: the product\'s tax, the state\'s tax, or both.') . '</p>
				</div>
				<label>' . $this->l('Status:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ((!$obj->id or $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') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" /></label>
					<p>' . $this->l('Enabled or disabled') . '</p>
				</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>';
    }
예제 #12
0
    public function displayForm($isMainTab = true)
    {
        global $currentIndex, $cookie;
        parent::displayForm();
        $defaultLayout = '';
        $defaultLayoutTab = array(array('firstname', 'lastname'), array('company'), array('vat_number'), array('address1'), array('address2'), array('postcode', 'city'), array('Country:name'), array('phone'));
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        foreach ($defaultLayoutTab as $line) {
            $defaultLayout .= implode(' ', $line) . "\r\n";
        }
        echo '
		<script type="text/javascript" language="javascript" src="' . _PS_JS_DIR_ . 'jquery/jquery-fieldselection.js"></script>
		<script type="text/javascript" language="javascript">
			
			lastLayoutModified = "";
			
			$(document).ready(function()
			{
				$(".availableFieldsList").css("display", "none");
				$(".addPattern").click(function()
				{
					addFieldsToCursorPosition($(this).attr("id"))
					lastLayoutModified = $("#ordered_fields").val();
				});
				$("#ordered_fields").keyup(function()
				{
					lastLayoutModified = $(this).val();
				});
				$("#useLastDefaultLayout").mouseover(function()
				{
					switchExplanationText("' . $this->l('Will display back your last registered layout') . '");
				});
				$("#useDefaultLayoutSystem").mouseover(function()
				{
					switchExplanationText("' . $this->l('Will display a default layout for this country') . '");
				});
				$("#useCurrentLastModifiedLayout").mouseover(function()
				{
					switchExplanationText("' . $this->l('Will display back you\'re current editing layout') . '");
				});
				$("#eraseCurrentLayout").mouseover(function()
				{
					switchExplanationText("' . $this->l('Will delete the current layout') . '");
				});
				
			});
			
			function  switchExplanationText(text)
			{
				$("#explanationText").fadeOut("fast", function()
				{
					$(this).html(text);
					$(this).fadeIn("fast");
				});
			}
			
			function addFieldsToCursorPosition(pattern)
			{
				$("#ordered_fields").replaceSelection(pattern + " ");
			}
			
			function displayAvailableFields(containerName)
			{
				$(".availableFieldsList").each( function (){
					if ($(this).attr(\'id\') != \'availableListFieldsFor_\'+containerName)
						$(this).slideUp();
				});
				$("#availableListFieldsFor_" + containerName).slideToggle();
			}
			
			function resetLayout(defaultLayout, type)
			{
				if (confirm("' . $this->l('Are you sure to apply this selection ?') . '"))
				{
					$("#ordered_fields").val(unescape(defaultLayout.replace(/\\+/g, " ")));
				}
			}
			
		</script>
		<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/world.gif" />' . $this->l('Countries') . '</legend>
				<label>' . $this->l('Country:') . ' </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="30" 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 style="clear: both">' . $this->l('Name of country') . '</p>
				</div>
				<label>' . $this->l('ISO code:') . ' </label>
				<div class="margin-form">
					<input type="text" size="4" maxlength="3" name="iso_code" value="' . htmlentities($this->getFieldValue($obj, 'iso_code'), ENT_COMPAT, 'UTF-8') . '" style="text-transform: uppercase;" /> <sup>*</sup>
					<p>' . $this->l('2- or 3-letter ISO code, e.g., FR for France') . '. <a href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html" target="_blank">' . $this->l('Official list here') . '</a>.</p>
				</div>
				<label>' . $this->l('Call prefix:') . ' </label>
				<div class="margin-form">
					<input type="text" size="4" maxlength="3" name="call_prefix" value="' . (int) $this->getFieldValue($obj, 'call_prefix') . '" style="text-transform: uppercase;" /> <sup>*</sup>
					<p>' . $this->l('International call prefix, e.g., 33 for France.') . '.</p>
				</div>
				<label>' . $this->l('Default currency:') . ' </label>
				<div class="margin-form">
					<select name="id_currency">
						<option value="0" ' . (Tools::getValue('id_currency', $obj->id_currency) == 0 ? 'selected' : '') . '>' . $this->l('Default store currency') . '</option>
		';
        $currencies = Currency::getCurrencies();
        foreach ($currencies as $currency) {
            echo '<option value="' . intval($currency['id_currency']) . '" ' . (Tools::getValue('id_currency', $obj->id_currency) == $currency['id_currency'] ? 'selected' : '') . '>' . Tools::htmlentitiesUTF8($currency['name']) . '</option>';
        }
        echo '
					</select>
				</div>
				<label>' . $this->l('Zone:') . ' </label>
				<div class="margin-form">
					<select name="id_zone">';
        $zones = Zone::getZones();
        foreach ($zones as $zone) {
            echo '		<option value="' . (int) $zone['id_zone'] . '"' . ($this->getFieldValue($obj, 'id_zone') == $zone['id_zone'] ? ' selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $address_layout = AddressFormat::getAddressCountryFormat($obj->id);
        if ($value = Tools::getValue('address_layout')) {
            $address_layout = $value;
        }
        echo '		</select>
					<p>' . $this->l('Geographical zone where country is located') . '</p>
				</div>
				<label>' . $this->l('Need zip code:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="need_zip_code" id="need_zip_code_on" value="1" onchange="disableZipFormat();" ' . ((!$obj->id or $this->getFieldValue($obj, 'need_zip_code')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_zip_code_on"> <img src="../img/admin/enabled.gif" alt="" title="' . $this->l('Yes') . '" /></label>
					<input type="radio" name="need_zip_code" id="need_zip_code_off" value="0" onchange="disableZipFormat();" ' . ((!$this->getFieldValue($obj, 'need_zip_code') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_zip_code_off"> <img src="../img/admin/disabled.gif" alt="" title="' . $this->l('No') . '" /></label>
				</div>
				<label class="zip_code_format">' . $this->l('Zip code format:') . ' </label>
				<div class="margin-form zip_code_format">
					<input type="text" name="zip_code_format" id="zip_code_format" value="' . $this->getFieldValue($obj, 'zip_code_format') . '" onkeyup="$(\'#zip_code_format\').val($(\'#zip_code_format\').val().toUpperCase());" /> <sup>*</sup>
					<p>' . $this->l('National zip code (L for a letter, N for a number and C for the Iso code), e.g., NNNNN for France. No verification if undefined') . '.</p>
				</div>
				<label class="address_layout">' . $this->l('Address layout:') . ' </label>
				<div class="margin-form" style="vertical-align: top;">
					<div style="float:left">
						<textarea id="ordered_fields" name="address_layout" style="width: 300px;height: 140px;">' . $address_layout . '</textarea>
					</div>
					<div style="float:left; margin-left:20px; width:340px;">
						' . $this->l('Liable fields for the address information (click to have more details)') . ': ' . $this->_displayValidFields() . '
					</div>
					<div class="clear"></div>
					<div style="margin:10px 0 10px 0;">
						<a id="useLastDefaultLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(\'' . urlencode($address_layout) . '\', \'lastDefault\');" class="button">' . $this->l('Use the last registered layout') . '</a>
						<a id="useDefaultLayoutSystem" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(\'' . urlencode($defaultLayout) . '\', \'defaultSystem\');" class="button">' . $this->l('Use a default layout') . '</a>
						<a id="useCurrentLastModifiedLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(lastLayoutModified, \'currentModified\')" class="button">' . $this->l('Use my current modified layout') . '</a>
						<a id="eraseCurrentLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(\'\', \'erase\');" class="button">' . $this->l('Clean layout') . '</a>
						<div style="margin-top:10px; padding-top:5px; height:10px;" id="explanationText"></div>
					</div>
				</div>
				<label>' . $this->l('Status:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'active')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="" title="' . $this->l('Enabled') . '" /></label>
					<input type="radio" name="active" id="active_off" value="0" ' . ((!$this->getFieldValue($obj, 'active') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="" title="' . $this->l('Disabled') . '" /></label>
					<p>' . $this->l('Enabled or disabled') . '</p>
				</div>
				<label>' . $this->l('Contains states:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="contains_states" id="contains_states_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'contains_states')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="contains_states_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="contains_states" id="contains_states_off" value="0" ' . ((!$this->getFieldValue($obj, 'contains_states') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="contains_states_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</label>
				</div>
				<label>' . $this->l('Need tax identification number?') . ' </label>
				<div class="margin-form">
					<input type="radio" name="need_identification_number" id="need_identification_number_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'need_identification_number')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_identification_number_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="need_identification_number" id="need_identification_number_off" value="0" ' . ((!$this->getFieldValue($obj, 'need_identification_number') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_identification_number_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</label>
				</div>
				<div class="clear"></div>
				<label>' . $this->l('Display tax label:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="display_tax_label" id="display_tax_label_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'display_tax_label')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="display_tax_label_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="display_tax_label" id="display_tax_label_off" value="0" ' . ((!$this->getFieldValue($obj, 'display_tax_label') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="display_tax_label_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</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>
		<script type="text/javascript">disableZipFormat();</script>';
    }
예제 #13
0
 private function carrierCompatibility($carrier)
 {
     // fix a bug in Prestashop before version 1.4.4.0 classes/cart.php function isCarrierInRange() range behavior
     $rangePrices = RangePrice::getRanges($carrier->id);
     if (empty($rangePrices)) {
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = 0.0;
         $rangePrice->delimiter2 = 1000000.0;
         if (!$rangePrice->add()) {
             $this->log('installation adding rangePrice failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
     } else {
         $rangePrice = new RangeWeight($rangePrices[0]['id_range_price']);
     }
     $rangeWeights = RangeWeight::getRanges($carrier->id);
     if (empty($rangeWeights)) {
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = 0.0;
         $rangeWeight->delimiter2 = 1000000.0;
         if (!$rangeWeight->add()) {
             $this->log('installation adding rangeWeight failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
     } else {
         $rangeWeight = new RangeWeight($rangeWeights[0]['id_range_weight']);
     }
     // Zones
     $zones = Zone::getZones();
     foreach ($zones as $zone) {
         $carrier->addZone($zone['id_zone']);
     }
     // create for each zone delivery options
     foreach ($zones as $zone) {
         $deliveryRangeWeight = new Delivery();
         $deliveryRangeWeight->id_carrier = $carrier->id;
         $deliveryRangeWeight->id_range_weight = $rangeWeight->id;
         $deliveryRangeWeight->id_range_price = 0;
         $deliveryRangeWeight->price = 0;
         $deliveryRangeWeight->id_zone = $zone['id_zone'];
         if (!$deliveryRangeWeight->add(true, true)) {
             $this->log('installation adding deliveryRangeWeight failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
         $deliveryRangePrice = new Delivery();
         $deliveryRangePrice->id_carrier = $carrier->id;
         $deliveryRangePrice->id_range_price = $rangePrice->id;
         $deliveryRangePrice->id_range_weight = 0;
         $deliveryRangePrice->price = 0;
         $deliveryRangePrice->id_zone = $zone['id_zone'];
         if (!$deliveryRangePrice->add(true, true)) {
             $this->log('installation adding deliveryRangePrice failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
     }
 }
 /**
  * @return bool
  * @throws Exception
  * @throws PrestaShopDatabaseException
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since ${VERSION}
  */
 public function installCarriers()
 {
     foreach (\acsws\classes\ACSWSOptions::getInstance()->getValue('carrierList') as $carrier_key => $carrier_name) {
         $carrierId = Configuration::get($carrier_key);
         if ($carrierId < 1) {
             // Create carrier
             $carrier = new Carrier();
             $carrier->name = $carrier_name;
             $carrier->id_tax_rules_group = 0;
             $carrier->active = 1;
             $carrier->deleted = 0;
             foreach (Language::getLanguages(true) as $language) {
                 // TODO Carrier delay
                 $carrier->delay[(int) $language['id_lang']] = '' . $carrier_name;
             }
             $carrier->shipping_handling = 1;
             $carrier->range_behavior = 0;
             $carrier->is_module = 1;
             $carrier->shipping_external = 1;
             $carrier->external_module_name = $this->name;
             $carrier->need_range = 1;
             if (!$carrier->add()) {
                 return false;
             }
             // Associate carrier to all groups
             $groups = Group::getGroups(true);
             foreach ($groups as $group) {
                 Db::getInstance()->insert('carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']));
             }
             // Create price range
             $rangePrice = new RangePrice();
             $rangePrice->id_carrier = $carrier->id;
             $rangePrice->delimiter1 = '0';
             $rangePrice->delimiter2 = '10000';
             $rangePrice->add();
             // Create weight range
             $rangeWeight = new RangeWeight();
             $rangeWeight->id_carrier = $carrier->id;
             $rangeWeight->delimiter1 = '0';
             $rangeWeight->delimiter2 = '10000';
             $rangeWeight->add();
             // Associate carrier to all zones
             $zones = Zone::getZones(true);
             foreach ($zones as $zone) {
                 Db::getInstance()->insert('carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']));
                 Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
                 Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
             }
             copy(dirname(__FILE__) . '/img/logo.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
             Configuration::updateValue($carrier_key, $carrier->id);
         }
     }
     return true;
 }
    public function renderZones($tax_rules, $id_lang)
    {
        $html = '';
        $zones = Zone::getZones(true);
        foreach ($zones as $key => $zone) {
            $html .= '<div class="tab-page" id="tab-page-' . $key . '">
							<h4 class="tab">' . $zone['name'] . '</h4>
							<script type="text/javascript">
								tabPane1.addTabPage( document.getElementById( "tab-page-' . $key . '" ) );
							</script>
						' . $this->renderCountries($tax_rules, $zone['id_zone'], $id_lang) . '
					  </div>';
        }
        return $html;
    }
예제 #16
0
    public function hookAdminStatsModules()
    {
        $ru = AdminController::$currentIndex . '&module=' . $this->name . '&token=' . Tools::getValue('token');
        $db = Db::getInstance();
        if (!isset($this->context->cookie->stats_granularity)) {
            $this->context->cookie->stats_granularity = 10;
        }
        if (Tools::isSubmit('submitIdZone')) {
            $this->context->cookie->stats_id_zone = (int) Tools::getValue('stats_id_zone');
        }
        if (Tools::isSubmit('submitGranularity')) {
            $this->context->cookie->stats_granularity = Tools::getValue('stats_granularity');
        }
        $currency = $this->context->currency;
        $employee = $this->context->employee;
        $from = max(strtotime(_PS_CREATION_DATE_ . ' 00:00:00'), strtotime($employee->stats_date_from . ' 00:00:00'));
        $to = strtotime($employee->stats_date_to . ' 23:59:59');
        $to2 = min(time(), $to);
        $interval = ($to - $from) / 60 / 60 / 24;
        $interval2 = ($to2 - $from) / 60 / 60 / 24;
        $prop30 = $interval / $interval2;
        if ($this->context->cookie->stats_granularity == 7) {
            $interval_avg = $interval2 / 30;
        }
        if ($this->context->cookie->stats_granularity == 4) {
            $interval_avg = $interval2 / 365;
        }
        if ($this->context->cookie->stats_granularity == 10) {
            $interval_avg = $interval2;
        }
        if ($this->context->cookie->stats_granularity == 42) {
            $interval_avg = $interval2 / 7;
        }
        $data_table = array();
        if ($this->context->cookie->stats_granularity == 10) {
            for ($i = $from; $i <= $to2; $i = strtotime('+1 day', $i)) {
                $data_table[date('Y-m-d', $i)] = array('fix_date' => date('Y-m-d', $i), 'countOrders' => 0, 'countProducts' => 0, 'totalSales' => 0);
            }
        }
        $date_from_gadd = $this->context->cookie->stats_granularity != 42 ? 'LEFT(date_add, ' . (int) $this->context->cookie->stats_granularity . ')' : 'IFNULL(MAKEDATE(YEAR(date_add),DAYOFYEAR(date_add)-WEEKDAY(date_add)), CONCAT(YEAR(date_add),"-01-01*"))';
        $date_from_ginvoice = $this->context->cookie->stats_granularity != 42 ? 'LEFT(invoice_date, ' . (int) $this->context->cookie->stats_granularity . ')' : 'IFNULL(MAKEDATE(YEAR(invoice_date),DAYOFYEAR(invoice_date)-WEEKDAY(invoice_date)), CONCAT(YEAR(invoice_date),"-01-01*"))';
        $result = $db->query('
		SELECT
			' . $date_from_ginvoice . ' as fix_date,
			COUNT(*) as countOrders,
			SUM((SELECT SUM(od.product_quantity) FROM ' . _DB_PREFIX_ . 'order_detail od WHERE o.id_order = od.id_order)) as countProducts,
			SUM(o.total_paid_tax_excl / o.conversion_rate) as totalSales
		FROM ' . _DB_PREFIX_ . 'orders o
		WHERE o.valid = 1
		AND o.invoice_date BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
		GROUP BY ' . $date_from_ginvoice);
        while ($row = $db->nextRow($result)) {
            $data_table[$row['fix_date']] = $row;
        }
        $this->html .= '<div>
			<div class="panel-heading"><i class="icon-dashboard"></i> ' . $this->displayName . '</div>
			<div class="alert alert-info">' . $this->l('The listed amounts do not include tax.') . '</div>
			<form id="granularity" action="' . Tools::safeOutput($ru) . '#granularity" method="post" class="form-horizontal">
				<div class="row row-margin-bottom">
					<label class="control-label col-lg-3">
						' . $this->l('Time frame') . '
					</label>
					<div class="col-lg-2">
						<input type="hidden" name="submitGranularity" value="1" />
						<select name="stats_granularity" onchange="this.form.submit();">
							<option value="10">' . $this->l('Daily') . '</option>
							<option value="42" ' . ($this->context->cookie->stats_granularity == '42' ? 'selected="selected"' : '') . '>' . $this->l('Weekly') . '</option>
							<option value="7" ' . ($this->context->cookie->stats_granularity == '7' ? 'selected="selected"' : '') . '>' . $this->l('Monthly') . '</option>
							<option value="4" ' . ($this->context->cookie->stats_granularity == '4' ? 'selected="selected"' : '') . '>' . $this->l('Yearly') . '</option>
						</select>
					</div>
				</div>
			</form>

			<table class="table">
				<thead>
					<tr>
						<th></th>
						<th class="text-center"><span class="title_box active">' . $this->l('Visits') . '</span></th>
						<th class="text-center"><span class="title_box active">' . $this->l('Registrations') . '</span></th>
						<th class="text-center"><span class="title_box active">' . $this->l('Placed orders') . '</span></th>
						<th class="text-center"><span class="title_box active">' . $this->l('Bought items') . '</span></th>
						<th class="text-center"><span class="title_box active">' . $this->l('Percentage of registrations') . '</span></th>
						<th class="text-center"><span class="title_box active">' . $this->l('Percentage of orders') . '</span></th>
						<th class="text-center"><span class="title_box active">' . $this->l('Revenue') . '</span></th>
					</tr>
				</thead>';
        $visit_array = array();
        $sql = 'SELECT ' . $date_from_gadd . ' as fix_date, COUNT(*) as visits
				FROM ' . _DB_PREFIX_ . 'connections c
				WHERE c.date_add BETWEEN ' . ModuleGraph::getDateBetween() . '
				' . Shop::addSqlRestriction(false, 'c') . '
				GROUP BY ' . $date_from_gadd;
        $visits = Db::getInstance()->query($sql);
        while ($row = $db->nextRow($visits)) {
            $visit_array[$row['fix_date']] = $row['visits'];
        }
        foreach ($data_table as $row) {
            $visits_today = (int) (isset($visit_array[$row['fix_date']]) ? $visit_array[$row['fix_date']] : 0);
            $date_from_greg = $this->context->cookie->stats_granularity != 42 ? 'LIKE \'' . $row['fix_date'] . '%\'' : 'BETWEEN \'' . Tools::substr($row['fix_date'], 0, 10) . ' 00:00:00\' AND DATE_ADD(\'' . Tools::substr($row['fix_date'], 0, 8) . Tools::substr($row['fix_date'], 8, 2) . ' 23:59:59\', INTERVAL 7 DAY)';
            $row['registrations'] = Db::getInstance()->getValue('
			SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'customer
			WHERE date_add BETWEEN ' . ModuleGraph::getDateBetween() . '
			AND date_add ' . $date_from_greg . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER));
            $this->html .= '
			<tr>
				<td>' . $row['fix_date'] . '</td>
				<td class="text-center">' . $visits_today . '</td>
				<td class="text-center">' . (int) $row['registrations'] . '</td>
				<td class="text-center">' . (int) $row['countOrders'] . '</td>
				<td class="text-center">' . (int) $row['countProducts'] . '</td>
				<td class="text-center">' . ($visits_today ? round(100 * (int) $row['registrations'] / $visits_today, 2) . ' %' : '-') . '</td>
				<td class="text-center">' . ($visits_today ? round(100 * (int) $row['countOrders'] / $visits_today, 2) . ' %' : '-') . '</td>
				<td class="text-right">' . Tools::displayPrice($row['totalSales'], $currency) . '</td>
			</tr>';
            $this->t1 += $visits_today;
            $this->t2 += (int) $row['registrations'];
            $this->t3 += (int) $row['countOrders'];
            $this->t4 += (int) $row['countProducts'];
            $this->t8 += $row['totalSales'];
        }
        $this->html .= '
				<tr>
					<th></th>
					<th class="text-center"><span class="title_box active">' . $this->l('Visits') . '</span></th>
					<th class="text-center"><span class="title_box active">' . $this->l('Registrations') . '</span></th>
					<th class="text-center"><span class="title_box active">' . $this->l('Placed orders') . '</span></th>
					<th class="text-center"><span class="title_box active">' . $this->l('Bought items') . '</span></th>
					<th class="text-center"><span class="title_box active">' . $this->l('Percentage of registrations') . '</span></th>
					<th class="text-center"><span class="title_box active">' . $this->l('Percentage of orders') . '</span></th>
					<th class="text-center"><span class="title_box active">' . $this->l('Revenue') . '</span></th>
				</tr>
				<tr>
					<td>' . $this->l('Total') . '</td>
					<td class="text-center">' . (int) $this->t1 . '</td>
					<td class="text-center">' . (int) $this->t2 . '</td>
					<td class="text-center">' . (int) $this->t3 . '</td>
					<td class="text-center">' . (int) $this->t4 . '</td>
					<td class="text-center">--</td>
					<td class="text-center">--</td>
					<td class="text-right">' . Tools::displayPrice($this->t8, $currency) . '</td>
				</tr>
				<tr>
					<td>' . $this->l('Average') . '</td>
					<td class="text-center">' . (int) ($this->t1 / $interval_avg) . '</td>
					<td class="text-center">' . (int) ($this->t2 / $interval_avg) . '</td>
					<td class="text-center">' . (int) ($this->t3 / $interval_avg) . '</td>
					<td class="text-center">' . (int) ($this->t4 / $interval_avg) . '</td>
					<td class="text-center">' . ($this->t1 ? round(100 * $this->t2 / $this->t1, 2) . ' %' : '-') . '</td>
					<td class="text-center">' . ($this->t1 ? round(100 * $this->t3 / $this->t1, 2) . ' %' : '-') . '</td>
					<td class="text-right">' . Tools::displayPrice($this->t8 / $interval_avg, $currency) . '</td>
				</tr>
				<tr>
					<td>' . $this->l('Forecast') . '</td>
					<td class="text-center">' . (int) ($this->t1 * $prop30) . '</td>
					<td class="text-center">' . (int) ($this->t2 * $prop30) . '</td>
					<td class="text-center">' . (int) ($this->t3 * $prop30) . '</td>
					<td class="text-center">' . (int) ($this->t4 * $prop30) . '</td>
					<td class="text-center">--</td>
					<td class="text-center">--</td>
					<td class="text-right">' . Tools::displayPrice($this->t8 * $prop30, $currency) . '</td>
				</tr>
			</table>
		</div>';
        $ca = $this->getRealCA();
        $sql = 'SELECT COUNT(DISTINCT c.id_guest)
		FROM ' . _DB_PREFIX_ . 'connections c
		WHERE c.date_add BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . Shop::addSqlRestriction(false, 'c');
        $visitors = Db::getInstance()->getValue($sql);
        $sql = 'SELECT COUNT(DISTINCT g.id_customer)
		FROM ' . _DB_PREFIX_ . 'connections c
		INNER JOIN ' . _DB_PREFIX_ . 'guest g ON c.id_guest = g.id_guest
		WHERE g.id_customer != 0
		AND c.date_add BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . Shop::addSqlRestriction(false, 'c');
        $customers = Db::getInstance()->getValue($sql);
        $sql = 'SELECT COUNT(DISTINCT c.id_cart)
		FROM ' . _DB_PREFIX_ . 'cart c 
		INNER JOIN ' . _DB_PREFIX_ . 'cart_product cp on c.id_cart = cp.id_cart
		WHERE (c.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' OR c.date_upd BETWEEN ' . ModuleGraph::getDateBetween() . ')
		' . Shop::addSqlRestriction(false, 'c');
        $carts = Db::getInstance()->getValue($sql);
        $sql = 'SELECT COUNT(DISTINCT c.id_cart)
		FROM ' . _DB_PREFIX_ . 'cart c 
		INNER JOIN ' . _DB_PREFIX_ . 'cart_product cp on c.id_cart = cp.id_cart
		WHERE (c.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' OR c.date_upd BETWEEN ' . ModuleGraph::getDateBetween() . ')
		AND id_address_invoice != 0
		' . Shop::addSqlRestriction(false, 'c');
        $fullcarts = Db::getInstance()->getValue($sql);
        $sql = 'SELECT COUNT(*)
		FROM ' . _DB_PREFIX_ . 'orders o
		WHERE o.valid = 1
		AND o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o');
        $orders = Db::getInstance()->getValue($sql);
        $this->html .= '
		<div class="row row-margin-bottom">
			<h4><i class="icon-filter"></i> ' . $this->l('Conversion') . '</h4>
		</div>
		<div class="row row-margin-bottom">
			<table class="table">
				<tbody>
					<tr>
						<td rowspan="2" class="text-center">
							<p>' . $this->l('Visitors') . '</p>
							<p>' . $visitors . '</p>
						</td>
						<td class="text-center">
							<p><i class="icon-chevron-right"></i></p>
							<p>' . round(100 * $customers / max(1, $visitors), 2) . ' %</p>
						</td>
						<td class="text-center">
							<p>' . $this->l('Accounts') . '</p>
							<p>' . $customers . '</p>
						</td>
						<td class="text-center">
							<p><i class="icon-chevron-right"></i></p>
							<p>' . round(100 * $fullcarts / max(1, $customers), 2) . ' %</p>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . $this->l('Full carts') . '</p>
							<p>' . $fullcarts . '</p>
						</td>
						<td rowspan="2" class="text-center">
							<p><i class="icon-chevron-right"></i></p>
							<p>' . round(100 * $orders / max(1, $fullcarts), 2) . ' %</p>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . $this->l('Orders') . '</p>
							<p>' . $orders . '</p>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . $this->l('Registered visitors') . '</p>
						</td>
						<td rowspan="2" class="text-center">
							<i class="icon-chevron-right"></i>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . round(100 * $orders / max(1, $customers), 2) . ' %</p>
						</td>
						<td rowspan="2" class="text-center">
							<i class="icon-chevron-right"></i>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . $this->l('Orders') . '</p>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . $this->l('Visitors') . '</p>
						</td>
						<td rowspan="2" class="text-center">
							<i class="icon-chevron-right"></i>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . round(100 * $orders / max(1, $visitors), 2) . ' %</p>
						</td>
						<td rowspan="2" class="center">
							<i class="icon-chevron-right"></i>
						</td>
						<td rowspan="2" class="text-center">
							<p>' . $this->l('Orders') . '</p>
						</td>
					</tr>
					<tr>
						<td class="text-center">
							<p><i class="icon-chevron-right"></i></p>
							<p>' . round(100 * $carts / max(1, $visitors)) . ' %</p>
						</td>
						<td class="text-center">
							<p>' . $this->l('Carts') . '</p>
							<p>' . $carts . '</p>
						</td>
						<td class="text-center">
							<p><i class="icon-chevron-right"></i></p>
							<p>' . round(100 * $fullcarts / max(1, $carts)) . ' %</p>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="alert alert-info">
			<p>' . $this->l('A simple statistical calculation lets you know the monetary value of your visitors:') . '</p>
			<p>' . $this->l('On average, each visitor places an order for this amount:') . ' <b>' . Tools::displayPrice($ca['ventil']['total'] / max(1, $visitors), $currency) . '.</b></p>
			<p>' . $this->l('On average, each registered visitor places an order for this amount:') . ' <b>' . Tools::displayPrice($ca['ventil']['total'] / max(1, $customers), $currency) . '</b>.</p>
		</div>';
        $from = strtotime($employee->stats_date_from . ' 00:00:00');
        $to = strtotime($employee->stats_date_to . ' 23:59:59');
        $interval = ($to - $from) / 60 / 60 / 24;
        $this->html .= '
			<div class="row row-margin-bottom">
				<h4><i class="icon-money"></i> ' . $this->l('Payment distribution') . '</h4>
				<div class="alert alert-info">' . $this->l('The amounts include taxes, so you can get an estimation of the commission due to the payment method.') . '
				</div>
				<form id="cat" action="' . Tools::safeOutput($ru) . '#payment" method="post" class="form-horizontal">
					<div class="row row-margin-bottom">
						<label class="control-label col-lg-3">
							' . $this->l('Zone:') . '
						</label>
						<div class="col-lg-3">
							<input type="hidden" name="submitIdZone" value="1" />
							<select name="stats_id_zone" onchange="this.form.submit();">
								<option value="0">' . $this->l('-- No filter --') . '</option>';
        foreach (Zone::getZones() as $zone) {
            $this->html .= '<option value="' . (int) $zone['id_zone'] . '" ' . ($this->context->cookie->stats_id_zone == $zone['id_zone'] ? 'selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $this->html .= '
							</select>
						</div>
					</div>
				</form>
				<table class="table">
					<thead>
						<tr>
							<th class="text-center"><span class="title_box active">' . $this->l('Module') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Orders') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Sales') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Average cart value') . '</span></th>
						</tr>
					</thead>
					<tbody>';
        foreach ($ca['payment'] as $payment) {
            $this->html .= '
						<tr>
							<td class="text-center">' . $payment['payment_method'] . '</td>
							<td class="text-center">' . (int) $payment['nb'] . '</td>
							<td class="text-right">' . Tools::displayPrice($payment['total'], $currency) . '</td>
							<td class="text-right">' . Tools::displayPrice($payment['total'] / (int) $payment['nb'], $currency) . '</td>
						</tr>';
        }
        $this->html .= '
					</tbody>
				</table>
			</div>
			<div class="row row-margin-bottom">
				<h4><i class="icon-sitemap"></i> ' . $this->l('Category distribution') . '</h4>
				<form id="cat_1" action="' . Tools::safeOutput($ru) . '#cat" method="post" class="form-horizontal">
					<div class="row row-margin-bottom">
						<label class="control-label col-lg-3">
							' . $this->l('Zone') . '
						</label>
						<div class="col-lg-3">
							<input type="hidden" name="submitIdZone" value="1" />
							<select name="stats_id_zone" onchange="this.form.submit();">
								<option value="0">' . $this->l('-- No filter --') . '</option>';
        foreach (Zone::getZones() as $zone) {
            $this->html .= '<option value="' . (int) $zone['id_zone'] . '" ' . ($this->context->cookie->stats_id_zone == $zone['id_zone'] ? 'selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $this->html .= '
							</select>
						</div>
					</div>
				</form>
				<table class="table">
					<thead>
						<tr>
							<th class="text-center"><span class="title_box active">' . $this->l('Category') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Products sold') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Sales') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Percentage of products sold') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Percentage of sales') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Average price') . '</span></th>
						</tr>
					</thead>
					<tbody>';
        foreach ($ca['cat'] as $catrow) {
            $this->html .= '
						<tr>
							<td class="text-center">' . (empty($catrow['name']) ? $this->l('Unknown') : $catrow['name']) . '</td>
							<td class="text-center">' . $catrow['orderQty'] . '</td>
							<td class="text-right">' . Tools::displayPrice($catrow['orderSum'], $currency) . '</td>
							<td class="text-center">' . number_format(100 * $catrow['orderQty'] / $this->t4, 1, '.', ' ') . '%</td>
							<td class="text-center">' . ((int) $ca['ventil']['total'] ? number_format(100 * $catrow['orderSum'] / $ca['ventil']['total'], 1, '.', ' ') : '0') . '%</td>
							<td class="text-right">' . Tools::displayPrice($catrow['priveAvg'], $currency) . '</td>
						</tr>';
        }
        $this->html .= '
					</tbody>
				</table>
			</div>
			<div class="row row-margin-bottom">
				<h4><i class="icon-flag"></i> ' . $this->l('Language distribution') . '</h4>
				<table class="table">
					<thead>
						<tr>
							<th class="text-center"><span class="title_box active">' . $this->l('Language') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Sales') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Percentage') . '</span></th>
							<th class="text-center" colspan="2"><span class="title_box active">' . $this->l('Growth') . '</span></th>
						</tr>
					</thead>
					<tbody>';
        foreach ($ca['lang'] as $ophone => $amount) {
            $percent = (int) $ca['langprev'][$ophone] ? number_format(100 * $amount / $ca['langprev'][$ophone] - 100, 1, '.', ' ') : '&#x221e;';
            $this->html .= '
					<tr ' . ($percent < 0 ? 'class="alt_row"' : '') . '>
						<td class="text-center">' . $ophone . '</td>
						<td class="text-right">' . Tools::displayPrice($amount, $currency) . '</td>
						<td class="text-center">' . ((int) $ca['ventil']['total'] ? number_format(100 * $amount / $ca['ventil']['total'], 1, '.', ' ') . '%' : '-') . '</td>
						<td class="text-center">' . ($percent > 0 || $percent == '&#x221e;' ? '<img src="../img/admin/arrow_up.png" alt="" />' : '<img src="../img/admin/arrow_down.png" alt="" /> ') . '</td>
						<td class="text-center">' . ($percent > 0 || $percent == '&#x221e;' ? '+' : '') . $percent . '%</td>
					</tr>';
        }
        $this->html .= '
					</tbody>
				</table>
			</div>
			<div class="row row-margin-bottom">
				<h4><i class="icon-map-marker"></i> ' . $this->l('Zone distribution') . '</h4>
				<table class="table">
					<thead>
						<tr>
							<th class="text-center"><span class="title_box active">' . $this->l('Zone') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Orders') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Sales') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Percentage of orders') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Percentage of sales') . '</span></th>
						</tr>
					</thead>
					<tbody>';
        foreach ($ca['zones'] as $zone) {
            $this->html .= '
					<tr>
						<td class="text-center">' . (isset($zone['name']) ? $zone['name'] : $this->l('Undefined')) . '</td>
						<td class="text-center">' . (int) $zone['nb'] . '</td>
						<td class="text-right">' . Tools::displayPrice($zone['total'], $currency) . '</td>
						<td class="text-center">' . ($ca['ventil']['nb'] ? number_format(100 * $zone['nb'] / $ca['ventil']['nb'], 1, '.', ' ') : '0') . '%</td>
						<td class="text-center">' . ((int) $ca['ventil']['total'] ? number_format(100 * $zone['total'] / $ca['ventil']['total'], 1, '.', ' ') : '0') . '%</td>
					</tr>';
        }
        $this->html .= '
					</tbody>
				</table>
			</div>
			<div class="row row-margin-bottom">
				<h4><i class="icon-money"></i> ' . $this->l('Currency distribution') . '</h4>
				<form id="cat_2" action="' . Tools::safeOutput($ru) . '#currencies" method="post" class="form-horizontal">
					<div class="row row-margin-bottom">
						<label class="control-label col-lg-3">
							' . $this->l('Zone:') . '
						</label>
						<div class="col-lg-3">
							<input type="hidden" name="submitIdZone" value="1" />
							<select name="stats_id_zone" onchange="this.form.submit();">
								<option value="0">' . $this->l('-- No filter --') . '</option>';
        foreach (Zone::getZones() as $zone) {
            $this->html .= '<option value="' . (int) $zone['id_zone'] . '" ' . ($this->context->cookie->stats_id_zone == $zone['id_zone'] ? 'selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $this->html .= '
							</select>
						</div>
					</div>
				</form>
				<table class="table">
					<thead>
						<tr>
							<th class="text-center"><span class="title_box active">' . $this->l('Currency') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Orders') . '</span></th>
							<th class="text-right"><span class="title_box active">' . $this->l('Sales (converted)') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Percentage of orders') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Percentage of sales') . '</span></th>
						</tr>
					</thead>
					<tbody>';
        foreach ($ca['currencies'] as $currency_row) {
            $this->html .= '
						<tr>
							<td class="text-center">' . $currency_row['name'] . '</td>
							<td class="text-center">' . (int) $currency_row['nb'] . '</td>
							<td class="text-right">' . Tools::displayPrice($currency_row['total'], $currency) . '</td>
							<td class="text-center">' . ($ca['ventil']['nb'] ? number_format(100 * $currency_row['nb'] / $ca['ventil']['nb'], 1, '.', ' ') : '0') . '%</td>
							<td class="text-center">' . ((int) $ca['ventil']['total'] ? number_format(100 * $currency_row['total'] / $ca['ventil']['total'], 1, '.', ' ') : '0') . '%</td>
						</tr>';
        }
        $this->html .= '
					</tbody>
				</table>
			</div>
			<div class="row row-margin-bottom">
				<h4><i class="icon-ticket"></i> ' . $this->l('Attribute distribution') . '</h4>
				<table class="table">
					<thead>
						<tr>
							<th class="text-center"><span class="title_box active">' . $this->l('Group') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Attribute') . '</span></th>
							<th class="text-center"><span class="title_box active">' . $this->l('Quantity of products sold') . '</span></th>
						</tr>
					</thead>
					<tbody>';
        foreach ($ca['attributes'] as $attribut) {
            $this->html .= '
						<tr>
							<td class="text-center">' . $attribut['gname'] . '</td>
							<td class="text-center">' . $attribut['aname'] . '</td>
							<td class="text-center">' . (int) $attribut['total'] . '</td>
						</tr>';
        }
        $this->html .= '
					</tbody>
				</table>
			</div>';
        return $this->html;
    }
 protected function generateZoneData()
 {
     $delimiter = ';';
     $line = array();
     $titles = array();
     $new_path = new Sampledatainstall();
     $f = fopen($new_path->sendPath() . 'output/zones.vsc', 'w');
     foreach ($this->zones_fields as $field => $array) {
         $titles[] = $array['label'];
     }
     fputcsv($f, $titles, $delimiter, '"');
     $zones = Zone::getZones();
     if ($zones) {
         foreach ($zones as $zone) {
             foreach ($this->zones_fields as $field => $array) {
                 $line[$field] = !Tools::isEmpty($zone[$field]) ? $zone[$field] : '';
             }
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
     }
     fclose($f);
 }
예제 #18
0
 /**
  * create shopgate carrier
  */
 public function createShopgateCarrier()
 {
     /** @var CarrierCore $carrier */
     $carrier = new Carrier();
     $carrier->name = self::MODULE_CARRIER_NAME;
     $carrier->active = true;
     $carrier->deleted = true;
     $carrier->shipping_handling = false;
     $carrier->range_behavior = true;
     $carrier->delay[Configuration::get('PS_LANG_DEFAULT')] = self::MODULE_CARRIER_NAME;
     $carrier->shipping_external = true;
     $carrier->is_module = true;
     $carrier->external_module_name = self::DEFAULT_EXTERNAL_MODULE_CARRIER_NAME;
     $carrier->need_range = true;
     foreach (Language::getLanguages() as $language) {
         $carrier->delay[$language['id_lang']] = 'Depends on Shopgate selected carrier';
     }
     if ($carrier->add()) {
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         /** @var RangePriceCore $rangePrice */
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '1000000';
         $rangePrice->add();
         /** @var RangeWeightCore $rangeWeight */
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '1000000';
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             /** @var $zone ZoneCore */
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
         }
     }
     Configuration::updateValue('SG_CARRIER_ID', $carrier->id);
 }
예제 #19
0
    public function displayForm()
    {
        global $currentIndex;
        $obj = $this->loadObject(true);
        $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
        $languages = Language::getLanguages();
        echo '
		<script type="text/javascript">
			id_language = Number(' . $defaultLanguage . ');
		</script>
		<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 class="width3"><legend><img src="../img/admin/world.gif" />' . $this->l('Countries') . '</legend>
				<label>' . $this->l('Country:') . ' </label>
				<div class="margin-form">';
        foreach ($languages as $language) {
            echo '
					<div id="name_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
						<input size="30" type="text" name="name_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'name', intval($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($languages, $defaultLanguage, 'name', 'name');
        echo '		<p style="clear: both">' . $this->l('Name of country') . '</p>
				</div>
				<label>' . $this->l('ISO code:') . ' </label>
				<div class="margin-form">
					<input type="text" size="4" maxlength="3" name="iso_code" value="' . htmlentities($this->getFieldValue($obj, 'iso_code'), ENT_COMPAT, 'UTF-8') . '" style="text-transform: uppercase;" /> <sup>*</sup>
					<p>' . $this->l('2- or 3-letter ISO code, e.g., FR for France') . '. <a href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html" target="_blank">' . $this->l('Official list here') . '</a>.</p>
				</div>
				<label>' . $this->l('Zone:') . ' </label>
				<div class="margin-form">
					<select name="id_zone">';
        $zones = Zone::getZones();
        foreach ($zones as $zone) {
            echo '<option value="' . intval($zone['id_zone']) . '"' . ($this->getFieldValue($obj, 'id_zone') == $zone['id_zone'] ? ' selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        echo '
					</select>
					<p>' . $this->l('Geographical zone where country is located') . '</p>
				</div>
				<label>' . $this->l('Status:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'active')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="" title="' . $this->l('Enabled') . '" /></label>
					<input type="radio" name="active" id="active_off" value="0" ' . ((!$this->getFieldValue($obj, 'active') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="" title="' . $this->l('Disabled') . '" /></label>
					<p>' . $this->l('Enabled or disabled') . '</p>
				</div>
				<label>' . $this->l('Contains states:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="contains_states" id="contains_states_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'contains_states')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="contains_states_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="contains_states" id="contains_states_off" value="0" ' . ((!$this->getFieldValue($obj, 'contains_states') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="contains_states_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</label>
				</div>
				<label>' . $this->l('Need tax identification number?') . ' </label>
				<div class="margin-form">
					<input type="radio" name="need_identification_number" id="need_identification_number_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'need_identification_number')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_identification_number_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="need_identification_number" id="need_identification_number_off" value="0" ' . ((!$this->getFieldValue($obj, 'need_identification_number') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_identification_number_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</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>';
    }
예제 #20
0
 public function renderForm()
 {
     $this->fields_form = array('legend' => array('title' => $this->l('States'), 'image' => '../img/admin/world.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 30, 'maxlength' => 32, 'required' => true, 'desc' => $this->l('State name to display in addresses and on invoices')), array('type' => 'text', 'label' => $this->l('ISO code:'), 'name' => 'iso_code', 'size' => 7, 'maxlength' => 7, 'required' => true, 'class' => 'uppercase', 'desc' => $this->l('1 to 4 letter ISO code')), array('type' => 'select', 'label' => $this->l('Country:'), 'name' => 'id_country', 'required' => false, 'default_value' => (int) $this->context->country->id, 'options' => array('query' => Country::getCountries($this->context->language->id, false, true), 'id' => 'id_country', 'name' => 'name'), 'desc' => $this->l('Country where state, region or city is located')), array('type' => 'select', 'label' => $this->l('Zone:'), 'name' => 'id_zone', 'required' => false, 'options' => array('query' => Zone::getZones(), 'id' => 'id_zone', 'name' => 'name'), 'desc' => array($this->l('Geographical zone where this state is located'), $this->l('Used for shipping'))), array('type' => 'radio', 'label' => $this->l('Status:'), 'name' => 'active', 'required' => false, 'class' => 't', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'active_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />')), 'desc' => $this->l('Enabled or disabled'))), 'submit' => array('title' => $this->l('   Save   '), 'class' => 'button'));
     return parent::renderForm();
 }
예제 #21
0
 public static function installExternalCarrier($config)
 {
     $carrier = new Carrier();
     $carrier->name = $config['name'];
     $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
     $carrier->id_zone = $config['id_zone'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'fr') {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'en') {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'))) {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
     }
     if ($carrier->add()) {
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '10000';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '10000';
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
         }
         // Copy Logo
         if (!copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
             return false;
         }
         // Return ID Carrier
         return (int) $carrier->id;
     }
     return false;
 }
예제 #22
0
    public function displayForm($isMainTab = true)
    {
        global $currentIndex, $cookie;
        parent::displayForm();
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        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/world.gif" />' . $this->l('States') . '</legend>
				<label>' . $this->l('Name:') . ' </label>
				<div class="margin-form">
					<input type="text" size="30" maxlength="32" name="name" value="' . htmlentities($this->getFieldValue($obj, 'name'), ENT_COMPAT, 'UTF-8') . '" /> <sup>*</sup>
					<p class="clear">' . $this->l('State name to display in addresses and on invoices') . '</p>
				</div>
				<label>' . $this->l('ISO code:') . ' </label>
				<div class="margin-form">
					<input type="text" size="5" maxlength="4" name="iso_code" value="' . htmlentities($this->getFieldValue($obj, 'iso_code'), ENT_COMPAT, 'UTF-8') . '" style="text-transform: uppercase;" /> <sup>*</sup>
					<p>' . $this->l('1 to 4 letter ISO code (search on Wikipedia if you don\'t know)') . '</p>
				</div>
				<label>' . $this->l('Country:') . ' </label>
				<div class="margin-form">
					<select name="id_country">';
        $countries = Country::getCountries((int) $cookie->id_lang, false, true);
        foreach ($countries as $country) {
            echo '<option value="' . (int) $country['id_country'] . '"' . ($this->getFieldValue($obj, 'id_country') == $country['id_country'] ? ' selected="selected"' : '') . '>' . $country['name'] . '</option>';
        }
        echo '
					</select>
					<p>' . $this->l('Country where state, region or city is located') . '</p>
				</div>
				<label>' . $this->l('Zone:') . ' </label>
				<div class="margin-form">
					<select name="id_zone">';
        $zones = Zone::getZones();
        foreach ($zones as $zone) {
            echo '<option value="' . (int) $zone['id_zone'] . '"' . ($this->getFieldValue($obj, 'id_zone') == $zone['id_zone'] ? ' selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        echo '
					</select>
					<p>' . $this->l('Geographical zone where this state is located') . '<br />' . $this->l('Used for shipping') . '</p>
				</div>
				<label>' . $this->l('Status:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ((!$obj->id or $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') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" /></label>
					<p>' . $this->l('Enabled or disabled') . '</p>
				</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>';
    }
예제 #23
0
 function changeZones($id)
 {
     $carrier = new $this->className($id);
     if (!Validate::isLoadedObject($carrier)) {
         die(Tools::displayError('Object cannot be loaded'));
     }
     $zones = Zone::getZones(true);
     foreach ($zones as $zone) {
         if (sizeof($carrier->getZone($zone['id_zone']))) {
             if (!isset($_POST['zone_' . $zone['id_zone']]) or !$_POST['zone_' . $zone['id_zone']]) {
                 $carrier->deleteZone($zone['id_zone']);
             }
         } else {
             if (isset($_POST['zone_' . $zone['id_zone']]) and $_POST['zone_' . $zone['id_zone']]) {
                 $carrier->addZone($zone['id_zone']);
             }
         }
     }
 }
예제 #24
0
    $results = Db::getInstance()->executeS('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category` c WHERE c.`nleft` < ' . (int) $category->nleft . ' AND c.`nright` > ' . (int) $category->nright . '');
    $output = array();
    foreach ($results as $result) {
        $output[] = $result;
    }
    die(Tools::jsonEncode($output));
}
/* Update attribute */
if (Tools::isSubmit('ajaxUpdateTaxRule')) {
    $id_tax_rule = Tools::getValue('id_tax_rule');
    $tax_rules = new TaxRule((int) $id_tax_rule);
    $output = array();
    foreach ($tax_rules as $key => $result) {
        $output[$key] = $result;
    }
    die(Tools::jsonEncode($output));
}
if (Tools::isSubmit('getZones')) {
    $zones = Zone::getZones();
    $html = '<select id="zone_to_affect" name="zone_to_affect">';
    foreach ($zones as $z) {
        $html .= '<option value="' . $z['id_zone'] . '">' . $z['name'] . '</option>';
    }
    $html .= '</select>';
    $array = array('hasError' => false, 'errors' => '', 'data' => $html);
    die(Tools::jsonEncode($html));
}
function displayJavascriptAlert($s)
{
    echo '<script type="text/javascript">alert(\'' . addslashes($s) . '\');</script>';
}
예제 #25
0
 protected function createCarriers($eta)
 {
     // Sameday(ETA: 18:00)
     foreach ($this->carriers as $key => $value) {
         //Create new carrier
         $carrier = new Carrier();
         $carrier->name = $key;
         $carrier->active = true;
         $carrier->deleted = 0;
         $carrier->shipping_handling = false;
         $carrier->range_behavior = 0;
         $carrier->delay[Configuration::get('PS_LANG_DEFAULT')] = $eta;
         $carrier->shipping_external = true;
         $carrier->is_module = true;
         $carrier->external_module_name = $this->name;
         $carrier->need_range = true;
         $carrier->url = 'https://send24.com/track?@';
         if ($carrier->add()) {
             $groups = Group::getGroups(true);
             foreach ($groups as $group) {
                 Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
             }
             $rangePrice = new RangePrice();
             $rangePrice->id_carrier = $carrier->id;
             $rangePrice->delimiter1 = '0';
             $rangePrice->delimiter2 = '5';
             $rangePrice->add();
             $rangeWeight = new RangeWeight();
             $rangeWeight->id_carrier = $carrier->id;
             $rangeWeight->delimiter1 = '0';
             $rangeWeight->delimiter2 = '5';
             $rangeWeight->add();
             $zones = Zone::getZones(true);
             foreach ($zones as $z) {
                 if ($z['name'] == 'Europe') {
                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $z['id_zone']), 'INSERT');
                     Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
                     Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
                 }
             }
             copy(dirname(__FILE__) . '/views/img/send24.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
             Configuration::updateValue(self::PREFIX . $value, $carrier->id);
             Configuration::updateValue(self::PREFIX . $value . '_reference', $carrier->id);
         }
     }
     return true;
 }
예제 #26
0
    public function displayForm($isMainTab = true)
    {
        global $currentIndex, $cookie;
        parent::displayForm();
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        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/world.gif" />' . $this->l('Countries') . '</legend>
				<label>' . $this->l('Country:') . ' </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="30" 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 style="clear: both">' . $this->l('Name of country') . '</p>
				</div>
				<label>' . $this->l('ISO code:') . ' </label>
				<div class="margin-form">
					<input type="text" size="4" maxlength="3" name="iso_code" value="' . htmlentities($this->getFieldValue($obj, 'iso_code'), ENT_COMPAT, 'UTF-8') . '" style="text-transform: uppercase;" /> <sup>*</sup>
					<p>' . $this->l('2- or 3-letter ISO code, e.g., FR for France') . '. <a href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html" target="_blank">' . $this->l('Official list here') . '</a>.</p>
				</div>
				<label>' . $this->l('Call prefix:') . ' </label>
				<div class="margin-form">
					<input type="text" size="4" maxlength="3" name="call_prefix" value="' . (int) $this->getFieldValue($obj, 'call_prefix') . '" style="text-transform: uppercase;" /> <sup>*</sup>
					<p>' . $this->l('International call prefix, e.g., 33 for France.') . '.</p>
				</div>
				<label>' . $this->l('Default currency:') . ' </label>
				<div class="margin-form">
					<select name="id_currency">
						<option value="0" ' . (Tools::getValue('id_currency', $obj->id_currency) == 0 ? 'selected' : '') . '>' . $this->l('Default store currency') . '</option>
		';
        $currencies = Currency::getCurrencies();
        foreach ($currencies as $currency) {
            echo '<option value="' . intval($currency['id_currency']) . '" ' . (Tools::getValue('id_currency', $obj->id_currency) == $currency['id_currency'] ? 'selected' : '') . '>' . Tools::htmlentitiesUTF8($currency['name']) . '</option>';
        }
        echo '
					</select>
				</div>
				<label>' . $this->l('Zone:') . ' </label>
				<div class="margin-form">
					<select name="id_zone">';
        $zones = Zone::getZones();
        foreach ($zones as $zone) {
            echo '		<option value="' . (int) $zone['id_zone'] . '"' . ($this->getFieldValue($obj, 'id_zone') == $zone['id_zone'] ? ' selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $address_layout = AddressFormat::getAddressCountryFormat($obj->id);
        echo '		</select>
					<p>' . $this->l('Geographical zone where country is located') . '</p>
				</div>
				<label>' . $this->l('Need zip code:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="need_zip_code" id="need_zip_code_on" value="1" onchange="disableZipFormat();" ' . ((!$obj->id or $this->getFieldValue($obj, 'need_zip_code')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_zip_code_on"> <img src="../img/admin/enabled.gif" alt="" title="' . $this->l('Yes') . '" /></label>
					<input type="radio" name="need_zip_code" id="need_zip_code_off" value="0" onchange="disableZipFormat();" ' . ((!$this->getFieldValue($obj, 'need_zip_code') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_zip_code_off"> <img src="../img/admin/disabled.gif" alt="" title="' . $this->l('No') . '" /></label>
				</div>
				<label class="zip_code_format">' . $this->l('Zip code format:') . ' </label>
				<div class="margin-form zip_code_format">
					<input type="text" name="zip_code_format" id="zip_code_format" value="' . $this->getFieldValue($obj, 'zip_code_format') . '" onkeyup="$(\'#zip_code_format\').val($(\'#zip_code_format\').val().toUpperCase());" /> <sup>*</sup>
					<p>' . $this->l('National zip code (L for a letter, N for a number and C for the Iso code), e.g., NNNNN for France. No verification if undefined') . '.</p>
				</div>
				<label class="address_layout">' . $this->l('Address layout:') . ' </label>
				<div class="margin-form" style="vertical-align: top;">
					<p style="float: left;"><textarea id="ordered_fields" name="address_layout" style="width: 300px;height: 120px;">' . $address_layout . '</textarea></p>
					<p style="float: left;margin-left: 10px;"><a href="#" onClick="$(\'textarea#ordered_fields\').val(unescape(\'' . urlencode($address_layout) . '\'.replace(/\\+/g, \' \')));return false;" class="button">' . $this->l('Reset address layout') . '</a></p>					
					<p class="clear">' . $this->l('Possible fields :') . ' ' . implode(', ', Address::getDispFieldsValidate()) . '</p>
				</div>
				<label>' . $this->l('Status:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'active')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="" title="' . $this->l('Enabled') . '" /></label>
					<input type="radio" name="active" id="active_off" value="0" ' . ((!$this->getFieldValue($obj, 'active') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="" title="' . $this->l('Disabled') . '" /></label>
					<p>' . $this->l('Enabled or disabled') . '</p>
				</div>
				<label>' . $this->l('Contains states:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="contains_states" id="contains_states_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'contains_states')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="contains_states_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="contains_states" id="contains_states_off" value="0" ' . ((!$this->getFieldValue($obj, 'contains_states') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="contains_states_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</label>
				</div>
				<label>' . $this->l('Need tax identification number?') . ' </label>
				<div class="margin-form">
					<input type="radio" name="need_identification_number" id="need_identification_number_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'need_identification_number')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_identification_number_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="need_identification_number" id="need_identification_number_off" value="0" ' . ((!$this->getFieldValue($obj, 'need_identification_number') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="need_identification_number_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</label>
				</div>
				<div class="clear"></div>
				<label>' . $this->l('Display tax label:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="display_tax_label" id="display_tax_label_on" value="1" ' . ((!$obj->id or $this->getFieldValue($obj, 'display_tax_label')) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="display_tax_label_on"> <img src="../img/admin/enabled.gif" alt="" title="" />' . $this->l('Yes') . '</label>
					<input type="radio" name="display_tax_label" id="display_tax_label_off" value="0" ' . ((!$this->getFieldValue($obj, 'display_tax_label') and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="display_tax_label_off"> <img src="../img/admin/disabled.gif" alt="" title="" />' . $this->l('No') . '</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>
		<script type="text/javascript">disableZipFormat();</script>';
    }
예제 #27
0
 private function installCarrier($is_COD = 0)
 {
     $carrier = new Carrier();
     $carrier->name = 'Почта России';
     //Проверяем какого перевозчика создаем
     if ($is_COD) {
         $carrier->name .= ' (наложенный платеж)';
     }
     // @deprecated since 1.5.0
     //$carrier->id_tax_rules_group' = 0;
     // TODO: проверить -- это точно обязательно?
     //Способ доставки активен
     $carrier->active = true;
     // TODO: проверить -- это точно обязательно?
     //Не удален. При удалении способа доставки он не удаляется из
     //базы данных, а только помечается как удаленный
     $carrier->deleted = 0;
     // TODO: это может быть интересным -- стоимость упаковки и пр.
     //Доставка и обработка
     $carrier->shipping_handling = false;
     // Что делать, если Out Of Range. 0 -- считать, 1 -- не считать
     // Мы, ведь, сами определяем можем или не можем, настроек range
     // никаких не будет.
     //Исключения: применить наибольшую цену доставки
     $carrier->range_behavior = 0;
     // Тут зависимости от языка
     // TODO: по идее это время доставки, но для разных пунктов
     // оно может сильно отличасться. Посмотреть, можно-ли это как-то
     // динамически править
     $delay_str_list = array('ru' => 'Срок доставки зависит от удаленности', 'default' => 'Delivery time depens on distance');
     $languages = Language::getLanguages(false);
     foreach ($languages as $language) {
         //Проверяем есть ли текущий язык в списке предусмотренных языков
         if (!isset($delay_str_list[$language['iso_code']])) {
             //Если нет, то ставим фразу по умолчанию
             $carrier->delay[(int) $language['id_lang']] = $delay_str_list['default'];
         } else {
             //Иначе берем фразу из конфига
             $carrier->delay[(int) $language['id_lang']] = $delay_str_list[$language['iso_code']];
         }
     }
     // Этот перевозчик связан с модулем
     //Расчет производится из внешнего источника
     $carrier->shipping_external = true;
     //Признак того, что способ доставки принадлежит модулю
     $carrier->is_module = true;
     //Имя модуля, которому принадлежит способ доставки
     $carrier->external_module_name = 'russianpostcarrier';
     // Если я правильно понял, то заданные лимиты
     // нам не уперлись, у нас внутре свои лимиты задаются
     // UPD: Но оно в этом случае, похоже, не работает. Придется задавать лимиты
     $carrier->need_range = true;
     // TODO: еще полезные переменные, мы ими потом займемся,
     // надо понять, как оно считает
     // $carrier->max_width => 1;
     // $carrier->max_height => 1;
     // $carrier->max_depth => 1;
     // $carrier->max_weight => 1; // вот это вот особенно!
     if ($carrier->add()) {
         // Добавим нашего несчастного перевозчика всем группам
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         // Без указания пределов по весу и стоимости оно не заработало
         // Сделаем, хотя оно нам не надо
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '100500';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '100500';
         //Предельные тяжеловесные посылки 20 кг
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $z) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $z['id_zone']), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
         }
         copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
         return $carrier->id;
     }
     return false;
 }
예제 #28
0
 protected function addZones($carrier)
 {
     $zones = Zone::getZones();
     foreach ($zones as $zone) {
         $carrier->addZone($zone['id_zone']);
     }
 }
예제 #29
0
    public function hookAdminStatsModules()
    {
        global $cookie, $currentIndex;
        define('PS_BASE_URI', '/');
        $ru = $currentIndex . '&module=' . $this->name . '&token=' . Tools::getValue('token');
        $db = Db::getInstance();
        if (!isset($cookie->stats_granularity)) {
            $cookie->stats_granularity = 10;
        }
        if (Tools::isSubmit('submitIdZone')) {
            $cookie->stats_id_zone = (int) Tools::getValue('stats_id_zone');
        }
        if (Tools::isSubmit('submitGranularity')) {
            $cookie->stats_granularity = Tools::getValue('stats_granularity');
        }
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $employee = new Employee((int) $cookie->id_employee);
        $from = max(strtotime(_PS_CREATION_DATE_ . ' 00:00:00'), strtotime($employee->stats_date_from . ' 00:00:00'));
        $to = strtotime($employee->stats_date_to . ' 23:59:59');
        $to2 = min(time(), $to);
        $interval = ($to - $from) / 60 / 60 / 24;
        $interval2 = ($to2 - $from) / 60 / 60 / 24;
        $prop30 = $interval / $interval2;
        if ($cookie->stats_granularity == 7) {
            $intervalAvg = $interval2 / 30;
        }
        if ($cookie->stats_granularity == 4) {
            $intervalAvg = $interval2 / 365;
        }
        if ($cookie->stats_granularity == 10) {
            $intervalAvg = $interval2;
        }
        if ($cookie->stats_granularity == 42) {
            $intervalAvg = $interval2 / 7;
        }
        $dataTable = array();
        if ($cookie->stats_granularity == 10) {
            for ($i = $from; $i <= $to2; $i = strtotime('+1 day', $i)) {
                $dataTable[date('Y-m-d', $i)] = array('fix_date' => date('Y-m-d', $i), 'countOrders' => 0, 'countProducts' => 0, 'totalProducts' => 0);
            }
        }
        $dateFromGAdd = $cookie->stats_granularity != 42 ? 'LEFT(date_add, ' . (int) $cookie->stats_granularity . ')' : 'IFNULL(MAKEDATE(YEAR(date_add),DAYOFYEAR(date_add)-WEEKDAY(date_add)), CONCAT(YEAR(date_add),"-01-01*"))';
        $dateFromGInvoice = $cookie->stats_granularity != 42 ? 'LEFT(invoice_date, ' . (int) $cookie->stats_granularity . ')' : 'IFNULL(MAKEDATE(YEAR(invoice_date),DAYOFYEAR(invoice_date)-WEEKDAY(invoice_date)), CONCAT(YEAR(invoice_date),"-01-01*"))';
        $result = $db->ExecuteS('
		SELECT
			' . $dateFromGInvoice . ' as fix_date,
			COUNT(DISTINCT o.id_order) as countOrders,
			SUM(od.product_quantity) as countProducts,
			SUM(od.product_price * od.product_quantity / o.conversion_rate) as totalProducts
		FROM ' . _DB_PREFIX_ . 'orders o
		LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order
		LEFT JOIN ' . _DB_PREFIX_ . 'product p ON od.product_id = p.id_product
		WHERE o.valid = 1
		AND o.invoice_date BETWEEN ' . ModuleGraph::getDateBetween() . '
		GROUP BY ' . $dateFromGInvoice . '
		ORDER BY fix_date', false);
        while ($row = $db->nextRow($result)) {
            $dataTable[$row['fix_date']] = $row;
        }
        $this->_html .= '<div style="float:left;width:660px">
		<fieldset><legend><img src="../modules/' . $this->name . '/logo.gif" /> ' . $this->displayName . '</legend>
			<p style="float:left">' . $this->l('All amounts are without taxes.') . '</p>
			<form id="granularity" action="' . $ru . '#granularity" method="post" style="float:right">
				<input type="hidden" name="submitGranularity" value="1" />
				' . $this->l('Mode:') . ' <select name="stats_granularity" onchange="this.form.submit();" style="width:100px">
					<option value="10">' . $this->l('Day') . '</option>
					<option value="42" ' . ($cookie->stats_granularity == '42' ? 'selected="selected"' : '') . '>' . $this->l('Week') . '</option>
					<option value="7" ' . ($cookie->stats_granularity == '7' ? 'selected="selected"' : '') . '>' . $this->l('Month') . '</option>
					<option value="4" ' . ($cookie->stats_granularity == '4' ? 'selected="selected"' : '') . '>' . $this->l('Year') . '</option>
				</select>
			</form>
			<div class="clear">&nbsp;</div>
			<table class="table" border="0" cellspacing="0" cellspacing="0">
				<tr>
					<th style="width:70px;text-align:center"></th>
					<th style="text-align:center">' . $this->l('Visits') . '</th>
					<th style="text-align:center">' . $this->l('Reg.') . '</th>
					<th style="text-align:center">' . $this->l('Orders') . '</th>
					<th style="text-align:center">' . $this->l('Items') . '</th>
					<th style="text-align:center">' . $this->l('% Reg.') . '</th>
					<th style="text-align:center">' . $this->l('% Orders') . '</th>
					<th style="width:80px;text-align:center">' . $this->l('Coupons') . '</th>
					<th style="width:100px;text-align:center">' . $this->l('Products Sales') . '</th>
				</tr>';
        $visitArray = array();
        $visits = Db::getInstance()->ExecuteS('SELECT ' . $dateFromGAdd . ' as fix_date, COUNT(*) as visits FROM ' . _DB_PREFIX_ . 'connections c WHERE c.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' GROUP BY ' . $dateFromGAdd, false);
        while ($row = $db->nextRow($visits)) {
            $visitArray[$row['fix_date']] = $row['visits'];
        }
        $discountArray = array();
        $discounts = Db::getInstance()->ExecuteS('
		SELECT ' . $dateFromGInvoice . ' as fix_date, SUM(od.value) as total
		FROM ' . _DB_PREFIX_ . 'orders o
		LEFT JOIN ' . _DB_PREFIX_ . 'order_discount od ON o.id_order = od.id_order
		WHERE o.valid = 1
		AND o.total_paid_real > 0
		AND o.invoice_date BETWEEN ' . ModuleGraph::getDateBetween() . '
		GROUP BY ' . $dateFromGInvoice, false);
        while ($row = $db->nextRow($discounts)) {
            $discountArray[$row['fix_date']] = $row['total'];
        }
        $today = date('Y-m-d');
        foreach ($dataTable as $row) {
            $discountToday = isset($discountArray[$row['fix_date']]) ? $discountArray[$row['fix_date']] : 0;
            $visitsToday = (int) (isset($visitArray[$row['fix_date']]) ? $visitArray[$row['fix_date']] : 0);
            $dateFromGReg = $cookie->stats_granularity != 42 ? 'LIKE \'' . $row['fix_date'] . '%\'' : 'BETWEEN \'' . substr($row['fix_date'], 0, 10) . ' 00:00:00\' AND DATE_ADD(\'' . substr($row['fix_date'], 0, 8) . substr($row['fix_date'], 8, 2) . ' 23:59:59\', INTERVAL 7 DAY)';
            $row['registrations'] = Db::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'customer WHERE date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND date_add ' . $dateFromGReg);
            $totalHT = $row['totalProducts'] - $discountToday;
            $this->_html .= '
			<tr>
				<td>' . $row['fix_date'] . '</td>
				<td align="center">' . $visitsToday . '</td>
				<td align="center">' . (int) $row['registrations'] . '</td>
				<td align="center">' . (int) $row['countOrders'] . '</td>
				<td align="center">' . (int) $row['countProducts'] . '</td>
				<td align="center">' . ($visitsToday ? round(100 * (int) $row['registrations'] / $visitsToday, 2) . ' %' : '-') . '</td>
				<td align="center">' . ($visitsToday ? round(100 * (int) $row['countOrders'] / $visitsToday, 2) . ' %' : '-') . '</td>
				<td align="right">' . Tools::displayPrice($discountToday, $currency) . '</td>
				<td align="right" >' . Tools::displayPrice($totalHT, $currency) . '</td>
			</tr>';
            $this->t1 += $visitsToday;
            $this->t2 += (int) $row['registrations'];
            $this->t3 += (int) $row['countOrders'];
            $this->t4 += (int) $row['countProducts'];
            $this->t7 += $discountToday;
            $this->t8 += $totalHT;
        }
        $this->_html .= '
				<tr>
					<th style="width:70px;text-align:center"></th>
					<th style="text-align:center">' . $this->l('Visits') . '</th>
					<th style="text-align:center">' . $this->l('Reg.') . '</th>
					<th style="text-align:center">' . $this->l('Orders') . '</th>
					<th style="text-align:center">' . $this->l('Items') . '</th>
					<th style="text-align:center">' . $this->l('% Reg.') . '</th>
					<th style="text-align:center">' . $this->l('% Orders') . '</th>
					<th style="width:80px;text-align:center">' . $this->l('Coupons') . '</th>
					<th style="width:100px;text-align:center">' . $this->l('Products Sales') . '</th>
				</tr>
				<tr>
					<th>' . $this->l('Total') . '</th>
					<td style="font-weight: 700" align="center">' . (int) $this->t1 . '</td>
					<td style="font-weight: 700" align="center">' . (int) $this->t2 . '</td>
					<td style="font-weight: 700" align="center">' . (int) $this->t3 . '</td>
					<td style="font-weight: 700" align="center">' . (int) $this->t4 . '</td>
					<td style="font-weight: 700" align="center">--</td>
					<td style="font-weight: 700" align="center">--</td>
					<td style="font-weight: 700" align="right">' . Tools::displayPrice($this->t7, $currency) . '</td>
					<td style="font-weight: 700" align="right">' . Tools::displayPrice($this->t8, $currency) . '</td>
				</tr>
				<tr>
					<th>' . $this->l('Average') . '</th>
					<td style="font-weight: 700" align="center">' . (int) ($this->t1 / $intervalAvg) . '</td>
					<td style="font-weight: 700" align="center">' . (int) ($this->t2 / $intervalAvg) . '</td>
					<td style="font-weight: 700" align="center">' . (int) ($this->t3 / $intervalAvg) . '</td>
					<td style="font-weight: 700" align="center">' . (int) ($this->t4 / $intervalAvg) . '</td>
					<td style="font-weight: 700" align="center">' . ($this->t1 ? round(100 * $this->t2 / $this->t1, 2) . ' %' : '-') . '</td>
					<td style="font-weight: 700" align="center">' . ($this->t1 ? round(100 * $this->t3 / $this->t1, 2) . ' %' : '-') . '</td>
					<td style="font-weight: 700" align="right">' . Tools::displayPrice($this->t7 / $intervalAvg, $currency) . '</td>
					<td style="font-weight: 700" align="right">' . Tools::displayPrice($this->t8 / $intervalAvg, $currency) . '</td>
				</tr>
				<tr>
					<th>' . $this->l('Forecast') . '</th>
					<td style="font-weight: 700" align="center">' . (int) ($this->t1 * $prop30) . '</td>
					<td style="font-weight: 700" align="center">' . (int) ($this->t2 * $prop30) . '</td>
					<td style="font-weight: 700" align="center">' . (int) ($this->t3 * $prop30) . '</td>
					<td style="font-weight: 700" align="center">' . (int) ($this->t4 * $prop30) . '</td>
					<td style="font-weight: 700" align="center">--</td>
					<td style="font-weight: 700" align="center">--</td>
					<td style="font-weight: 700" align="right">' . Tools::displayPrice($this->t7 * $prop30, $currency) . '</td>
					<td style="font-weight: 700" align="right">' . Tools::displayPrice($this->t8 * $prop30, $currency) . '</td>
				</tr>
			</table>
		</fieldset>';
        $ca = $this->getRealCA();
        $visitors = Db::getInstance()->getValue('SELECT COUNT(DISTINCT id_guest) FROM ' . _DB_PREFIX_ . 'connections WHERE date_add BETWEEN ' . ModuleGraph::getDateBetween());
        $customers = Db::getInstance()->getValue('SELECT COUNT(DISTINCT id_customer) FROM ' . _DB_PREFIX_ . 'connections c INNER JOIN ' . _DB_PREFIX_ . 'guest g ON c.id_guest = g.id_guest WHERE id_customer != 0 AND c.date_add BETWEEN ' . ModuleGraph::getDateBetween());
        $carts = Db::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'cart WHERE id_cart IN (SELECT id_cart FROM ' . _DB_PREFIX_ . 'cart_product) AND (date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' OR date_upd BETWEEN ' . ModuleGraph::getDateBetween() . ')');
        $fullcarts = Db::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'cart WHERE id_cart IN (SELECT id_cart FROM ' . _DB_PREFIX_ . 'cart_product) AND id_address_invoice != 0 AND (date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' OR date_upd BETWEEN ' . ModuleGraph::getDateBetween() . ')');
        $orders = Db::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 AND date_add BETWEEN ' . ModuleGraph::getDateBetween());
        $this->_html .= '<div class="clear">&nbsp;</div>
		<fieldset><legend><img src="../modules/' . $this->name . '/funnel.png" /> ' . $this->l('Conversion') . '</legend>
			<span style="float:left;text-align:center;margin-right:10px;padding-top:15px">' . $this->l('Visitors') . '<br />' . $visitors . '</span>
			<span style="float:left;text-align:center;margin-right:10px">
				<img src="../modules/' . $this->name . '/next.png"><br />' . round(100 * $customers / max(1, $visitors)) . ' %<br />
				<img src="../modules/' . $this->name . '/next.png"><br />' . round(100 * $carts / max(1, $visitors)) . ' %
			</span>
			<span style="float:left;text-align:center;margin-right:10px">
				' . $this->l('Accounts') . '<br />' . $customers . '<br />
				' . $this->l('Carts') . '<br />' . $carts . '
			</span>
			<span style="float:left;text-align:center;margin-right:10px">
				<img src="../modules/' . $this->name . '/next.png"><br />' . round(100 * $fullcarts / max(1, $customers)) . ' %<br />
				<img src="../modules/' . $this->name . '/next.png"><br />' . round(100 * $fullcarts / max(1, $carts)) . ' %<br />
			</span>
			<span style="float:left;text-align:center;margin-right:10px;padding-top:15px">' . $this->l('Full carts') . '<br />' . $fullcarts . '</span>
			<span style="float:left;text-align:center;margin-right:10px;padding-top:15px"><img src="../modules/' . $this->name . '/next.png"><br />' . round(100 * $orders / max(1, $fullcarts)) . ' %</span>
			<span style="float:left;text-align:center;margin-right:10px;padding-top:15px">' . $this->l('Orders') . '<br />' . $orders . '</span>
			<br class="clear" /><br class="clear" />
			<span style="float:left;text-align:center;margin-right:10px">' . $this->l('Registered visitors') . '</span>
			<span style="float:left;text-align:center;margin-right:10px">
				<img src="../modules/' . $this->name . '/next.png"> ' . round(100 * $orders / max(1, $customers), 2) . ' % <img src="../modules/' . $this->name . '/next.png">
			</span>
			<span style="float:left;text-align:center;margin-right:10px">' . $this->l('Orders') . '</span>
			<br class="clear" />
			<span style="float:left;text-align:center;margin-right:10px">' . $this->l('Visitors') . '</span>
			<span style="float:left;text-align:center;margin-right:10px">
				<img src="../modules/' . $this->name . '/next.png"> <b>' . round(100 * $orders / max(1, $visitors), 2) . ' %</b> <img src="../modules/' . $this->name . '/next.png">
			</span>
			<span style="float:left;text-align:center;margin-right:10px">' . $this->l('Orders') . '</span>
			<div class="clear">&nbsp;</div>
			' . $this->l('Turn your visitors into money:') . '
			<br />' . $this->l('Each visitor yields') . ' <b>' . Tools::displayPrice($ca['ventil']['total'] / max(1, $visitors), $currency) . '.</b>
			<br />' . $this->l('Each registered visitor yields') . ' <b>' . Tools::displayPrice($ca['ventil']['total'] / max(1, $customers), $currency) . '</b>.
		</fieldset>';
        $from = strtotime($employee->stats_date_from . ' 00:00:00');
        $to = strtotime($employee->stats_date_to . ' 23:59:59');
        $interval = ($to - $from) / 60 / 60 / 24;
        $prop5000 = 5000 / 30 * $interval;
        $this->_html .= '
		<div class="clear">&nbsp;</div>';
        $this->_html .= '<fieldset><legend id="payment"><img src="../img/t/AdminPayment.gif" />' . $this->l('Payment distibution') . '</legend>
			<form id="cat" action="' . $ru . '#payment" method="post" style="float:right">
				<input type="hidden" name="submitIdZone" value="1" />
				' . $this->l('Zone:') . ' <select name="stats_id_zone" onchange="this.form.submit();">
					<option value="0">' . $this->l('-- No filter --') . '</option>';
        foreach (Zone::getZones() as $zone) {
            $this->_html .= '<option value="' . (int) $zone['id_zone'] . '" ' . ($cookie->stats_id_zone == $zone['id_zone'] ? 'selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $this->_html .= '</select>
			</form>
			<table class="table float" border="0" cellspacing="0" cellspacing="0">
				<tr><th>' . $this->l('Module') . '</th><th>' . $this->l('Count') . '</th><th>' . $this->l('Total') . '</th><th>' . $this->l('Cart') . '</th></tr>';
        foreach ($ca['payment'] as $payment) {
            $this->_html .= '
					<tr>
						<td>' . $payment['module'] . '</td>
						<td style="text-align:center;padding:4px">' . (int) $payment['nb'] . '<br />' . ($ca['ventil']['nb'] ? number_format(100 * $payment['nb'] / $ca['ventil']['nb'], 1, '.', ' ') : '0') . ' %</td>
						<td style="text-align:center;padding:4px">' . Tools::displayPrice($payment['total'], $currency) . '<br />' . ((double) $ca['ventil']['total'] > 0 ? number_format(100 * $payment['total'] / $ca['ventil']['total'], 1, '.', ' ') : '0') . ' %</td>
						<td style="text-align:center;padding:4px">' . Tools::displayPrice($payment['cart'], $currency) . '</td>
					</tr>';
        }
        $this->_html .= '
			</table>
		</fieldset>
		<div class="clear">&nbsp;</div>
		<fieldset><legend><img src="../img/t/AdminCatalog.gif" /> ' . $this->l('Category distribution') . '</legend>
			<form id="cat" action="' . $ru . '#cat" method="post" style="float:right">
				<input type="hidden" name="submitIdZone" value="1" />
				' . $this->l('Zone:') . ' <select name="stats_id_zone" onchange="this.form.submit();">
					<option value="0">' . $this->l('-- No filter --') . '</option>';
        foreach (Zone::getZones() as $zone) {
            $this->_html .= '<option value="' . (int) $zone['id_zone'] . '" ' . ($cookie->stats_id_zone == $zone['id_zone'] ? 'selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $this->_html .= '	</select>
			</form>
			<table class="table float" border="0" cellspacing="0" cellspacing="0">
				<tr><th style="width:50px">' . $this->l('Category') . '</th><th>' . $this->l('Count') . '</th><th>' . $this->l('Sales') . '</th><th>' . $this->l('% Count') . '</th><th>' . $this->l('% Sales') . '</th><th>' . $this->l('Avg price') . '</th></tr>';
        foreach ($ca['cat'] as $catrow) {
            $this->_html .= '
				<tr>
					<td>' . (empty($catrow['name']) ? $this->l('Unknown') : $catrow['name']) . '</td>
					<td align="right">' . $catrow['orderQty'] . '</td>
					<td align="right">' . Tools::displayPrice($catrow['orderSum'], $currency) . '</td>
					<td align="right">' . number_format(100 * $catrow['orderQty'] / $this->t4, 1, '.', ' ') . '%</td>
					<td align="right">' . ((int) $ca['ventil']['total'] ? number_format(100 * $catrow['orderSum'] / $ca['ventil']['total'], 1, '.', ' ') : '0') . '%</td>
					<td align="right">' . Tools::displayPrice($catrow['priveAvg'], $currency) . '</td>
				</tr>';
        }
        $this->_html .= '
			</table>
		</fieldset>
		<div class="clear">&nbsp;</div>
		<fieldset><legend><img src="../img/t/AdminLanguages.gif" /> ' . $this->l('Language distribution') . '</legend>
			<table class="table" border="0" cellspacing="0" cellspacing="0">
				<tr><th>' . $this->l('Customers') . '</th><th>' . $this->l('Sales') . '</th><th>' . $this->l('%') . '</th><th colspan="2">' . $this->l('Growth') . '</th></tr>';
        foreach ($ca['lang'] as $ophone => $amount) {
            $percent = (int) $ca['langprev'][$ophone] ? number_format(100 * $amount / $ca['langprev'][$ophone] - 100, 1, '.', ' ') : '&#x221e;';
            $this->_html .= '
				<tr ' . ($percent < 0 ? 'class="alt_row"' : '') . '>
					<td>' . $ophone . '</td>
					<td align="right">' . Tools::displayPrice($amount, $currency) . '</td>
					<td align="right">' . ((double) $ca['ventil']['total'] > 0 ? number_format(100 * $amount / $ca['ventil']['total'], 1, '.', ' ') . '%' : '-') . '</td>
					<td>' . (($percent > 0 or $percent == '&#x221e;') ? '<img src="../img/admin/arrow_up.png" />' : '<img src="../img/admin/arrow_down.png" /> ') . '</td>
					<td align="right">' . (($percent > 0 or $percent == '&#x221e;') ? '+' : '') . $percent . '%</td>
				</tr>';
        }
        $this->_html .= '
			</table>
		</fieldset>
		<div class="clear">&nbsp;</div>
		<fieldset><legend><img src="../img/t/AdminLanguages.gif" />' . $this->l('Zone distribution') . '</legend>
			<table class="table" border="0" cellspacing="0" cellspacing="0">
				<tr><th>' . $this->l('Zone') . '</th><th>' . $this->l('Count') . '</th><th>' . $this->l('Total') . '</th><th>' . $this->l('% Count') . '</th><th>' . $this->l('% Sales') . '</th></tr>';
        foreach ($ca['zones'] as $zone) {
            $this->_html .= '
				<tr>
					<td>' . (isset($zone['name']) ? $zone['name'] : $this->l('Undefined')) . '</td>
					<td align="right">' . (int) $zone['nb'] . '</td>
					<td align="right">' . Tools::displayPrice($zone['total'], $currency) . '</td>
					<td align="right">' . ($ca['ventil']['nb'] ? number_format(100 * $zone['nb'] / $ca['ventil']['nb'], 1, '.', ' ') : '0') . '%</td>
					<td align="right">' . ((double) $ca['ventil']['total'] > 0 ? number_format(100 * $zone['total'] / $ca['ventil']['total'], 1, '.', ' ') : '0') . '%</td>
				</tr>';
        }
        $this->_html .= '
			</table>
		</fieldset>
		<div class="clear">&nbsp;</div>
		<fieldset><legend id="currencies"><img src="../img/t/AdminCurrencies.gif" />' . $this->l('Currency distribution') . '</legend>
			<form id="cat" action="' . $ru . '#currencies" method="post" style="float:right">
				<input type="hidden" name="submitIdZone" value="1" />
				' . $this->l('Zone:') . ' <select name="stats_id_zone" onchange="this.form.submit();">
					<option value="0">' . $this->l('-- No filter --') . '</option>';
        foreach (Zone::getZones() as $zone) {
            $this->_html .= '<option value="' . (int) $zone['id_zone'] . '" ' . ($cookie->stats_id_zone == $zone['id_zone'] ? 'selected="selected"' : '') . '>' . $zone['name'] . '</option>';
        }
        $this->_html .= '</select>
			</form>
			<table class="table" border="0" cellspacing="0" cellspacing="0">
				<tr><th>' . $this->l('Currency') . '</th><th>' . $this->l('Count') . '</th><th>' . $this->l('Sales (converted)') . '</th><th>' . $this->l('% Count') . '</th><th>' . $this->l('% Sales') . '</th></tr>';
        foreach ($ca['currencies'] as $currencyRow) {
            $this->_html .= '
					<tr>
						<td>' . $currencyRow['name'] . '</td>
						<td align="right">' . (int) $currencyRow['nb'] . '</td>
						<td align="right">' . Tools::displayPrice($currencyRow['total'], $currency) . '</td>
						<td align="right">' . ($ca['ventil']['nb'] ? number_format(100 * $currencyRow['nb'] / $ca['ventil']['nb'], 1, '.', ' ') : '0') . '%</td>
						<td align="right">' . ((double) $ca['ventil']['total'] > 0 ? number_format(100 * $currencyRow['total'] / $ca['ventil']['total'], 1, '.', ' ') : '0') . '%</td>
					</tr>';
        }
        $this->_html .= '
			</table>
		</fieldset>
		<div class="clear">&nbsp;</div>
		<fieldset><legend><img src="../img/t/AdminCatalog.gif" />' . $this->l('Attribute distribution') . '</legend>
			<table class="table" border="0" cellspacing="0" cellspacing="0">
				<tr><th>' . $this->l('Group') . '</th><th>' . $this->l('Attribute') . '</th><th>' . $this->l('Count') . '</th></tr>';
        foreach ($ca['attributes'] as $attribut) {
            $this->_html .= '
				<tr>
					<td>' . $attribut['gname'] . '</td>
					<td>' . $attribut['aname'] . '</td>
					<td align="right">' . (int) $attribut['total'] . '</td>
				</tr>';
        }
        $this->_html .= '</table>
		</fieldset>
		</div>';
        return $this->_html;
    }
 public function renderForm()
 {
     $this->fields_form = array('legend' => array('title' => $this->l('States'), 'icon' => 'icon-globe'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'maxlength' => 32, 'required' => true, 'hint' => $this->l('Provide the State name to be display in addresses and on invoices.')), array('type' => 'text', 'label' => $this->l('ISO code'), 'name' => 'iso_code', 'maxlength' => 7, 'required' => true, 'class' => 'uppercase', 'hint' => $this->l('1 to 4 letter ISO code.') . ' ' . $this->l('You can prefix it with the country ISO code if needed.')), array('type' => 'select', 'label' => $this->l('Country'), 'name' => 'id_country', 'required' => true, 'default_value' => (int) $this->context->country->id, 'options' => array('query' => Country::getCountries($this->context->language->id, false, true), 'id' => 'id_country', 'name' => 'name'), 'hint' => $this->l('Country where the state is located.') . ' ' . $this->l('Only the countries with the option "contains states" enabled are displayed.')), array('type' => 'select', 'label' => $this->l('Zone'), 'name' => 'id_zone', 'required' => true, 'options' => array('query' => Zone::getZones(), 'id' => 'id_zone', 'name' => 'name'), 'hint' => array($this->l('Geographical region where this state is located.'), $this->l('Used for shipping'))), array('type' => 'switch', 'label' => $this->l('Status'), 'name' => 'active', 'required' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'active_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />')))), 'submit' => array('title' => $this->l('Save')));
     return parent::renderForm();
 }