Jump to content

restringir categoria para ciertos paises? ayuda


crnjohnsen

Recommended Posts

Tendrías que tocar el controlador, obtener la IP del cliente que está accediendo a la página web, geolocalizar la IP para obtener el país y después no mostrar esa categoría... si tienes conocimientos avanzados sobre Prestashop podrías hacerlo fácil.... si no dominas mucho Prestashop, se me ocurre que podrías hacerlo a través de Javascript, y ocultas vía CSS la categoría en relación a la IP del cliente.

Link to comment
Share on other sites

1.Primero activa y configura la geolocalizacion desde

Preferencias / Geolocalizacion

2. Crea un archivo CategoryController.php con este contenido

<?php
class CategoryController extends CategoryControllerCore
{
	    public function init()
    {
        // Get category ID
        $id_category = (int)Tools::getValue('id_category');
        if (!$id_category || !Validate::isUnsignedId($id_category)) {
            $this->errors[] = Tools::displayError('Missing category ID');
        }
        // Instantiate category
        $this->category = new Category($id_category, $this->context->language->id);
        parent::init();
  
		 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()); 
         $countrynotAllowed = array('Croatia', 'Cuba', 'Spain', 'Czech Republic', 'Denmark');
         $categorynotAllowed = array('11', '12', '10', '15', '20');
		 if (in_array($record->country_name,$countrynotAllowed) && in_array($this->category->id,$categorynotAllowed)){
            header('HTTP/1.1 403 Forbidden');
            header('Status: 403 Forbidden');
            $this->display_column_left  = false;
            $this->display_column_right = false;
			$this->errors[] = Tools::displayError('Category Not Available In Your Country');
            $this->customer_access = false;
        }
		
		
    }
	
}

en ese codigo tendrás que editar esta parte con los paises y categorias (IDs) a los que se limitará el acceso, ejemplo:

$countrynotAllowed = array('Croatia', 'Cuba', 'Spain', 'Czech Republic', 'Denmark');
$categorynotAllowed = array('11', '12', '10', '15', '20');

una vez editado lo subes a la ruta

override/controllers/front/

3. Elimina este archivo para que se regenere y aplique los cambios contenidos en el override

cache/class_index.php
  • Like 1
Link to comment
Share on other sites

  • 5 years later...
En 28/8/2016 a las 9:08 AM, ventura dijo:

1.Primero activa y configura la geolocalizacion desde

Preferencias / Geolocalizacion

2. Crea un archivo CategoryController.php con este contenido

<?php
class CategoryController extends CategoryControllerCore
{
	    public function init()
    {
        // Get category ID
        $id_category = (int)Tools::getValue('id_category');
        if (!$id_category || !Validate::isUnsignedId($id_category)) {
            $this->errors[] = Tools::displayError('Missing category ID');
        }
        // Instantiate category
        $this->category = new Category($id_category, $this->context->language->id);
        parent::init();
  
		 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()); 
         $countrynotAllowed = array('Croatia', 'Cuba', 'Spain', 'Czech Republic', 'Denmark');
         $categorynotAllowed = array('11', '12', '10', '15', '20');
		 if (in_array($record->country_name,$countrynotAllowed) && in_array($this->category->id,$categorynotAllowed)){
            header('HTTP/1.1 403 Forbidden');
            header('Status: 403 Forbidden');
            $this->display_column_left  = false;
            $this->display_column_right = false;
			$this->errors[] = Tools::displayError('Category Not Available In Your Country');
            $this->customer_access = false;
        }
		
		
    }
	
}

en ese codigo tendrás que editar esta parte con los paises y categorias (IDs) a los que se limitará el acceso, ejemplo:

$countrynotAllowed = array('Croatia', 'Cuba', 'Spain', 'Czech Republic', 'Denmark');
$categorynotAllowed = array('11', '12', '10', '15', '20');

una vez editado lo subes a la ruta

override/controllers/front/

3. Elimina este archivo para que se regenere y aplique los cambios contenidos en el override

cache/class_index.php

Hola Antonio

perdona que reflote un hilo tan viejo

me imagino que esto era PS 1.6, porque lo he probado en 1.7 y volviendome loco no lo he logrado

me podrías echar una mano como sería esto mismo para PS 1.7 que realmente lo necesitaría

muchas gracias

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...