Jump to content

Send Email On Customer Creation Via Webservice


zencompany

Recommended Posts

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 by zencompany (see edit history)
Link to comment
Share on other sites

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

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

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.

  • Like 1
Link to comment
Share on other sites

  • 7 months later...
  • 2 weeks later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...