pouc Posted December 22, 2014 Share Posted December 22, 2014 (edited) Bonjour, Voici mon problème, je souhaiterais lors de l'inscription d'un nouveau client si celui-ci remplie ou non une variable présente sur le formulaire qu'il s'implante dans un groupe différent. Donc dans customer.php j'ai le code suivant: public function __construct($id = null) { $this->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP'); if(empty($mavariable)){ $this->id_group =6;} else{ $this->id_group =800;} parent::__construct($id); } Mais ça ne fonctionne pas du tout, quelqu'un aurait-il une solution? Merci. Baptiste Edited January 20, 2015 by pouc (see edit history) Link to comment Share on other sites More sharing options...
Baba deCode Posted December 22, 2014 Share Posted December 22, 2014 Est ce que $mavariable est assigné a smarty ? Link to comment Share on other sites More sharing options...
Mediacom87 Posted December 22, 2014 Share Posted December 22, 2014 Bonjour, pour réaliser cela il existe déjà un module http://www.prestatoolbox.fr/nos-modules/158-groupe-vip.html Link to comment Share on other sites More sharing options...
pouc Posted December 22, 2014 Author Share Posted December 22, 2014 (edited) C'est à dire alexandre-KM? Edited December 22, 2014 by pouc (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted December 22, 2014 Share Posted December 22, 2014 Sous quelle version de Presta êtes-vous ? Ensuite l'approche ne me parait pas la meilleure en tapant dans la classe mère, le controller est fait pour ça Aller dans la fonction protected function processSubmitAccount() et y rajouter vos conditions au niveau de if (!$customer->is_guest) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP'))); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int)Configuration::get('PS_GUEST_GROUP'))); } Vous remarquerez que la fonction addGroups() attend un array, qui dans le cas général ne possède qu'une entrée. Vous pouvez donc rajouter la votre. Concernant la variable, pas besoin de l'assigner par smarty un simple $ma_variable = Tools::getValue('ma_condition'); suffit. Vous pouvez aussi passer par un module et vous accrocher au hook: actionAuthentication pour effectuer le changement de groupe une fois l'inscription réussie. 1 Link to comment Share on other sites More sharing options...
pouc Posted December 23, 2014 Author Share Posted December 23, 2014 Merci pour cette réponse mais je manque un peu de connaissance en php et bien que vous m'ayez bien mis sur la piste je ne sais pas absolument pas ou et quoi mettre!! "$ma_variable = Tools::getValue('ma_condition');" je dois le mettre ou exactement? et comment je rédige ma condition? Merci. Baptiste Link to comment Share on other sites More sharing options...
Eolia Posted December 23, 2014 Share Posted December 23, 2014 Bon, je pense que vous allez modifier le fichier authentification.tpl pour y rajouter votre case à cocher, donc quelquechose du genre <div class="checkbox"> <label for="my_group"> <input type="checkbox" name="my_group" id="my_group" value="1" /> {l s='Votre texte correspondant à la cas à cocher'}</label> </div> Donc vous récupérez la valeur de la checkbox (0 ou 1) dans "$ma_variable = Tools::getValue('my_group');" Et dans le controller vous remplacez le bloc cité ci-dessus par: $ma_variable = Tools::getValue('my_group'); $id_special_group = 'id du groupe spécial que vous avez créé'; if(!$customer->is_guest && $ma_variable == 1) { $this->context->customer = $customer; $customer->cleanGroups(); //Vous incluez votre client dans ce groupe spécial $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP')), (int)$id_special_group); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } elseif (!$customer->is_guest && $ma_variable == 0) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP'))); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int)Configuration::get('PS_GUEST_GROUP'))); } Link to comment Share on other sites More sharing options...
pouc Posted December 23, 2014 Author Share Posted December 23, 2014 En faite sur mon authentification.tpl j'ai justement ma variable(un numéro d'identification professionnel) qui est déjà présente, et je voudrais faire un contrôle "si cette variable à été remplie" alors le nouvel ,arrivant = groupe par défaut + autre groupe id=800 sinon = groupe par défaut + autre groupe id=6." Mais il ne faut pas que le client est à choisir le groupe dans lequel il doit être ça doit être automatique, a moins qu'en suivant votre solution je réalise une checkbox caché sur mon tpl en y mettant la condition si le champ est remplie checkbox =1 sinon = 0. Qu'en pensez-vous? Baptiste Link to comment Share on other sites More sharing options...
Eolia Posted December 23, 2014 Share Posted December 23, 2014 ben si votre option existe déjà il suffit de récupérer sa valeur comme dans mon exemple. Il faudrait le bout de code de votre tpl pour savoir... Link to comment Share on other sites More sharing options...
pouc Posted December 23, 2014 Author Share Posted December 23, 2014 j'ai rien dans mon tpl mise à part le champ <p class="text"> <label for="nthera">{l s='Numéro Thérapeute'}</label> <input type="text" class="text" id="nthera" name="nthera" value="{if isset($smarty.post.nthera)}{$smarty.post.nthera}{/if}" /> </p> qui est celui que je veux vérifier. Du coup je suis en train de regarder pour réaliser une checkbox caché mais c'est plus dur que je ne pensais, et la question que je me pose est ce qu'il faut que crée la checkbox en faisa,t toute les manips de l'ajout dans la bdd de la création en override. Baptiste Link to comment Share on other sites More sharing options...
Eolia Posted December 23, 2014 Share Posted December 23, 2014 donc $ma_variable = Tools::getValue('nthera'); pas besoin de checkbox pour le coup Link to comment Share on other sites More sharing options...
pouc Posted December 23, 2014 Author Share Posted December 23, 2014 ah ok!!^^ Merci beaucoup!! Baptiste Link to comment Share on other sites More sharing options...
pouc Posted December 24, 2014 Author Share Posted December 24, 2014 ça ne fonctionne pas!! if (!count($this->errors)) { $ma_variable = Tools::getValue('nthera'); $id_special_group = '800'; if (!$customer->is_guest && $ma_variable == 1) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP')),(int)$id_special_group); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } elseif (!$customer->is_guest && $ma_variable == 0) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP'))); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int)Configuration::get('PS_GUEST_GROUP'))); } est-ce que j'ai fait une erreur quelques part? Baptiste Link to comment Share on other sites More sharing options...
Eolia Posted December 24, 2014 Share Posted December 24, 2014 Ben logique ^^ l'exemple que je t'avais donné était pour une checkbox donc valeur 1 ou 0 Que te retourne Tools::getValue('nthera') ? c'est cette valeur qu'il faut évaluer Link to comment Share on other sites More sharing options...
pouc Posted December 24, 2014 Author Share Posted December 24, 2014 oh mais oui je suis vraiment trop c*n!! =) yes c'est nthera qu'il faut évaluer. Link to comment Share on other sites More sharing options...
pouc Posted January 5, 2015 Author Share Posted January 5, 2015 et du coup quelle modification je dois apporter pour que cela fonctionne? Link to comment Share on other sites More sharing options...
pouc Posted January 13, 2015 Author Share Posted January 13, 2015 pas d'idées? Link to comment Share on other sites More sharing options...
Mediacom87 Posted January 13, 2015 Share Posted January 13, 2015 Bonjour, pour réaliser cela il existe déjà un module http://www.prestatoolbox.fr/nos-modules/158-groupe-vip.html Moi j'avais déjà donné la solution il y 3 semaines Link to comment Share on other sites More sharing options...
Eolia Posted January 13, 2015 Share Posted January 13, 2015 Vous pouvez coller ici le contenu (la partie concernée, bien sûr) de votre tpl et de votre contrôleur ? Link to comment Share on other sites More sharing options...
pouc Posted January 13, 2015 Author Share Posted January 13, 2015 (edited) Dans mon tpl du coup je n'ai fais aucune modification!! et dans authController : if (!count($this->errors)) { $ma_variable = Tools::getValue('nthera'); $id_special_group = '800'; if (!$customer->is_guest && empty($ma_variable)) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP')),(int)$id_special_group); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int)Configuration::get('PS_GUEST_GROUP'))); } Edited January 13, 2015 by pouc (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted January 13, 2015 Share Posted January 13, 2015 if (!count($this->errors)) { $ma_variable = Tools::getValue('nthera'); $id_special_group = '800'; if (!$customer->is_guest && !empty($ma_variable)) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the special customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP')),(int)$id_special_group); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } elseif (!$customer->is_guest && empty($ma_variable)) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP'))); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int)Configuration::get('PS_GUEST_GROUP'))); } Devrait fonctionner Link to comment Share on other sites More sharing options...
pouc Posted January 13, 2015 Author Share Posted January 13, 2015 Je pense que le votre code doit fonctionner mais par contre j'ai pas l'impression qu'un des codes de presta ne fait pas la différence entre ma variable remplie et ma variable vide. Donc votre code ne fonctionne pas est-ce qu'il y aurait un moyen de savoir si presta prends en compte ma variable ou pas. Baptiste Link to comment Share on other sites More sharing options...
pouc Posted January 20, 2015 Author Share Posted January 20, 2015 des idées? Link to comment Share on other sites More sharing options...
Eolia Posted January 20, 2015 Share Posted January 20, 2015 if (!count($this->errors)) { $ma_variable = Tools::getValue('nthera'); die(var_dump($ma_variable)); $id_special_group = '800'; ... Et regardez le résultat Link to comment Share on other sites More sharing options...
pouc Posted January 20, 2015 Author Share Posted January 20, 2015 Il ne se passe rien!! Link to comment Share on other sites More sharing options...
Eolia Posted January 20, 2015 Share Posted January 20, 2015 Exact car le client est créé avant d'arriver à cette étape.Supprimez vos modifs dans le controller et insérez ceci dans la classe Customer.php, ligne 222 juste avant /* Can't create a guest customer, if this feature is disabled */ $ma_variable = Tools::getValue('my_group'); $id_special_group = '4'; if(!empty($ma_variable)) $this->id_default_group = (int)$id_special_group; /* Can't create a guest customer, if this feature is disabled */ Changez bien sûr le nom de la variable 'my_group' et l'id du groupe spécial suivant vos paramètres de boutique.Le code ci-dessus est testé et fonctionnel sur une 1.6 avec cet ajout dans le authentification.tpl juste avant les checkboxes newsletter et optin: <div class="checkbox"> <label for="my_group"> <input type="checkbox" name="my_group" id="my_group" value="1" /> {l s='Votre texte correspondant à la case à cocher'}</label> </div> {if $newsletter} ... Link to comment Share on other sites More sharing options...
pouc Posted January 20, 2015 Author Share Posted January 20, 2015 Parfait!! j'ai réussi avec quelques légère modification mais en tout cas ça marche. alors ligne 220 dans customer.php j'ai ceux-ci: public function __construct($id = null) { $ma_variable = Tools::getValue('nthera'); $id_special_group = '800'; if (!empty($ma_variable)) { $this->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP'); $this->id_group = (int)$id_special_group; } else{ $this->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP'); $this->id_group =6; } parent::__construct($id); } Donc si ma variable est remplie il est inscrit dans le groupe client et dans l'id 800 sinon il est inscrit dans le groupe client et l'id 6. Merci beaucoup pour votre aide!! Baptiste Link to comment Share on other sites More sharing options...
Eolia Posted January 20, 2015 Share Posted January 20, 2015 Ce n'est pas une bonne idée de mettre la modif dans le __construct(), car là, à chaque instanciation d'un objet customer vous traitez l'id_default pour rien. Je vous l'avais mis dans la fonction add(), car c'est celle-ci qui est appelée au moment de l'inscription^^ Link to comment Share on other sites More sharing options...
pouc Posted January 20, 2015 Author Share Posted January 20, 2015 Ah oui j'avais pas fais gaffe je vais changer ça!!^^ Merci! Link to comment Share on other sites More sharing options...
wouababelouba Posted April 24, 2015 Share Posted April 24, 2015 (edited) Bonjour, Je me permets de relancer le sujet, en ce qui me concerne j'utilise la méthode de surcharge du contrôleur AuthController décrite initialement par Eolia, et cela fonctionne très bien. Voilà mon code : if (!count($this->errors)) { if (!$customer->is_guest) { $this->context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP'))); if (!$this->sendConfirmationMail($customer)) $this->errors[] = Tools::displayError('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int)Configuration::get('PS_GUEST_GROUP'))); } /*** * OVERRIDE BEGINS * Auto assignation au groupe pro (id = 4) si SIRET existe ***/ $siret = (Tools::isSubmit('siret')) ? (int)Tools::getValue('siret') : ''; if($siret != '') { $customer->cleanGroups(); $customer->addGroups(array((int)4)); } ... Mais j'aurais aimé pouvoir rendre ça plus "administrable", en laissant le choix via le backoffice de créer des conditions d'auto-assignation, pour le groupe pro mais également d'autres. Par exemple, en utilisant le champ date de naissance, indiquer une année dans le backoffice qui permettrait de placer un client dans un groupe "jeunes de moins de 25 ans". Et dans AuthController cela pourrait donner ça : if($birthyear != '' && (date("Y") - $birthyear <= 25)) { $customer->addGroups(array((int)5)); // avec 5 ID du groupe jeunes moins 25 ans } Est-ce qu'un module qui fait ça existe déjà ? Merci ! Edited April 24, 2015 by wouababelouba (see edit history) 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