Jump to content

Récupérer id_country du client à la connexion [Prestashop 1.4]


Recommended Posts

Bonjour,

Je souhaiterais récupérer l'id_country du client dès sa connexion, afin de la rediriger directement vers une page en fonction de son pays.

Ca doit se passer la dedans (AuthController.php, ligne 255 environ) :

               else
               {
                   self::$cookie->id_customer = (int)($customer->id);
                   self::$cookie->customer_lastname = $customer->lastname;
                   self::$cookie->customer_firstname = $customer->firstname;    
     self::$cookie->logged = 1;
                   self::$cookie->is_guest = $customer->isGuest();
                   self::$cookie->passwd = $customer->passwd;
                   self::$cookie->email = $customer->email;
                   if (Configuration::get('PS_CART_FOLLOWING') AND (empty(self::$cookie->id_cart) OR Cart::getNbProducts(self::$cookie->id_cart) == 0))
                       self::$cookie->id_cart = (int)(Cart::lastNoneOrderedCart((int)($customer->id)));
                   /* Update cart address */
                   self::$cart->id_carrier = 0;
                   self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
                   self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
                   self::$cart->update();
                   Module::hookExec('authentication');
                   if (!Tools::isSubmit('ajax'))
                   {
                       Tools::redirect('category.php?id_category='.self::$cookie->departement);
                   }
               }



EDIT : En fait je pense qu'il faudrait directement le récupérer pour le stocker dans un cookie, mais je ne sais vraiment pas comment l'écrire... :/

Merci d'avance ;)

Link to comment
Share on other sites

Bon solution trouvée ! J'ai créé une fonction dans classes/Address.php qui cherche dans la base donnée le id_country :

// Récupère la valeur d'id_country
static public function getCountry($id_customer,  $active = true)
{
   return Db::getInstance()->getValue('
       SELECT `id_country`
       FROM `'._DB_PREFIX_.'address`
       WHERE `id_customer` = '.(int)($id_customer).' AND `deleted` = 0'.($active ? ' AND `active` = 1' : ''));
}



Et ensuite stocker la valeur retournée dans un cookie dans le fichier controllers/AuthController.php :

else
{
       self::$cookie->id_customer = (int)($customer->id);
       self::$cookie->customer_lastname = $customer->lastname;
   self::$cookie->customer_firstname = $customer->firstname;    
/*ici*/    self::$cookie->country = Address::getCountry((int)($customer->id));     ////////////            
   self::$cookie->logged = 1;
   self::$cookie->is_guest = $customer->isGuest();
   self::$cookie->passwd = $customer->passwd;
   self::$cookie->email = $customer->email;
   if (Configuration::get('PS_CART_FOLLOWING') AND (empty(self::$cookie->id_cart) OR Cart::getNbProducts(self::$cookie->id_cart) == 0))
   self::$cookie->id_cart = (int)(Cart::lastNoneOrderedCart((int)($customer->id)));
   /* Update cart address */
   self::$cart->id_carrier = 0;
   self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
   self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
   self::$cart->update();
   Module::hookExec('authentication');
   if (!Tools::isSubmit('ajax'))
   {
       Tools::redirect('category.php?id_category='.self::$cookie->departement);
   }
}

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...