batou Posted April 28, 2019 Share Posted April 28, 2019 (edited) Hi, I'm currently creating some custom modules. I need to do some sql select, update and insert right after a customer created his account. To do my sql, I need the e-mail used and the ID of this new customer. I don't know where to do that properly. Thank's in advance Edited August 11, 2019 by batou (see edit history) Link to comment Share on other sites More sharing options...
Janett Posted April 28, 2019 Share Posted April 28, 2019 You can use hook actionCustomerAccountAdd, new customer data is in param argument Link to comment Share on other sites More sharing options...
batou Posted April 28, 2019 Author Share Posted April 28, 2019 That means I need to create a specific module to do this ? Link to comment Share on other sites More sharing options...
Janett Posted April 28, 2019 Share Posted April 28, 2019 Yes Link to comment Share on other sites More sharing options...
batou Posted April 28, 2019 Author Share Posted April 28, 2019 Not possible to add smth like override script? I have a table with email invited and I want to compare new customer with this table. If they match, do 2 insert sql with the new id_customer If not, I will create new module thank you for your help Link to comment Share on other sites More sharing options...
Janett Posted April 28, 2019 Share Posted April 28, 2019 Override are not recommended, it's a bad practice. Use them only if any hook can be used. It's really easy to create a module to do what you need. Link to comment Share on other sites More sharing options...
batou Posted April 28, 2019 Author Share Posted April 28, 2019 Ok I just dont know how to get the new ID but I will try! Thank you Link to comment Share on other sites More sharing options...
Janett Posted April 28, 2019 Share Posted April 28, 2019 Looks into param argument, it's an array who contain useful data like Customer Id Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted April 29, 2019 Share Posted April 29, 2019 (edited) Hi.. use like this actionCustomerAccountAdd hook in your module file public function hookActionCustomerAccountAdd($params) { $id_customer = $params['newCustomer']->id; //get your customer id here return true; } Thanks Edited April 29, 2019 by Nishith (see edit history) Link to comment Share on other sites More sharing options...
batou Posted April 29, 2019 Author Share Posted April 29, 2019 (edited) Thank you Nishith. Can I add my sql request directly in this hook ? Something like ? public function hookActionObjectCustomerAddAfter($params) { $id_customer = $params['newCustomer']->id; //get your customer id here $customerEmail = $params['newCustomer']->email; //get your customer email here $sql = ' SELECT `id_list` FROM `ilea_join_list_new_customer` WHERE email='.$customerEmail; if ($results = Db::getInstance()->ExecuteS($sql)){ foreach ($results as $curent_id_list) { Db::getInstance()->insert('ilea_join_list_customer', array( 'id_customer' => (int)$id_customer, 'id_giftlist' => (int)$curent_id_list ), false, true, Db::INSERT, false); } } } > didn't work even with your hook hookActionCustomerAccountAdd Edited April 29, 2019 by batou (see edit history) Link to comment Share on other sites More sharing options...
batou Posted May 24, 2019 Author Share Posted May 24, 2019 up ! I didn't find the solution for the moment 😕 Link to comment Share on other sites More sharing options...
Janett Posted May 24, 2019 Share Posted May 24, 2019 (edited) It didn't work because your code is not right... /** * Install Module. * * @return bool */ public function install() { return parent::install() && $this->registerHook('actionCustomerAccountAdd'); } /** * Retrieve Customer data after account creation. * * @param array $params */ public function hookActionCustomerAccountAdd(array $params) { if (isset($params['newCustomer']) && Validate::isLoadedObject($params['newCustomer']) ) { $giftList = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT `id_list` FROM `ilea_join_list_new_customer` WHERE `email` LIKE "'.pSQL($params['newCustomer']->email).'" '); if ($giftList) { foreach ($giftList as $giftListItem) { Db::getInstance()->execute(' INSERT INTO `ilea_join_list_customer` (`id_customer`, `id_giftlist`) VALUES (' . (int) $params['newCustomer']->id . ', ' . (int) $giftListItem['id_list'] . ') '); } } } } If your module is already installed, reset it for hook registration. Edited May 24, 2019 by Janett (see edit history) Link to comment Share on other sites More sharing options...
Janett Posted May 31, 2019 Share Posted May 31, 2019 @KILIYATSIA Create a module and use hook ActionCustomerAccountAdd as explained 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