Alexandre Carette Posted March 12, 2016 Share Posted March 12, 2016 (edited) Bonjour, J'ai un formulaire qui permet la création d'un compte, l'utilisateur choisit son groupe de client... le traitement du formulaire marche sauf pour l'assignation du client au groupe par defaut... Je suis en prestashop 1.6.1.4 J'aimerai assigner le groupe de client par défaut lors de la création d'un compte, voici ma fonction: public static function registeraccount($firstname,$lastname,$mail,$password,$group) { $passwd = md5(_COOKIE_KEY_.$password); $customer = new Customer(); $customer->passwd = $passwd; $customer->email = $mail; $customer->firstname = $firstname; $customer->lastname = $lastname; $customer->active = 1; $customer->newsletter = 0; $customer->add(); $customer->cleanGroups(); $customer->addGroups(array(3,$group)); $customer->id_default_group = $group; //Ne marche pas $context = Context::getContext(); $context->cookie->__set('id_customer' , $customer->id); $context->cookie->__set('customer_lastname' , $customer->lastname); $context->cookie->__set('customer_firstname' , $customer->firstname); $context->cookie->__set('passwd' , $customer->passwd); $context->cookie->__set('logged' , 1); $context->cookie->__set('email' , $customer->email); $context->cart->secure_key = $customer->secure_key; Tools::redirect('index.php'); } Pouvez vous m'aider ? Merci beaucoup Edited March 12, 2016 by Alex-Kodd (see edit history) Link to comment Share on other sites More sharing options...
KenzoDev Posted March 12, 2016 Share Posted March 12, 2016 Bonsoir, j'ai une fonction similiare sur un 1.6.1.4, inspirée de processSubmitAccount dans l'AuthController, et dans mon cas $customer->id_default_group = (int)$group_default fonctionne bien. Par contre, $customer->add(); devrait être placé après l'assignation du groupe par default. 1 Link to comment Share on other sites More sharing options...
Alexandre Carette Posted March 12, 2016 Author Share Posted March 12, 2016 (edited) Merci KenzoDev ca marche super bien ! class UserRegister extends ObjectModel { public static function registeraccount($firstname,$lastname,$mail,$password,$group) { $passwd = md5(_COOKIE_KEY_.$password); $customer = new Customer(); $customer->passwd = $passwd; $customer->email = $mail; $customer->firstname = $firstname; $customer->lastname = $lastname; $customer->active = 1; $customer->newsletter = 0; $customer->id_default_group = (int)$group; // Ca marche $customer->add(); $customer->cleanGroups(); $customer->addGroups(array(3,$group)); $context = Context::getContext(); $context->cookie->__set('id_customer' , $customer->id); $context->cookie->__set('customer_lastname' , $customer->lastname); $context->cookie->__set('customer_firstname' , $customer->firstname); $context->cookie->__set('passwd' , $customer->passwd); $context->cookie->__set('logged' , 1); $context->cookie->__set('email' , $customer->email); $context->cart->secure_key = $customer->secure_key; Tools::redirect('index.php'); } } Edited March 12, 2016 by Alex-Kodd (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted March 13, 2016 Share Posted March 13, 2016 Si 3 correspond à ton groupe client par défaut et que tu veux que ton code soit portable, je te conseille d'utiliser la variable définie en base de données: $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP'), (int)$group)); 1 Link to comment Share on other sites More sharing options...
Alexandre Carette Posted March 13, 2016 Author Share Posted March 13, 2016 Si 3 correspond à ton groupe client par défaut OK merci Eolia, oui c'est bien ca ! Link to comment Share on other sites More sharing options...
bbxe Posted January 2, 2019 Share Posted January 2, 2019 Bonjour, Merci pour vos échanges. Dans quel fichier éditez-vous cette fonction ? Link to comment Share on other sites More sharing options...
Eolia Posted January 3, 2019 Share Posted January 3, 2019 Comme c'est écrit plus haut^^ Le 12/03/2016 à 7:41 PM, KenzoDev a dit : processSubmitAccount dans l'AuthController Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now