protected function getOptionFields() { $forms = array(); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $carriers = Carrier::getCarriers($this->context->language->id, true); $modules = Module::getModulesOnDisk(true); $forms = array('payment' => array('title' => $this->l('Average bank fees per payment method'), 'id' => 'payment'), 'carriers' => array('title' => $this->l('Average shipping fees per shipping method'), 'id' => 'carriers'), 'other' => array('title' => $this->l('Other settings'), 'id' => 'other')); foreach ($forms as &$form) { $form['icon'] = 'tab-preferences'; $form['fields'] = array(); $form['submit'] = array('title' => $this->l('Save')); } foreach ($modules as $module) { if (isset($module->tab) && $module->tab == 'payments_gateways' && $module->id) { $moduleClass = Module::getInstanceByName($module->name); if (!$moduleClass->isEnabledForShopContext()) { continue; } $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_FIXED'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a fixed fee for each order placed in %1$s with %2$s.'), $currency->iso_code, $module->displayName), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => $currency->iso_code); $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_VAR'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a variable fee for each order placed in %1$s with %2$s. It will be applied on the total paid with taxes.'), $currency->iso_code, $module->displayName), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); if (Currency::isMultiCurrencyActivated()) { $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_FIXED_FOREIGN'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a fixed fee for each order placed with a foreign currency with %s.'), $module->displayName), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => $currency->iso_code); $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_VAR_FOREIGN'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a variable fee for each order placed with a foreign currency with %s. It will be applied on the total paid with taxes.'), $module->displayName), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); } } } foreach ($carriers as $carrier) { $forms['carriers']['fields']['CONF_' . strtoupper($carrier['id_reference']) . '_SHIP'] = array('title' => $carrier['name'], 'desc' => sprintf($this->l('For the carrier named %s, indicate the domestic delivery costs in percentage of the price charged to customers.'), $carrier['name']), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); $forms['carriers']['fields']['CONF_' . strtoupper($carrier['id_reference']) . '_SHIP_OVERSEAS'] = array('title' => $carrier['name'], 'desc' => sprintf($this->l('For the carrier named %s, indicate the overseas delivery costs in percentage of the price charged to customers.'), $carrier['name']), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); } $forms['carriers']['description'] = $this->l('Method: Indicate the percentage of your carrier margin. For example, if you charge $10 of shipping fees to your customer for each shipment, but you really pay $4 to this carrier, then you should indicate "40" in the percentage field.'); $forms['other']['fields']['CONF_AVERAGE_PRODUCT_MARGIN'] = array('title' => $this->l('Average gross margin'), 'desc' => $this->l('You should calculate this percentage as follows: ((total sales revenue) - (cost of goods sold)) / (total sales revenue) * 100. This value is only used to calculate the Dashboard approximate gross margin, if you do not specify the wholesale price for each product.'), 'validation' => 'isPercentage', 'cast' => 'intval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); $forms['other']['fields']['CONF_ORDER_FIXED'] = array('title' => $this->l('Other fees per order'), 'desc' => $this->l('You should calculate this value by making the sum of all of your additional costs per order.'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => $currency->iso_code); return $forms; }
protected function getOptionFields() { $forms = array(); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $carriers = Carrier::getCarriers($this->context->language->id, true); $modules = Module::getModulesOnDisk(true); $forms = array('payment' => array('title' => $this->l('Average bank fees per payment method'), 'id' => 'payment'), 'carriers' => array('title' => $this->l('Average shipping fees per shipping method'), 'id' => 'carriers'), 'other' => array('title' => $this->l('Other settings'), 'id' => 'other'), 'expenses' => array('title' => $this->l('Other expenses (monthly)'), 'id' => 'expenses')); foreach ($forms as &$form) { $form['icon'] = 'tab-preferences'; $form['fields'] = array(); $form['submit'] = array('title' => $this->l('Save')); } foreach ($modules as $module) { if ($module->tab == 'payments_gateways' && $module->id) { $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_FIXED'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a fixed fee for each order placed in %1$s with %2$s.'), $currency->iso_code, $module->displayName), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => $currency->iso_code); $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_VAR'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a variable fee for each order placed in %1$s with %2$s. It will be applied on the total paid with taxes.'), $currency->iso_code, $module->displayName), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); if (Currency::isMultiCurrencyActivated()) { $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_FIXED_FOREIGN'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a fixed fee for each order placed with a foreign currency with %s.'), $module->displayName), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => $currency->iso_code); $forms['payment']['fields']['CONF_' . strtoupper($module->name) . '_VAR_FOREIGN'] = array('title' => $module->displayName, 'desc' => sprintf($this->l('Choose a variable fee for each order placed with a foreign currency with %s. It will be applied on the total paid with taxes.'), $module->displayName), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); } } } foreach ($carriers as $carrier) { $forms['carriers']['fields']['CONF_' . strtoupper($carrier['id_reference']) . '_SHIP'] = array('title' => $carrier['name'], 'desc' => sprintf($this->l('%% of what you charged the customer for domestic delivery with %s.'), $carrier['name']), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); $forms['carriers']['fields']['CONF_' . strtoupper($carrier['id_reference']) . '_SHIP_OVERSEAS'] = array('title' => $carrier['name'], 'desc' => sprintf($this->l('%% of what you charged the customer for overseas delivery with %s.'), $carrier['name']), 'validation' => 'isPercentage', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); } $forms['other']['fields']['CONF_AVERAGE_PRODUCT_MARGIN'] = array('title' => $this->l('Average gross margin (Selling price / Buying price)'), 'desc' => $this->l('Only used if you do not specify your buying price for each product.'), 'validation' => 'isPercentage', 'cast' => 'intval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => '%'); $forms['other']['fields']['CONF_ORDER_FIXED'] = array('title' => $this->l('Other fee per order'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => $currency->iso_code); $expense_types = array('hosting' => $this->l('Hosting'), 'tools' => $this->l('Tools (E-mailing, etc.)'), 'acounting' => $this->l('Accounting'), 'development' => $this->l('Development'), 'marketing' => $this->l('Marketing (Adwords, etc.)'), 'others' => $this->l('Others')); foreach ($expense_types as $expense_type => $expense_label) { $forms['expenses']['fields']['CONF_MONTHLY_' . strtoupper($expense_type)] = array('title' => $expense_label, 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'text', 'defaultValue' => '0', 'suffix' => $currency->iso_code); } return $forms; }
public function renderWidget($hookName, array $configuration) { if (Configuration::isCatalogMode() || !Currency::isMultiCurrencyActivated()) { return false; } if (!$this->isCached($this->templateFile, $this->getCacheId('ps_currencyselector'))) { $this->smarty->assign($this->getWidgetVariables($hookName, $configuration)); } return $this->fetch($this->templateFile, $this->getCacheId('ps_currencyselector')); }
private function _prepareHook($params) { if (Configuration::get('PS_CATALOG_MODE')) { return false; } if (!Currency::isMultiCurrencyActivated()) { return false; } $this->smarty->assign('blockcurrencies_sign', $this->context->currency->sign); return true; }
protected function getCacheId($name = null) { $cache_array = array(); $cache_array[] = $name !== null ? $name : $this->name; if (Configuration::get('PS_SSL_ENABLED')) { $cache_array[] = (int) Tools::usingSecureMode(); } if (Shop::isFeatureActive()) { $cache_array[] = (int) $this->context->shop->id; } $cache_array[] = (int) Group::getCurrent()->id; if (Language::isMultiLanguageActivated()) { $cache_array[] = (int) $this->context->language->id; } if (Currency::isMultiCurrencyActivated()) { $cache_array[] = (int) $this->context->currency->id; } $cache_array[] = (int) $this->context->country->id; return implode('|', $cache_array); }
/** * use this code * Configuration::updateValue('LEO_CURRENT_RANDOM_CACHE', '1'); * where you want to have RANDOM cache */ protected function getCacheId($name = null) { $cache_array = array(); $cache_array[] = $name !== null ? $name : $this->name; if (isset($this->cache_param) && $this->cache_param) { if (isset($this->cache_param['controller']) && $this->cache_param['controller']) { $cache_array[] = $this->cache_param['controller']; } if (isset($this->cache_param['id']) && $this->cache_param['id']) { $cache_array[] = $this->cache_param['id']; } if (isset($this->cache_param['hook']) && $this->cache_param['hook']) { $cache_array[] = $this->cache_param['hook']; } // save to next time if (Configuration::get('LEO_CURRENT_RANDOM_CACHE') == 1) { $random_cache = Configuration::get('LEO_RANDOM_CACHE'); if (!$random_cache) { # validate module $random_cache = new stdClass(); } else { # validate module $random_cache = Tools::jsonDecode($random_cache); } $key = implode('|', $cache_array); $random_cache->{$key} = date('Ymd'); $leo_random_cache = Tools::jsonEncode($random_cache); Configuration::updateValue('LEO_RANDOM_CACHE', $leo_random_cache); } // Check RANDOM PRODUCT if ($random_cache = Configuration::get('LEO_RANDOM_CACHE')) { $key = implode('|', $cache_array); $value = date('Ymd'); $random_cache = Tools::jsonDecode($random_cache); if (isset($random_cache->{$key}) && $random_cache->{$key} == $value) { // cache in one day $random = date('Ymd') . '_' . rand(1, LeomanagewidgetsHelper::NUMBER_CACHE_FILE); $cache_array[] = 'random_' . $random; } } } if (Configuration::get('PS_SSL_ENABLED')) { $cache_array[] = (int) Tools::usingSecureMode(); } if (Shop::isFeatureActive()) { $cache_array[] = (int) $this->context->shop->id; } if (Group::isFeatureActive()) { $cache_array[] = (int) Group::getCurrent()->id; } if (Language::isMultiLanguageActivated()) { $cache_array[] = (int) $this->context->language->id; } if (Currency::isMultiCurrencyActivated()) { $cache_array[] = (int) $this->context->currency->id; } $cache_array[] = (int) $this->context->country->id; return implode('|', $cache_array); }