本文整理汇总了PHP中FrontController::isInWhitelistForGeolocation方法的典型用法代码示例。如果您正苦于以下问题:PHP FrontController::isInWhitelistForGeolocation方法的具体用法?PHP FrontController::isInWhitelistForGeolocation怎么用?PHP FrontController::isInWhitelistForGeolocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrontController
的用法示例。
在下文中一共展示了FrontController::isInWhitelistForGeolocation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
//.........这里部分代码省略.........
throw new PrestaShopException((sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\')))));
if (Configuration::get('PS_GEOLOCATION_ENABLED'))
if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault))
$this->context->country = $newDefault;
$currency = Tools::setCurrency($this->context->cookie);
if (isset($_GET['logout']) || ($this->context->customer->logged && Customer::isBanned($this->context->customer->id)))
{
$this->context->customer->logout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
}
elseif (isset($_GET['mylogout']))
{
$this->context->customer->mylogout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
}
/* Cart already exists */
if ((int)$this->context->cookie->id_cart)
{
$cart = new Cart($this->context->cookie->id_cart);
if ($cart->OrderExists())
{
unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
$this->context->cookie->check_cgv = false;
}
/* Delete product of cart, if user can't make an order from his country */
elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) &&
!in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) &&
$cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 &&
!FrontController::isInWhitelistForGeolocation() &&
!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
unset($this->context->cookie->id_cart, $cart);
// update cart values
elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency)
{
if ($this->context->cookie->id_customer)
$cart->id_customer = (int)($this->context->cookie->id_customer);
$cart->id_lang = (int)($this->context->cookie->id_lang);
$cart->id_currency = (int)$currency->id;
$cart->update();
}
/* Select an address if not set */
if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 ||
!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer)
{
$to_update = false;
if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0)
{
$to_update = true;
$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer);
}
if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0)
{
$to_update = true;
$cart->id_address_invoice = (int)Address::getFirstCustomerAddressId($cart->id_customer);
}
if ($to_update)
$cart->update();
}
}
if (!isset($cart) || !$cart->id)
示例2: geolocationManagement
protected function geolocationManagement($default_country)
{
if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
/* Check if Maxmind Database exists */
if (file_exists(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat')) {
if (!isset($this->context->cookie->iso_code_country) || isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) {
include_once _PS_GEOIP_DIR_ . 'geoipcity.inc';
$gi = geoip_open(realpath(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat'), GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, Tools::getRemoteAddr());
if (is_object($record)) {
if (!in_array(strtoupper($record->country_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && !FrontController::isInWhitelistForGeolocation()) {
if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
$this->restrictedCountry = true;
} elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
$this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => $record->country_name));
}
} else {
$has_been_set = !isset($this->context->cookie->iso_code_country);
$this->context->cookie->iso_code_country = strtoupper($record->country_code);
}
}
}
if (isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country)) {
$this->context->cookie->iso_code_country = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
}
if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) {
/* Update defaultCountry */
if ($default_country->iso_code != $this->context->cookie->iso_code_country) {
$default_country = new Country($id_country);
}
if (isset($has_been_set) && $has_been_set) {
$this->context->cookie->id_currency = (int) Currency::getCurrencyInstance($default_country->id_currency ? (int) $default_country->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id;
}
return $default_country;
} elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_ && !FrontController::isInWhitelistForGeolocation()) {
$this->restrictedCountry = true;
} elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_ && !FrontController::isInWhitelistForGeolocation()) {
$this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => 'Undefined'));
}
} else {
Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0);
}
}
return false;
}
示例3: geolocationManagement
/**
* Geolocation management.
*
* @param Country $defaultCountry
*
* @return Country|false
*/
protected function geolocationManagement($defaultCountry)
{
if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
/* Check if Maxmind Database exists */
if (@filemtime(_PS_GEOIP_DIR_ . _PS_GEOIP_CITY_FILE_)) {
if (!isset($this->context->cookie->iso_code_country) || isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) {
$reader = new GeoIp2\Database\Reader(_PS_GEOIP_DIR_ . _PS_GEOIP_CITY_FILE_);
$record = $reader->city(Tools::getRemoteAddr());
if (is_object($record)) {
if (!in_array(strtoupper($record->country->isoCode), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && !FrontController::isInWhitelistForGeolocation()) {
if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
$this->restrictedCountry = Country::GEOLOC_FORBIDDEN;
} elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
$this->restrictedCountry = Country::GEOLOC_CATALOG_MODE;
$this->warning[] = sprintf($this->l('You cannot place a new order from your country (%s).'), $record->country->name);
}
} else {
$hasBeenSet = !isset($this->context->cookie->iso_code_country);
$this->context->cookie->iso_code_country = strtoupper($record->country->isoCode);
}
}
}
if (isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country)) {
$this->context->cookie->iso_code_country = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
}
if (isset($this->context->cookie->iso_code_country) && ($idCountry = (int) Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) {
/* Update defaultCountry */
if ($defaultCountry->iso_code != $this->context->cookie->iso_code_country) {
$defaultCountry = new Country($idCountry);
}
if (isset($hasBeenSet) && $hasBeenSet) {
$this->context->cookie->id_currency = (int) ($defaultCountry->id_currency ? (int) $defaultCountry->id_currency : (int) Configuration::get('PS_CURRENCY_DEFAULT'));
}
return $defaultCountry;
} elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_ && !FrontController::isInWhitelistForGeolocation()) {
$this->restrictedCountry = Country::GEOLOC_FORBIDDEN;
} elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_ && !FrontController::isInWhitelistForGeolocation()) {
$this->restrictedCountry = Country::GEOLOC_CATALOG_MODE;
$this->warning[] = sprintf($this->l('You cannot place a new order from your country (%s).'), isset($record->country->name) && $record->country->name ? $record->country->name : $this->l('Undefined'));
}
}
}
return false;
}