public static function setRestrictions($id) { $countries = CountryCore::getCountries(Context::getContext()->language->id); if (version_compare(_PS_VERSION_, '1.5', '>=')) { $restrictions = Db::getInstance()->executeS('SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country WHERE id_module=' . $id . ' AND id_shop=' . Context::getContext()->shop->id); } else { $restrictions = Db::getInstance()->executeS('SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country WHERE id_module=' . $id); } $rlist = array(); foreach ($restrictions as $r) { $rlist[] = $r['id_country']; } $values = array(); while (($val = current($countries)) !== false) { if (!in_array(key($val), $rlist)) { if (version_compare(_PS_VERSION_, '1.5', '>=')) { $values[] = '(' . (int) $id . ', ' . (int) Context::getContext()->shop->id . ', ' . (int) key($val) . ')'; } else { $values[] = '(' . (int) $id . ', ' . (int) key($val) . ')'; } } next($countries); } if (!empty($values)) { if (version_compare(_PS_VERSION_, '1.5', '>=')) { Db::getInstance()->execute(' INSERT IGNORE INTO `' . _DB_PREFIX_ . 'module_country` (`id_module`, `id_shop`, `id_country`) VALUES ' . implode(',', $values)); } } return true; }
public function renderForm() { $enable_values = array(array('id' => 0, 'name' => 'No'), array('id' => 1, 'name' => 'Yes')); $countries = CountryCore::getCountries($this->context->language->id); $all_states = StateCore::getStates($this->context->language->id); $states = array(); foreach ($all_states as $row) { $states[$row['id_country']][] = $row; } $empty_states = array(array('id_state' => 0, 'name' => '-')); $order_state = OrderState::getOrderStates($this->context->language->id); $fields_form = array('form' => array('legend' => array('title' => $this->l('Contact details'), 'icon' => 'icon-envelope'), 'input' => array(array('type' => 'hidden', 'name' => 'secureKey'), array('type' => 'select', 'label' => $this->l('Enable'), 'name' => 'SHIPTOMYID_ENABLE', 'options' => array('query' => $enable_values, 'id' => 'id', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Ship2MyId username'), 'name' => 'SHIPTOMYID_USERNAME', 'size' => 64), array('type' => 'password', 'label' => $this->l('Ship2MyId password'), 'name' => 'SHIPTOMYID_PASSWORD', 'size' => 64), array('type' => 'text', 'label' => $this->l('Webservice URL'), 'name' => 'SHIPTOMYID_WEBSERVICE_URL', 'size' => 64), array('type' => 'text', 'label' => $this->l('Terms URL'), 'name' => 'SHIPTOMYID_TERMS_URL', 'size' => 64), array('type' => 'text', 'label' => $this->l('Privacy policy URL'), 'name' => 'SHIPTOMYID_PRIVACY_URL', 'size' => 64), array('type' => 'text', 'label' => $this->l('Ship2MyId video link'), 'name' => 'SHIPTOMYID_VIDEO_LINK', 'size' => 64), array('type' => 'text', 'label' => $this->l('Default street address'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_ADDRESS', 'size' => 64), array('type' => 'text', 'label' => $this->l('Default stree address (line 2)'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_ADDRESS2', 'size' => 64), array('type' => 'text', 'label' => $this->l('Default City'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_CITY', 'size' => 64), array('type' => 'select', 'label' => $this->l('Default region/state'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_STATE', 'options' => array('query' => $empty_states, 'id' => 'id_state', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Default zip/postal code'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_POSTCODE', 'size' => 64), array('type' => 'select', 'label' => $this->l('Default Country'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_COUNTRY', 'options' => array('query' => $countries, 'id' => 'id_country', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Default phone number'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_PHONE', 'size' => 64), array('type' => 'text', 'label' => $this->l('Ship2MyId label'), 'name' => 'SHIPTOMYID_DEFAULT_ADDR_ALIAS', 'size' => 64), array('type' => 'text', 'label' => $this->l('Webservice popup URL'), 'name' => 'SHIPTOMYID_POPUP_URL', 'size' => 64), array('type' => 'text', 'label' => $this->l('Webservice popup width'), 'name' => 'SHIPTOMYID_POPUP_WIDTH', 'size' => 64), array('type' => 'text', 'label' => $this->l('Webservice popup height'), 'name' => 'SHIPTOMYID_POPUP_HEIGHT', 'size' => 64), array('type' => 'select', 'label' => $this->l('Rejected order status'), 'name' => 'SHIPTOMYID_CANCEL_ORDER_STATE', 'options' => array('query' => $order_state, 'id' => 'id_order_state', 'name' => 'name')), array('type' => 'free', 'label' => $this->l('Check order cron URL'), 'name' => 'cron_link'), array('type' => 'free', 'name' => 'js_data')), 'submit' => array('title' => $this->l('Save')))); $helper = new HelperForm(); $helper->submit_action = 'btnSubmit'; $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues($states), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); return $helper->generateForm(array($fields_form)); }
protected function _getAddr(Address $address) { return array("first_name" => $address->firstname, "last_name" => $address->lastname, "phone" => $address->phone, "alt_phone" => $address->phone_mobile, "street" => $address->address1, "address_addition" => $address->address2, "city" => $address->city, "state" => State::getNameById($address->id_state), "country" => CountryCore::getIsoById($address->id_country), "zip" => $address->postcode); }
/** * Returns country iso from context. */ private function getCountryIso() { return \CountryCore::getIsoById(\Configuration::get('PS_COUNTRY_DEFAULT')); }