/** * Формирует HTML-код пользовательского элемента управления с идентификатором 'WeightCosts'. * * @see waHtmlControl::getControl() * @param string $name Идентификатор элемента управления, указанный в файле настроек * @param array $params Параметры элемента управления, указанные в файле настроек * @return string HTML-код элемента управления */ public static function settingWeightCosts($name, $params = array()) { foreach ($params as $field => $param) { if (strpos($field, 'wrapper')) { unset($params[$field]); } } $control = ''; if (!isset($params['value']) || !is_array($params['value'])) { $params['value'] = array(); } $costs = $params['value']; waHtmlControl::addNamespace($params, $name); $control .= '<table class="zebra">'; $params['description_wrapper'] = '%s'; $currency = waCurrency::getInfo('RUB'); $params['title_wrapper'] = '%s'; $params['control_wrapper'] = '<tr title="%3$s"><td>%1$s</td><td>→</td><td>%2$s ' . $currency['sign'] . '</td></tr>'; $params['size'] = 6; for ($zone = 1; $zone <= 5; $zone++) { $params['value'] = floatval(isset($costs[$zone]) ? $costs[$zone] : 0.0); $params['title'] = "Пояс {$zone}"; $control .= waHtmlControl::getControl(waHtmlControl::INPUT, $zone, $params); } $control .= "</table>"; return $control; }
public static function getTypes($currencies) { $result = array('%' => _w('% Discount')); foreach ($currencies as $c) { $info = waCurrency::getInfo($c['code']); $result[$c['code']] = $info['sign'] . ' ' . $c['code']; } $result['$FS'] = _w('Free shipping'); return $result; }
public function execute() { $asm = new waAppSettingsModel(); if (waRequest::post()) { $conf = waRequest::post('conf'); if ($conf && is_array($conf)) { $conf['affiliate_credit_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_credit_rate'], '0'))); $conf['affiliate_usage_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_usage_rate'], '0'))); foreach ($conf as $k => $v) { $asm->set('shop', $k, $v); } } } $enabled = shopAffiliate::isEnabled(); $def_cur = waCurrency::getInfo(wa()->getConfig()->getCurrency()); $tm = new shopTypeModel(); $product_types = $tm->getAll(); $conf = $asm->get('shop'); if (!empty($conf['affiliate_product_types'])) { $conf['affiliate_product_types'] = array_fill_keys(explode(',', $conf['affiliate_product_types']), true); } else { $conf['affiliate_product_types'] = array(); } $this->view->assign('conf', $conf); $this->view->assign('enabled', $enabled); $this->view->assign('product_types', $product_types); $this->view->assign('def_cur_sym', ifset($def_cur['sign'], wa()->getConfig()->getCurrency())); /** * Backend affiliate settings * * Plugins are expected to return one item or a list of items to to add to affiliate menu. * Each item is represented by an array: * array( * 'id' => string, // Required. * 'name' => string, // Required. * 'url' => string, // Required (unless you hack into JS using 'html' parameter). Content for settings page is fetched from this URL. * ) * * @event backend_settings_discounts */ $plugins = wa()->event('backend_settings_affiliate'); $config = wa('shop')->getConfig(); foreach ($plugins as $k => &$p) { if (substr($k, -7) == '-plugin') { $plugin_id = substr($k, 0, -7); $plugin_info = $config->getPluginInfo($plugin_id); $p['img'] = $plugin_info['img']; } } $this->view->assign('plugins', $plugins); $this->view->assign('installer', $this->getUser()->getRights('installer', 'backend')); }
public function execByType($type) { $dbsm = new shopDiscountBySumModel(); if (waRequest::post()) { $sums = waRequest::post('rate_sum'); $discounts = waRequest::post('rate_discount'); $rows = array(); $dbsm->deleteByField('type', $type); if (is_array($sums) && is_array($discounts)) { foreach ($sums as $k => $sum) { $sum = str_replace(',', '.', $sum); if (!is_numeric($sum) || $sum < 0) { continue; } $discount = (double) str_replace(',', '.', ifset($discounts[$k], 0)); $discount = min(max($discount, 0), 100); if ($sum || $discount) { $rows[] = array('sum' => $sum, 'discount' => $discount, 'type' => $type); } } if ($rows) { $dbsm->multipleInsert($rows); } } } $enabled = shopDiscounts::isEnabled($type); $def_cur = waCurrency::getInfo(wa()->getConfig()->getCurrency()); $rates = $dbsm->getByType($type); foreach ($rates as &$r) { $r['sum'] = (double) $r['sum']; $r['discount'] = (double) $r['discount']; } $this->view->assign('rates', $rates); $this->view->assign('enabled', $enabled); $this->view->assign('def_cur_sym', ifset($def_cur['sign'], wa()->getConfig()->getCurrency())); }
public function getCurrencyHtml() { $info = waCurrency::getInfo($this->currency); return ifset($info['sign_html'], $info['sign']); }
protected function getCurrencyInfo() { $currency = waCurrency::getInfo($this->getConfig()->getCurrency(false)); $locale = waLocale::getInfo(wa()->getLocale()); return array('code' => $currency['code'], 'sign' => $currency['sign'], 'sign_html' => !empty($currency['sign_html']) ? $currency['sign_html'] : $currency['sign'], 'sign_position' => isset($currency['sign_position']) ? $currency['sign_position'] : 1, 'sign_delim' => isset($currency['sign_delim']) ? $currency['sign_delim'] : ' ', 'decimal_point' => $locale['decimal_point'], 'frac_digits' => $locale['frac_digits'], 'thousands_sep' => $locale['thousands_sep']); }
/** * Format amount according to currency settings and current locale settings. * * TODO: document format string specifications. For now, see unit tests for some usage clues. * * @param string $format * @param float $n amount to format * @param string $currency 3-letter iso code * @param string $locale */ public static function format($format, $n, $currency, $locale = null) { $old_locale = waSystem::getInstance()->getLocale(); if ($locale === null) { $locale = $old_locale; } $currency = waCurrency::getInfo($currency); if ($format == '%w' || $format == '%W') { if ($locale !== $old_locale) { wa()->setLocale($locale); } waLocale::loadByDomain('webasyst', $locale); } $locale = waLocale::getInfo($locale); $result = preg_replace('/%([0-9]?\\.?[0-9]?)([iw]*)({[n|f|c|s][0-9]?})?/ie', 'self::extract($n, $currency, $locale, "$1", "$2", "$3")', $format); if ($locale !== $old_locale) { wa()->setLocale($old_locale); } return $result; }
public function currency($full_info = false) { $currency = $this->wa->getConfig()->getCurrency(false); if ($full_info) { return waCurrency::getInfo($currency); } else { return $currency; } }
/** * Format amount according to currency settings and current locale settings. * * TODO: document format string specifications. For now, see unit tests for some usage clues. * * @param string $format * @param float $n amount to format * @param string $currency 3-letter iso code * @param string $locale */ public static function format($format, $n, $currency, $locale = null) { $old_locale = waSystem::getInstance()->getLocale(); if ($locale === null) { $locale = $old_locale; } if ($locale !== $old_locale) { wa()->setLocale($locale); } $currency = waCurrency::getInfo($currency); waLocale::loadByDomain('webasyst', $locale); $locale = waLocale::getInfo($locale); self::$data['n'] = $n; self::$data['locale'] = $locale; self::$data['currency'] = $currency; $pattern = '/%([0-9]?\\.?[0-9]?)([iw]*)({[n|f|c|s][0-9]?})?/i'; $result = preg_replace_callback($pattern, array('self', 'replace_callback'), $format); if ($locale !== $old_locale) { wa()->setLocale($old_locale); } return $result; }