public function getSettingsHTML($params = array()) { $values = $this->getSettings(); if (!empty($params['value'])) { $values = array_merge($values, $params['value']); } $view = wa()->getView(); $cm = new waCountryModel(); $view->assign('countires', $cm->all()); if (!empty($values['country'])) { $rm = new waRegionModel(); $view->assign('regions', $rm->getByCountry($values['country'])); } $namespace = ''; if (!empty($params['namespace'])) { if (is_array($params['namespace'])) { $namespace = array_shift($params['namespace']); while (($namspace_chunk = array_shift($params['namespace'])) !== null) { $namespace .= "[{$namspace_chunk}]"; } } else { $namespace = $params['namespace']; } } $view->assign('namespace', $namespace); $view->assign('values', $values); $view->assign('p', $this); $view->assign('xhr_url', wa()->getAppUrl('webasyst') . '?module=backend&action=regions'); $html = $view->fetch($this->path . '/templates/settings.html'); $html .= parent::getSettingsHTML($params); return $html; }
/** * Example of direct usage HTML templates instead waHtmlControl * (non-PHPdoc) * @see waShipping::getSettingsHTML() */ public function getSettingsHTML($params = array()) { $values = $this->getSettings(); if (!empty($params['value'])) { $values = array_merge($values, $params['value']); } $view = wa()->getView(); $app_config = wa()->getConfig(); if (method_exists($app_config, 'getCurrencies')) { $view->assign('currencies', $app_config->getCurrencies()); } $namespace = ''; if (!empty($params['namespace'])) { if (is_array($params['namespace'])) { $namespace = array_shift($params['namespace']); while (($namspace_chunk = array_shift($params['namespace'])) !== null) { $namespace .= "[{$namspace_chunk}]"; } } else { $namespace = $params['namespace']; } } $view->assign('namespace', $namespace); $view->assign('values', $values); $view->assign('p', $this); $html = ''; $html .= $view->fetch($this->path . '/templates/settings.html'); $html .= parent::getSettingsHTML($params); return $html; }
protected function init() { $autoload = waAutoload::getInstance(); foreach (array('uspsLabelsExpressMailQuery', 'uspsLabelsInternationalShippingQuery', 'uspsLabelsUspsTrackingQuery', 'uspsLabelsQuery', 'uspsLabelsSignatureConfirmationQuery', 'uspsQuery', 'uspsRatingsQuery', 'uspsServices', 'uspsTrackingQuery') as $class_name) { $autoload->add($class_name, "wa-plugins/shipping/usps/lib/classes/{$class_name}.class.php"); } parent::init(); }
/** * @see waShipping::getSettingsHTML() * @param array $params * @return string HTML */ public function getSettingsHTML($params = array()) { $params += array('translate' => array(&$this, '_w')); $values = $this->getSettings(); if (!empty($params['value'])) { $values = array_merge($values, $params['value']); } if (!$values['rate_zone']['country']) { $l = substr(wa()->getUser()->getLocale(), 0, 2); if ($l == 'ru') { $values['rate_zone']['country'] = 'rus'; $values['rate_zone']['region'] = '77'; $values['city'] = ''; } else { $values['rate_zone']['country'] = 'usa'; } } $view = wa()->getView(); $cm = new waCountryModel(); $view->assign('countries', $cm->all()); if (!empty($values['rate_zone']['country'])) { $rm = new waRegionModel(); $view->assign('regions', $rm->getByCountry($values['rate_zone']['country'])); } if (!empty($values['rate'])) { self::sortRates($values['rate']); if ($values['rate_by'] == 'price') { $values['rate'] = array_reverse($values['rate']); } } else { $values['rate'] = array(); $values['rate'][] = array('limit' => 0, 'cost' => 0.0); } $app_config = wa()->getConfig(); if (method_exists($app_config, 'getCurrencies')) { $view->assign('currencies', $app_config->getCurrencies()); } $namespace = ''; if (!empty($params['namespace'])) { if (is_array($params['namespace'])) { $namespace = array_shift($params['namespace']); while (($namespace_chunk = array_shift($params['namespace'])) !== null) { $namespace .= "[{$namespace_chunk}]"; } } else { $namespace = $params['namespace']; } } $view->assign('namespace', $namespace); $view->assign('values', $values); $view->assign('p', $this); $html = ''; $view->assign('xhr_url', wa()->getAppUrl('webasyst') . '?module=backend&action=regions'); $view->assign('map_adapters', wa()->getMapAdapters()); $html .= $view->fetch($this->path . '/templates/settings.html'); $html .= parent::getSettingsHTML($params); return $html; }
protected function getTotalWeight() { $w = parent::getTotalWeight(); if ($w === null) { return $this->min_weight; } else { return max($w, $this->min_weight); } }
protected function getItems() { $items = parent::getItems(); foreach ($items as &$item) { if (empty($item['weight'])) { $item['weight'] = $this->min_weight; } } $this->setItems($items); return $items; }
public function execute() { $params = waRequest::request(); $params['result'] = true; $module_id = waRequest::param('module_id'); $result = waShipping::execCallback($params, $module_id); if (!empty($result['template'])) { $this->template = $result['template']; } $this->view->assign('params', $params); $this->view->assign('result', $result); }
/** * Несмотря на название это, видимо, валидатор сохраняемых значений * конфигурации. Во всяком случае то, что он возвращает сохраняется * в БД. * * Название ПВЗ не можеь быть пустым. Потомушта. * * @todo Проверять, чтоб страна и регион были указаны * * @param array $settings * @return array * @throws waException Если данные не прошли проверку */ public function saveSettings($settings = array()) { foreach ($settings['rate'] as $index => $item) { if (!isset($item['location']) || empty($item['location'])) { throw new waException(_w('Pick-up point name cannot be empty')); } $settings['rate'][$index]['cost'] = isset($item['cost']) ? str_replace(',', '.', floatval($item['cost'])) : "0"; $settings['rate'][$index]['maxweight'] = isset($item['maxweight']) ? str_replace(',', '.', floatval($item['maxweight'])) : "0"; $settings['rate'][$index]['free'] = isset($item['free']) ? str_replace(',', '.', floatval($item['free'])) : "0"; } return parent::saveSettings($settings); }
/** * Предварительная подготовка данных для сохранения настроек с помощью метода saveSettings() базового класса waSystemPlugin. * * @see waSystemPlugin::saveSettings() */ public function saveSettings($settings = array()) { $fields = array('halfkilocost', 'overhalfkilocost'); foreach ($fields as $field) { if (ifempty($settings[$field])) { foreach ($settings[$field] as &$value) { if (strpos($value, ',') !== false) { $value = str_replace(',', '.', $value); } $value = str_replace(',', '.', (double) $value); } unset($value); } } return parent::saveSettings($settings); }
public function getSettingsHTML($params = array()) { $model = new waRegionModel(); if (!isset($params['options'])) { $params['options'] = array(); } $params['options']['region'] = array(); foreach ($model->getByCountry('rus') as $region) { $params['options']['region'][$region['code']] = $region['name']; } return parent::getSettingsHTML($params); }
protected function getCustomFields($id, waShipping $plugin) { $contact = $this->getContact(); $order_params = $this->getSessionData('params', array()); $shipping_params = isset($order_params['shipping']) ? $order_params['shipping'] : array(); foreach ($shipping_params as $k => $v) { $order_params['shipping_params_' . $k] = $v; } $order = new waOrder(array('contact' => $contact, 'contact_id' => $contact ? $contact->getId() : null, 'params' => $order_params)); $custom_fields = $plugin->customFields($order); if (!$custom_fields) { return $custom_fields; } $params = array(); $params['namespace'] = 'shipping_' . $id; $params['title_wrapper'] = '%s'; $params['description_wrapper'] = '<br><span class="hint">%s</span>'; $params['control_wrapper'] = '<div class="wa-name">%s</div><div class="wa-value">%s %s</div>'; $selected_shipping = $this->getSessionData('shipping'); $selected = $selected_shipping ? $id == $selected_shipping['id'] : false; $controls = array(); foreach ($custom_fields as $name => $row) { $row = array_merge($row, $params); if ($selected && isset($shipping_params[$name])) { $row['value'] = $shipping_params[$name]; } $controls[$name] = waHtmlControl::getControl($row['control_type'], $name, $row); } return $controls; }
public static function getList() { if (!class_exists('waShipping')) { throw new waException(_w('Shipping plugins not installed yet')); } return waShipping::enumerate(); }
protected function init() { $this->cities = (include $this->path . '/lib/config/data/cities.php'); parent::init(); }