nguigno Posted June 5, 2020 Share Posted June 5, 2020 Hi guys, This is my first module and i'm a bit confuse, actually what i want is pretty simple atleast for a prestashop developer. My goal is to add my new user automatically in group 3 when he subscribed to our website. My code does actually nothing i don't know why, could you give me some hints ? <?php if (!defined('_PS_VERSION_')) { exit; } class iModelAttachToClientGroup extends Module { public function __construct() { $this->name = 'imodelattachtoclientgroup'; $this->tab = 'others'; $this->version = '1.0.1'; $this->author = 'Quentin'; $this->need_instance = 0; $this->ps_versions_compliancy = [ 'min' => '1.6', 'max' => _PS_VERSION_ ]; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('iModel Attach user To Client Group'); $this->description = $this->l('When a customer subscribe to our website, hes attached to the customer group Particuliers TTC, This module add him also into Client group.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('MYMODULE_NAME')) { $this->warning = $this->l('No name provided'); } } } public function install() { return parent::install(); } public function uninstall() { return parent::uninstall(); } public function hookcreateAccount($params) { $this->context->customer->addGroups(array(3)); //$this->context->customer->addGroups(3); $this->context->customer->update(); print_r("print_r TEST"); ppp("test ppp"); } ?> Sorry i'm very lost ! Thanks in advance !! Best regards. Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted June 5, 2020 Share Posted June 5, 2020 Hi.. which ps version you use ? please register "actionCustomerAccountAdd" hook in your module install method. please ps native module for example Thanks Link to comment Share on other sites More sharing options...
nguigno Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) Hi sorry ! i'm using the last version of prestashop 1.7.6.5 So i registered the hook, but i don't understand the "ps native module for exemple" ? <?php if (!defined('_PS_VERSION_')) { exit; } class iModelAttachToClientGroup extends Module { public function __construct() { $this->name = 'imodelattachtoclientgroup'; $this->tab = 'others'; $this->version = '1.0.1'; $this->author = 'Quentin'; $this->need_instance = 0; $this->ps_versions_compliancy = [ 'min' => '1.6', 'max' => _PS_VERSION_ ]; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('iModel Attach user To Client Group'); $this->description = $this->l('When a customer subscribe to our website, hes attached to the customer group Particuliers TTC, This module add him also into Client group.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('MYMODULE_NAME')) { $this->warning = $this->l('No name provided'); } } public function install() { return parent::install() and $this->registerHook('hookactionCustomerAccountAdd'); } public function uninstall() { return parent::uninstall(); } /*public function hookcreateAccount($params) { $this->context->customer->addGroups(array(3)); //$this->context->customer->addGroups(3); $this->context->customer->update(); print_r("print_r TEST"); ppp("test ppp"); }*/ public function hookactionCustomerAccountAdd(){ $this->context->customer->addGroups(array(3)); //$this->context->customer->addGroups(3); $this->context->customer->update(); print_r("print_r TEST"); ppp("test ppp"); } } Edited June 8, 2020 by nguigno forgot to paste the code (see edit history) Link to comment Share on other sites More sharing options...
nguigno Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) I tried these Hooks : hookcreateAccount hookactionCustomerAccountAdd Without any result 😕 Edited June 8, 2020 by nguigno (see edit history) Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted June 12, 2020 Share Posted June 12, 2020 (edited) Hi your code somthing look like this <?php if (!defined('_PS_VERSION_')) { exit; } class iModelAttachToClientGroup extends Module { public function __construct() { $this->name = 'imodelattachtoclientgroup'; $this->tab = 'others'; $this->version = '1.0.1'; $this->author = 'Quentin'; $this->need_instance = 0; $this->ps_versions_compliancy = [ 'min' => '1.6', 'max' => _PS_VERSION_ ]; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('iModel Attach user To Client Group'); $this->description = $this->l('When a customer subscribe to our website, hes attached to the customer group Particuliers TTC, This module add him also into Client group.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('MYMODULE_NAME')) { $this->warning = $this->l('No name provided'); } } public function install() { return parent::install() && $this->registerHook('actionCustomerAccountAdd'); } public function uninstall() { return parent::uninstall(); } public function hookActionCustomerAccountAdd($params){ $customer = $params['newCustomer']; $customer->addGroups(array(3)); //3 id of customer group } } if add new hook in your module then uninstall and install module again Thank you Edited June 12, 2020 by Nishith (see edit history) Link to comment Share on other sites More sharing options...
nguigno Posted June 15, 2020 Author Share Posted June 15, 2020 Love you man !! thank you very much that work ! Have a great day Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted June 15, 2020 Share Posted June 15, 2020 On 6/15/2020 at 8:23 AM, nguigno said: Love you man !! thank you very much that work ! Have a great day Expand you are welocome Thank you Link to comment Share on other sites More sharing options...
brunobibos Posted June 5, 2023 Share Posted June 5, 2023 After many tries, this worked as well for me! Thanks a lot! 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