zencompany Posted February 4, 2016 Share Posted February 4, 2016 (edited) Hello Everyone, When I create customers via webservice NO welcome email is sent to the customer email address with login credentials while this is perfectly working if a customer is created from frontend. I would like to know if this is a bug, do you know where exactly the database query is executed on customer creation ? Please help as it's urgent for me. Edited February 5, 2016 by zencompany (see edit history) Link to comment Share on other sites More sharing options...
zencompany Posted February 5, 2016 Author Share Posted February 5, 2016 up Link to comment Share on other sites More sharing options...
yaniv14 Posted February 5, 2016 Share Posted February 5, 2016 I am not sure if webservice will trigger the welcome email. The AuthController in controllers/front is the controller that create the user on the front end. Check function processSubmitAccount. Maybe you will have to sent the mail manually with the webservice it self (look for sendConfirmationMail function in the same file). Link to comment Share on other sites More sharing options...
zencompany Posted February 8, 2016 Author Share Posted February 8, 2016 Hello, I tried to update AuthController in controllers/front but this file seems to be not used while the webservice is adding the customer, I succesfully added static function call Mail::Send to classes/Customer.php add() function and the mail is now triggered, however the password is already salted and hashed and it does not make sense to send this to the customer. (the object at this point is already containing the encoded password) Do you know if there's a way to send the email within the function (where the password is hashed) so it's still available\the plain one send to the webservice ? Thank you. Link to comment Share on other sites More sharing options...
yaniv14 Posted February 8, 2016 Share Posted February 8, 2016 Why can't you call your own mail send function inside the webservice call instead of adding it to the customer class. in this case you will have the password. Link to comment Share on other sites More sharing options...
zencompany Posted February 8, 2016 Author Share Posted February 8, 2016 Do you know how this can be achieved ? What file I have to modify? Link to comment Share on other sites More sharing options...
zencompany Posted February 8, 2016 Author Share Posted February 8, 2016 Ok, I solved this. Here is the solution I applied to the Customer.php file. 1. Set the objectMethods to the $webserviceParameters array : protected $webserviceParameters = array( 'objectMethods' => array( 'add' => 'addWs' ), 'fields' => array( 'id_default_group' => array('xlink_resource' => 'groups'), 'id_lang' => array('xlink_resource' => 'languages'), 'newsletter_date_add' => array(), 'ip_registration_newsletter' => array(), 'last_passwd_gen' => array('setter' => null), 'secure_key' => array('setter' => null), 'deleted' => array(), 'passwd' => array('setter' => 'setWsPasswd') ), 'associations' => array( 'groups' => array('resource' => 'groups'), ) ); 2. Add new addWS() function to CustomerCore class so it's used by webservice only. public function addWs($autodate = true, $null_values = true) { $this->id_shop = ($this->id_shop) ? $this->id_shop : Context::getContext()->shop->id; $this->id_shop_group = ($this->id_shop_group) ? $this->id_shop_group : Context::getContext()->shop->id_shop_group; $this->id_lang = ($this->id_lang) ? $this->id_lang : Context::getContext()->language->id; $this->birthday = (empty($this->years) ? $this->birthday : (int)$this->years.'-'.(int)$this->months.'-'.(int)$this->days); $this->secure_key = md5(uniqid(rand(), true)); $this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_FRONT').'minutes')); if ($this->newsletter && !Validate::isDate($this->newsletter_date_add)) $this->newsletter_date_add = date('Y-m-d H:i:s'); if ($this->id_default_group == Configuration::get('PS_CUSTOMER_GROUP')) if ($this->is_guest) $this->id_default_group = (int)Configuration::get('PS_GUEST_GROUP'); else $this->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP'); /* Can't create a guest customer, if this feature is disabled */ //if ($this->is_guest && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) //return false; $vars = array( '{firstname}' => $this->firstname, '{lastname}' => $this->lastname, '{email}' => $this->email, '{passwd}' => $this->plainpasswd ); Mail::Send( 1, 'account', Mail::l('Welcome!', (int)$id_lang), $vars, $this->email, $this->firstname.' '.$this->lastname, null, null, null, null, _PS_MAIL_DIR_, false, (int)$this->id_shop ); $success = parent::add($autodate, $null_values); $this->updateGroup($this->groupBox); return $success; } 3. Set the passwd value to $this->plainpasswd to get it plain as this needs to be human readable to the email user: public function setWsPasswd($passwd) { $this->plainpasswd = $passwd; if ($this->id != 0) { if ($this->passwd != $passwd) $this->passwd = Tools::encrypt($passwd); } else $this->passwd = Tools::encrypt($passwd); return true; } Thank for your support, I hope this can be helpful for someone. 1 Link to comment Share on other sites More sharing options...
polpol Posted September 23, 2016 Share Posted September 23, 2016 Thank you zencompany, works great! Does anyone know if this can be achieved using php files in override folder? Link to comment Share on other sites More sharing options...
R_Zorzo Posted October 6, 2016 Share Posted October 6, 2016 Of course you can allways make an override so you keep you changes safe in case of updates and so. Even more, this should be the correct way of modifying a core class. So create override/classes/Customer.php <?php class Customer extends CustomerCore { //Paste here the code ZendCompany wrote. } Don´t forget to delete your class_index.php after all this. See ya! 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