示例#1
0
 function onAfterRoute()
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     if (!file_exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_geolocator' . DS . 'assets' . DS . 'helper.php')) {
         return;
     }
     include_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_geolocator' . DS . 'assets' . DS . 'helper.php';
     require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'config.php';
     $can_change = OPCconfig::getValueNoCache('currency_config', 'can_change', 0, true);
     if (empty($can_change)) {
         $ci = JRequest::getVar('virtuemart_currency_id');
         $session = JFactory::getSession();
         if (!empty($ci)) {
             //currency was set elsewhere
             $session->set('opc_currency', $ci);
             return;
         }
         $ci2 = $session->get('opc_currency');
         if (!empty($ci2)) {
             return;
         }
     }
     //debug:
     if ($_SERVER['REMOTE_ADDR'] == '192.168.122.122') {
         $_SERVER['REMOTE_ADDR'] = '92.240.237.203';
     }
     if (class_exists('geoHelper')) {
         $c2c = geoHelper::getCountry2Code();
     }
     if (empty($c2c)) {
         return;
     }
     $default = 0;
     $c_int = OPCconfig::getValueNoCache('currency_config', $c2c, 0, $default);
     if (empty($c_int)) {
         return;
     }
     $c_int = (int) $c_int;
     // set global request variable
     JRequest::setVar('virtuemart_currency_id', $c_int);
     $app->setUserState('virtuemart_currency_id', $c_int);
     $app->setUserState('com_virtuemart.virtuemart_currency_id', $c_int);
     // $virtuemart_currency_id = $app->getUserStateFromRequest( "virtuemart_currency_id", 'virtuemart_currency_id',JRequest::getVar('virtuemart_currency_id',$currencyDisplay->_vendorCurrency) );
 }
示例#2
0
 static function getDefaultCountry(&$cart, $searchBT = false)
 {
     if ($searchBT) {
         if (!empty($cart->BT['virtuemart_country_id'])) {
             return $cart->BT['virtuemart_country_id'];
         }
     }
     if (defined('OPC_DEFAULT_COUNTRY')) {
         return OPC_DEFAULT_COUNTRY;
     }
     if (defined('DEFAULT_COUNTRY')) {
         if (is_numeric(DEFAULT_COUNTRY)) {
             define('OPC_DEFAULT_COUNTRY', DEFAULT_COUNTRY);
             return DEFAULT_COUNTRY;
         }
     }
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!empty($op_use_geolocator)) {
         if (file_exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_geolocator' . DS . 'assets' . DS . 'helper.php')) {
             include_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_geolocator' . DS . 'assets' . DS . 'helper.php';
             if (class_exists('geoHelper')) {
                 $c2 = geoHelper::getCountry2Code("");
             }
             if (!empty($c2)) {
                 $db = JFactory::getDBO();
                 $q = "select virtuemart_country_id from #__virtuemart_countries where country_2_code = '" . $db->getEscaped($c2) . "' limit 0,1";
                 $db->setQuery($q);
                 $c = $db->loadResult();
                 if (!empty($c)) {
                     define('OPC_DEFAULT_COUNTRY', $c);
                     if (!defined('DEFAULT_COUNTRY')) {
                         define('DEFAULT_COUNTRY', $c);
                     }
                     // case IP address
                     return $c;
                 }
             }
         }
     }
     $lang = JFactory::getLanguage();
     $tag = $lang->getTag();
     if (!empty($default_country_array[$tag])) {
         define('DEFAULT_COUNTRY', $default_country_array[$tag]);
         define('OPC_DEFAULT_COUNTRY', $default_country_array[$tag]);
         return $default_country_array[$tag];
     }
     if (!empty($default_shipping_country)) {
         define('DEFAULT_COUNTRY', $default_shipping_country);
         define('OPC_DEFAULT_COUNTRY', $default_shipping_country);
         return $default_shipping_country;
     }
     //
     //$default_country_array["en-GB"] = "222";
     //$default_country_array["sk-SK"] = "189";
     $vendor = OPCloader::getVendorInfo($cart);
     if (!empty($vendor)) {
         $c = $vendor['virtuemart_country_id'];
         define('DEFAULT_COUNTRY', $c);
         define('OPC_DEFAULT_COUNTRY', $c);
         return $c;
     }
 }
示例#3
0
 public static function getSetShopperGroup($debug = false)
 {
     $user = JFactory::getUser();
     $uid = (int) $user->get('id');
     if ($uid > 0) {
         return;
     }
     $session = JFactory::getSession();
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (empty($option_sgroup)) {
         return;
     }
     // language shopper group
     //$lang_shopper_group['en-GB'] = '4';
     if (!empty($option_sgroup) && $option_sgroup === 1) {
         $lang = JFactory::getLanguage();
         $tag = $lang->getTag();
         if (!empty($tag)) {
             if (!empty($lang_shopper_group)) {
                 if (!empty($lang_shopper_group[$tag])) {
                     // end of lang shopper group
                     return OPCShopperGroups::setShopperGroups($lang_shopper_group[$tag]);
                 }
             }
         }
     } else {
         if ($option_sgroup == 2) {
             // geo ip based shopper group:
             $ip_vm_country = $session->get('opc_ip_country', 0);
             $ip_sg = $session->get('opc_ip_sg');
             if (!empty($ip_sg)) {
                 // ip sg was already set
                 //return OPCloader::setShopperGroup($lang_shopper_group_ip[$ip_vm_country]);
             }
             if (empty($ip_vm_country)) {
                 if (file_exists(JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_geolocator" . DS . "assets" . DS . "helper.php")) {
                     require_once JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_geolocator" . DS . "assets" . DS . "helper.php";
                     if (class_exists("geoHelper")) {
                         $country_2_code = geoHelper::getCountry2Code("");
                         if (!empty($country_2_code)) {
                             $country_2_code = strtolower($country_2_code);
                             $db = JFactory::getDBO();
                             $db->setQuery("select virtuemart_country_id from #__virtuemart_countries where country_2_code = '" . $country_2_code . "' limit 1 ");
                             $r = $db->loadResult();
                             //$e = $db->getErrorMsg(); echo $e;
                             if (!empty($r)) {
                                 $ip_vm_country = $r;
                             }
                         }
                     }
                 }
             }
             if (!empty($lang_shopper_group_ip[$ip_vm_country])) {
                 $id = OPCShopperGroups::setShopperGroups($lang_shopper_group_ip[$ip_vm_country]);
                 $session->set('opc_ip_country', $ip_vm_country);
                 $session->set('opc_ip_sg', $id);
                 return $id;
             }
         }
     }
     // we should set default here
     $a = $session->get('vm_shoppergroups_add', null, 'vm');
     if (!empty($a)) {
         $session->set('vm_shoppergroups_add', array(), 'vm');
     }
     return;
 }