コード例 #1
0
ファイル: country.php プロジェクト: jeprodev/jeproshop
 public function update()
 {
     if ($this->viewAccess() && JeproshopTools::checkCountryToken()) {
         if ($this->has_errors) {
             return false;
         }
         $input = JRequest::get('post');
         $country_id = $input['country_id'];
         $app = JFactory::getApplication();
         $countryModel = new JeproshopCountryModelCountry();
         if ($countryModel->updateCountry()) {
             $app->enqueueMessage(JText::_('COM_JEPROSHOP_COUNTRY_HAS_BEEN_SUCCESSFULLY_UPDATED_MESSAGE'));
             $app->redirect('index.php?option=com_jeproshop&view=country&task=edit&country_id=' . (int) $country_id . '&' . JeproshopTools::getCountryToken() . '&=1');
         }
     }
 }
コード例 #2
0
ファイル: view.html.php プロジェクト: jeprodev/jeproshop
 public function renderEditForm($tpl = null)
 {
     if (!isset($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     $image = COM_JEPROSHOP_SUPPLIER_IMAGE_DIR . $this->supplier->supplier_id . '.jpg';
     $imageUrl = JeproshopImageManager::thumbnail($image, 'supplier_' . $this->supplier->supplier_id . '.' . $this->imageType, 350, $this->imageType, true, true);
     $imageSize = file_exists($image) ? filesize($image) / 1000 : false;
     $helper = new JeproshopHelper();
     $this->assignRef('helper', $helper);
     $address = $this->supplier->getSupplierAddress();
     $this->assignRef('address', $address);
     $countries = JeproshopCountryModelCountry::getStaticCountries($this->context->language->lang_id, false);
     $this->assignRef('countries', $countries);
     $this->addToolBar();
     $this->sideBar = JHtmlSideBar::render();
     parent::display($tpl);
 }
コード例 #3
0
ファイル: add_rule.php プロジェクト: jeprodev/jeproshop
echo JText::_('COM_JEPROSHOP_YOU_ARE_ABOUT_TO_ADD_LABEL') . ' ' . JText::_('COM_JEPROSHOP_A_NEW_TAX_RULE_LABEL');
?>
</div>
            <div class="panel-content well" >
                <div class="control-group" >
                    <div class="control-label" ><label for="jform_country_id" title="<?php 
echo JText::_('COM_JEPROSHOP_COUNTRY_TITLE_DESC');
?>
" ><?php 
echo JText::_('COM_JEPROSHOP_COUNTRY_LABEL');
?>
</label> </div>
                    <div class="controls" >
                        <?php 
$default_country_id = (int) $this->context->country->country_id;
$countries = JeproshopCountryModelCountry::getStaticCountries($this->context->language->lang_id);
?>
                        <select id="jform_country_id" name="jform[country_id]" >
                            <option value="0" ><?php 
echo JText::_('COM_JEPROSHOP_ALL_LABEL');
?>
</option>
                            <?php 
foreach ($countries as $country) {
    ?>
                                <option value="<?php 
    echo $country->country_id;
    ?>
" ><?php 
    echo $country->name;
    ?>
コード例 #4
0
ファイル: order.php プロジェクト: jeprodev/jeproshop
 public function getOrderList(JeproshopContext $context = NULL)
 {
     jimport('joomla.html.pagination');
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $option = $app->input->get('option');
     $view = $app->input->get('view');
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     $select = " ord.currency_id, ord.order_id AS pdf_id, CONCAT(LEFT(customer." . $db->quoteName('firstname') . ", 1), '. ',";
     $select .= " customer." . $db->quoteName('lastname') . ") AS " . $db->quoteName('customer_name') . ", order_status_lang.";
     $select .= $db->quoteName('name') . " AS " . $db->quoteName('order_status_name') . ", order_status." . $db->quoteName('color');
     $select .= ", IF((SELECT COUNT(orders.order_id) FROM " . $db->quoteName('#__jeproshop_orders') . " AS orders WHERE orders.customer_id ";
     $select .= "= ord.customer_id) > 1, 0, 1) AS new, country_lang.name as country_name, IF(ord.valid, 1, 0) badge_success ";
     $join = " LEFT JOIN " . $db->quoteName('#__jeproshop_customer') . " AS customer ON (customer." . $db->quoteName('customer_id');
     $join .= " = ord." . $db->quoteName('customer_id') . ") INNER JOIN " . $db->quoteName('#__jeproshop_address') . " AS address ";
     $join .= " ON address.address_id = ord.address_delivery_id INNER JOIN " . $db->quoteName('#__jeproshop_country') . " AS country ";
     $join .= " ON address.country_id = country.country_id INNER JOIN " . $db->quoteName('#__jeproshop_country_lang') . " AS country_lang";
     $join .= " ON (country." . $db->quoteName('country_id') . " = country_lang." . $db->quoteName('country_id') . " AND country_lang.";
     $join .= $db->quoteName('lang_id') . " = " . (int) $context->language->lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_order_status');
     $join .= " AS order_status ON (order_status." . $db->quoteName('order_status_id') . " = ord." . $db->quoteName('current_status') . ") LEFT JOIN ";
     $join .= $db->quoteName('#__jeproshop_order_status_lang') . " order_status_lang ON (order_status." . $db->quoteName('order_status_id') . " = ";
     $join .= " order_status_lang." . $db->quoteName('order_status_id') . " AND order_status_lang." . $db->quoteName('lang_id') . " = ";
     $join .= (int) $context->language->lang_id . ") ";
     $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int');
     $limit_start = $app->getUserStateFromRequest($option . $view . '.limit_start', 'limit_start', 0, 'int');
     $order_by = $app->getUserStateFromRequest($option . $view . '.order_by', 'order_by', 'order_id', 'string');
     $order_way = $app->getUserStateFromRequest($option . $view . '.order_way', 'order_way', 'DESC', 'string');
     $lang_id = $app->getUserStateFromRequest($option . $view . '.lang_id', 'lang_id', $context->language->lang_id, 'int');
     $deleted = false;
     /* Manage default params values */
     $use_limit = true;
     if ($limit === false) {
         $use_limit = false;
     }
     $select_shop = ", shop.shop_name AS shop_name ";
     $join_shop = " LEFT JOIN " . $db->quoteName('#__jeproshop_shop') . " AS shop ON ord.shop_id = shop.shop_id ";
     $where_shop = JeproshopShopModelShop::addSqlRestriction(JeproshopShopModelShop::SHARE_ORDER, 'ord', 'shop');
     if (JeproshopCountryModelCountry::isCurrentlyUsed()) {
         $query = "SELECT DISTINCT country.country_id, country_lang." . $db->quoteName('name') . " FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord ";
         $query .= " INNER JOIN " . $db->quoteName('#__jeproshop_address') . " AS address ON address.address_id = ord.address_delivery_id INNER JOIN " . $db->quoteName('#__jeproshop_country');
         $query .= " AS country ON address.country_id = country.country_id INNER JOIN " . $db->quoteName('#__jeproshop_country_lang') . " AS country_lang ON (country." . $db->quoteName('country_id');
         $query .= " = country_lang." . $db->quoteName('country_id') . " AND country_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") ORDER BY country_lang.name ASC";
         $db->setQuery($query);
         $result = $db->loadObjectList();
         $shopLinkType = 'shop';
     }
     $where = "";
     if ($this->multishop_context && JeproshopShopModelShop::isTableAssociated('order')) {
         if (JeproshopShopModelShop::getShopContext() != JeproshopShopModelShop::CONTEXT_ALL || !$context->employee->isSuperAdmin()) {
             if (JeproshopShopModelShop::isFeaturePublished() && $test_join && JeproshopShopModelShop::isTableAssociated('order')) {
                 $where .= " AND ord.order_id IN (SELECT order_shop.shop_id FROM " . $db->quoteName('#__jeproshop_order_shop') . " AS order_shop WHERE order_shop.shop_id IN (" . implode(', ', JeproshopShopModelShop::getContextListShopIds()) . "))";
             }
         }
     }
     $lang_join = "";
     /*if($lang_id){
      		$lang_join = " LEFT JOIN " . $db->quoteName('#__jeproshop_order');
      	} */
     do {
         $query = "SELECT SQL_CALC_FOUND_ROWS ord." . $db->quoteName('order_id') . " AS pdf_id, ord." . $db->quoteName('reference') . ", ord." . $db->quoteName('customer_id');
         if (JeproshopSettingModelSetting::getValue('enable_b2b_mode')) {
             $query .= ", customer." . $db->quoteName('company');
         }
         $query .= ", " . $db->quoteName('total_paid_tax_incl') . ", " . $db->quoteName('payment') . ", ord." . $db->quoteName('date_add') . " AS date_add, ord.";
         $query .= $db->quoteName('currency_id') . ", order_status." . $db->quoteName('order_status_id') . ", " . $select . $select_shop;
         $query .= " FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord " . $lang_join . $join . $join_shop . " WHERE 1 " . $where;
         $query .= ($deleted ? " AND ord." . $db->quoteName('deleted') . " = 0 " : "") . (isset($filter) ? $filter : "") . $where_shop;
         $query .= (isset($group) ? $group : "") . " ORDER BY " . (str_replace('`', '', $order_by) == 'order_id' ? "ord." : "");
         $query .= $order_by . " " . $order_way;
         $db->setQuery($query);
         $total = count($db->loadObjectList());
         $query .= $use_limit === true ? " LIMIT " . (int) $limit_start . ", " . (int) $limit : "";
         $db->setQuery($query);
         $orders = $db->loadObjectList();
         if ($use_limit == true) {
             $limit_start = (int) $limit_start - (int) $limit;
             if ($limit_start < 0) {
                 break;
             }
         } else {
             break;
         }
     } while (empty($orders));
     $this->pagination = new JPagination($total, $limit_start, $limit);
     return $orders;
 }
コード例 #5
0
ファイル: address.php プロジェクト: jeprodev/jeproshop
 public function __construct($address_id = NULL, $lang_id = NULL)
 {
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== FALSE ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($address_id) {
         //Load address from database if address id is provided
         $cache_id = 'jeproshop_address_model_' . $address_id . '_' . $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $db = JFactory::getDBO();
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_address') . " AS address ";
             $query .= " WHERE address.address_id = " . (int) $address_id;
             $db->setQuery($query);
             $address_data = $db->loadObject();
             if ($address_data) {
                 JeproshopCache::store($cache_id, $address_data);
             }
         } else {
             $address_data = JeproshopCache::retrieve($cache_id);
         }
         if ($address_data) {
             $address_data->address_id = $address_id;
             foreach ($address_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     if ($this->address_id) {
         $this->country = JeproshopCountryModelCountry::getNameById($lang_id, $this->country_id);
     }
 }
コード例 #6
0
ファイル: view.html.php プロジェクト: jeprodev/jeproshop
 private function assignCountries()
 {
     // Select the most appropriate country
     $app = JFactory::getApplication();
     $country_id = $app->input->get('country_id');
     if (isset($country_id) && is_numeric($country_id)) {
         $selectedCountry = (int) $country_id;
     }
     if (!isset($selectedCountry)) {
         $selectedCountry = (int) JeproshopSettingModelSetting::getValue('default_country');
     }
     if (JeproshopSettingModelSetting::getValue('restrict_delivered_countries')) {
         $countries = JeproshopCarrierModelCarrier::getDeliveredCountries($this->context->language->lang_id, true, true);
         print_r($countries);
     } else {
         $countries = JeproshopCountryModelCountry::getCountries($this->context->language->lang_id, true);
     }
     $zones = JeproshopZoneModelZone::getZones();
     $this->assignRef('zones', $zones);
     $this->assignRef('countries', $countries);
     $registrationProcessType = JeproshopSettingModelSetting::getValue('registration_process_type');
     $this->assignRef('registration_process_type', $registrationProcessType);
     $selectedCountry = isset($selectedCountry) ? $selectedCountry : 0;
     $this->assignRef('selected_country', $selectedCountry);
     $vatNumberManagement = JeproshopSettingModelSetting::getValue('vat_number_management');
     $this->assignRef('vat_management', $vatNumberManagement);
 }
コード例 #7
0
ファイル: country.php プロジェクト: jeprodev/jeproshop
 public static function addModuleRestrictions(array $shops = array(), array $countries = array(), array $modules = array())
 {
     if (!count($shops)) {
         $shops = JeproshopShopModelShop::getShops(true, null, true);
     }
     if (!count($countries)) {
         $countries = JeproshopCountryModelCountry::getCountries((int) JeproshopContext::getContext()->cookie->lang_id);
     }
     if (!count($modules)) {
         $modules = Module::getPaymentModules();
     }
     $sql = false;
     foreach ($shops as $id_shop) {
         foreach ($countries as $country) {
             foreach ($modules as $module) {
                 $sql .= '(' . (int) $module['id_module'] . ', ' . (int) $id_shop . ', ' . (int) $country['id_country'] . '),';
             }
         }
     }
     if ($sql) {
         $sql = 'INSERT IGNORE INTO `' . _DB_PREFIX_ . 'module_country` (`id_module`, `id_shop`, `id_country`) VALUES ' . rtrim($sql, ',');
         return Db::getInstance()->execute($sql);
     } else {
         return true;
     }
 }
コード例 #8
0
ファイル: view.html.php プロジェクト: jeprodev/jeproshop
 public function renderEditRule($tpl = NULL)
 {
     if (!isset($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     $this->helper = new JeproshopHelper();
     $countryModel = new JeproshopCountryModelCountry();
     $countries = $countryModel->getCountries($this->context->language->lang_id);
     $taxModel = new JeproshopTaxModelTax();
     $taxes = $taxModel->getTaxes((int) $this->context->language->lang_id);
     $this->assignRef('taxes', $taxes);
     $taxRuleModel = new JeproshopTaxRuleModelTaxRule();
     $taxRules = $taxRuleModel->getTaxRuleList();
     $this->assignRef('tax_rules', $taxRules);
     $this->assignRef('countries', $countries);
     $this->addToolBar();
     $this->sideBar = JHtmlSidebar::render();
     parent::display($tpl);
 }
コード例 #9
0
ファイル: view.html.php プロジェクト: jeprodev/jeproshop
 private function initPriceForm()
 {
     if ($this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     if ($this->product->product_id) {
         $shops = JeproshopShopModelShop::getShops();
         $countries = JeproshopCountryModelCountry::getStaticCountries($this->context->language->lang_id);
         $groups = JeproshopGroupModelGroup::getStaticGroups($this->context->language->lang_id);
         $currencies = JeproshopCurrencyModelCurrency::getStaticCurrencies();
         $attributes = $this->product->getAttributesGroups((int) $this->context->language->lang_id);
         $combinations = array();
         if (count($attributes)) {
             foreach ($attributes as $attribute) {
                 $combinations[$attribute->product_attribute_id] = new JObject();
                 $combinations[$attribute->product_attribute_id]->product_attribute_id = $attribute->product_attribute_id;
                 if (!isset($combinations[$attribute->product_attribute_id]->attributes)) {
                     $combinations[$attribute->product_attribute_id]->attributes = '';
                 }
                 if (isset($combinations[$attribute->product_attribute_id])) {
                     $combinations[$attribute->product_attribute_id]->attributes .= $attribute->attribute_name . ' - ';
                     $combinations[$attribute->product_attribute_id]->price = JeproshopTools::displayPrice(JeproshopTools::convertPrice(JeproshopProductModelProduct::getStaticPrice((int) $this->product->product_id, false, $attribute->product_attribute_id), $this->context->currency), $this->context->currency);
                 }
             }
             foreach ($combinations as $combination) {
                 if (isset($combination->attributes)) {
                     $combination->attributes = rtrim($combination->attributes, ' - ');
                 }
             }
         }
         $specificPriceModificationForm = $this->displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups);
         $this->assignRef('specific_price_modification_form', $specificPriceModificationForm);
         $this->assignRef('ecotax_tax_excluded', $this->product->ecotax);
         //$this->applyTaxToEcotax();
         $this->assignRef('shops', $shops);
         /*$admin_one_shop = count($this->context->employee->getAssociatedShops()) == 1;
           $this->assignRef('admin_one_shop', $admin_one_shop); */
         $this->assignRef('currencies', $currencies);
         $this->assignRef('currency', $this->context->currency);
         $this->assignRef('countries', $countries);
         $this->assignRef('groups', $groups);
         $this->assignRef('combinations', $combinations);
         $multiShop = JeproshopShopModelShop::isFeaturePublished();
         $this->assignRef('multi_shop', $multiShop);
     } else {
         JError::raiseWarnig(JText::_('COM_JEPROSHOP_YOU_MUST_SAVE_THIS_PRODUCT_BEFORE_ADDING_SPECIFIC_PRICING_MESSAGE'));
         $this->product->tax_rules_group_id = JeproshopProductModelProduct::getTaxRulesMostUsedGroupId();
         $this->assignRef('ecotax_tax_excluded', 0);
     }
     $use_tax = JeproshopSettingModelSetting::getValue('use_tax');
     $this->assignRef('use_tax', $use_tax);
     $use_ecotax = JeproshopSettingModelSetting::getValue('use_eco_tax');
     $this->assignRef('use_ecotax', $use_ecotax);
     $tax_rules_groups = JeproshopTaxRulesGroupModelTaxRulesGroup::getTaxRulesGroups(true);
     $this->assignRef('tax_rules_groups', $tax_rules_groups);
     $taxesRatesByGroup = JeproshopTaxRulesGroupModelTaxRulesGroup::getAssociatedTaxRatesByCountryId($this->context->country->country_id);
     $this->assignRef('taxesRatesByGroup', $taxesRatesByGroup);
     $ecotaxTaxRate = JeproshopTaxModelTax::getProductEcotaxRate();
     $this->assignRef('ecotaxTaxRate', $ecotaxTaxRate);
     $tax_exclude_tax_option = JeproshopTaxModelTax::taxExcludedOption();
     $this->assignRef('tax_exclude_tax_option', $tax_exclude_tax_option);
     $this->product->price = JeproshopTools::convertPrice($this->product->price, $this->context->currency, true, $this->context);
     if ($this->product->unit_price_ratio != 0) {
         $unit_price = JeproshopTools::roundPrice($this->product->price / $this->product->unit_price_ratio, 2);
     } else {
         $unit_price = 0;
     }
     $this->assignRef('unit_price', $unit_price);
 }
コード例 #10
0
ファイル: view.html.php プロジェクト: jeprodev/jeproshop
 public function renderAddState($tpl = null)
 {
     if (!isset($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     $this->helper = new JeproshopHelper();
     $countries = JeproshopCountryModelCountry::getStaticCountries($this->context->language->lang_id);
     $zones = JeproshopZoneModelZone::getZones();
     $this->assignRef('countries', $countries);
     $this->assignRef('zones', $zones);
     $this->addToolBar();
     $this->sideBar = JHtmlSidebar::render();
     parent::display($tpl);
 }
コード例 #11
0
ファイル: tax.php プロジェクト: jeprodev/jeproshop
 public function add()
 {
     $db = JFactory::getDBO();
     $context = JeproshopContext::getContext();
     $input = JRequest::get('post');
     $inputData = $input['jform'];
     $selectedCountries = array();
     $app = JFactory::getApplication();
     $taxId = isset($inputData['tax_id']) ? $inputData['tax_id'] : $app->input->get('tax_id', 0);
     $taxRuleId = isset($inputData['tax_rule_id']) ? $inputData['tax_rule_id'] : $app->input->get('tax_rule_id', 0);
     $zipCode = $inputData['zipcode'];
     $behavior = $inputData['behavior'];
     $description = $inputData['description'];
     $country_id = $inputData['country_id'];
     if ($country_id == 0) {
         $countries = JeproshopCountryModelCountry::getStaticCountries($context->language->lang_id);
         foreach ($countries as $country) {
             $selectedCountries[] = $country->country_id;
         }
     } else {
         $selectedCountries[] = $country_id;
     }
     $selectedStates = array();
     $state_id = $inputData['state_id'];
     if ($state_id != 0) {
         $selectedStates[] = $state_id;
     } else {
         $selectedStates[] = 0;
     }
     $taxRulesGroupId = (int) $app->input->get('tax_rules_group_id');
     echo $taxRulesGroupId;
     $taxRuleGroup = new JeproshopTaxRulesGroupModelTaxRulesGroup($taxRulesGroupId);
     foreach ($selectedCountries as $country_id) {
         $first = true;
         foreach ($selectedStates as $state_id) {
             if ($taxRuleGroup->hasUniqueTaxRuleForCountry($country_id, $state_id, $taxRuleId)) {
                 JError::raiseWarning(500, JText::_('COM_JEPROSHOP_A_TAX_ALREADY_EXISTS_FOR_THIS_COUNTRY_STATE_WITH_TAX_ONLY_BEHAVIOR_LABEL'));
                 continue;
             }
             $taxRule = new JeproshopTaxRuleModelTaxRule();
             // update or creation?
             if (isset($taxRuleId) && $first) {
                 $taxRule->tax_rule_id = $taxRuleId;
                 $first = false;
             }
             $taxRule->tax_id = $taxId;
             $taxRule->tax_rules_group_id = (int) $taxRulesGroupId;
             $taxRule->country_id = $country_id;
             $taxRule->state_id = (int) $state_id;
             list($taxRule->zipcode_from, $taxRule->zipcode_to) = $taxRule->breakDownZipCode($zipCode);
             $country = new JeproshopCountryModelCountry((int) $country_id, (int) $context->language->lang_id);
             if ($zipCode && $country->need_zip_code) {
                 if ($country->zip_code_format) {
                     foreach (array($taxRule->zipcode_from, $taxRule->zipcode_to) as $zip_code) {
                         if ($zip_code) {
                             if (!$country->checkZipCode($zip_code)) {
                                 JError::raiseError(500, JText::_('COM_JEPROSHOP_THE_ZIP_POSTAL_CODE_IS_INVALID_AND_MUST_BE_TYPED_AS_FOLLOWS_MESSAGE') . JText::_('COM_JEPROSHOP_FOR_LABEL'));
                             }
                         }
                     }
                 }
             }
             $taxRule->behavior = $behavior;
             $taxRule->description = $description;
             $query = "INSERT INTO " . $db->quoteName('#__jeproshop_tax_rule') . "(" . $db->quoteName('tax_rules_group_id') . ", " . $db->quoteName('country_id') . ", " . $db->quoteName('state_id') . ", " . $db->quoteName('zipcode_from') . ", ";
             $query .= $db->quoteName('zipcode_to') . ", " . $db->quoteName('tax_id') . ", " . $db->quoteName('behavior') . ", " . $db->quoteName('description') . ") VALUES (" . (int) $taxRulesGroupId . ", " . (int) $country_id . ", " . (int) $state_id;
             $query .= ", " . $db->quote($taxRule->zipcode_from) . ", " . $db->quote($taxRule->zipcode_to) . ", " . (int) $taxId . ", " . (int) $behavior . ", " . $db->quote($description) . ")";
             $db->setQuery($query);
             $link = 'index.php?option=com_jeproshop&view=tax&task=';
             if ($db->query()) {
                 $link .= 'edit_rules_group&tax_rules_group_id=' . (int) $taxRulesGroupId . '&' . JeproshopTools::getTaxToken() . '=1';
             } else {
                 $link .= '';
             }
             $app->redirect($link);
         }
     }
 }
コード例 #12
0
ファイル: country.php プロジェクト: jeprodev/jeproshop
 public function needIdentificationNumber()
 {
     return JeproshopCountryModelCountry::needIdentificationNumberByCountryId($this->country_id);
 }
コード例 #13
0
ファイル: view.html.php プロジェクト: jeprodev/jeproshop
 /**
  * Assign template vars related to countries display
  */
 protected function assignCountries()
 {
     $context = JeproshopContext::getContext();
     $app = JFactory::getApplication();
     $country_id = $app->input->get('country_id');
     // Get selected country
     if (isset($country_id) && !is_null($country_id) && is_numeric($country_id)) {
         $selected_country = (int) $country_id;
     } else {
         if (isset($this->address) && isset($this->address->country_id) && !empty($this->address->country_id) && is_numeric($this->address->country_id)) {
             $selected_country = (int) $this->address->country_id;
         } else {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 // get all countries as language (xy) or language-country (wz-XY)
                 $array = array();
                 preg_match("#(?<=-)\\w\\w|\\w\\w(?!-)#", $_SERVER['HTTP_ACCEPT_LANGUAGE'], $array);
                 if (!JeproshopTools::isLanguageIsoCode($array[0]) || !($selected_country = JeproshopCountryModelCountry::getByIso($array[0]))) {
                     $selected_country = (int) JeproshopSettingModelSetting::getValue('default_country');
                 }
             } else {
                 $selected_country = (int) JeproshopSettingModelSetting::getValue('default_country');
             }
         }
     }
     // Generate countries list
     if (JeproshopSettingModelSetting::getValue('restrict_delivered_countries')) {
         $countries = JeproshopCarrierModelCarrier::getDeliveredCountries($context->language->lang_id, true, true);
     } else {
         $countries = JeproshopCountryModelCountry::getCountries($context->language->lang_id, true);
     }
     // @todo use helper
     $list = '';
     foreach ($countries as $country) {
         $selected = $country->country_id == $selected_country ? 'selected="selected"' : '';
         $list .= '<option value="' . (int) $country->country_id . '" ' . $selected . '>' . htmlentities(ucfirst($country->name)) . '</option>';
     }
     // Assign vars
     $this->assignRef('countries_list', $list);
     $this->assignRef('countries', $countries);
 }