allow to reuse creation customer method for modification. Password is
not mandatory
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Event\CustomRefEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
@@ -39,12 +40,12 @@ class Customer extends BaseCustomer
|
||||
* @param string $zipcode customer zipcode
|
||||
* @param int $countryId customer country id (from Country table)
|
||||
* @param string $email customer email, must be unique
|
||||
* @param string $plainPassword customer plain password, hash is made calling setPassword method
|
||||
* @param string $plainPassword customer plain password, hash is made calling setPassword method. Not mandatory parameter but an exception is thrown if customer is new without password
|
||||
* @param int $reseller
|
||||
* @param null $sponsor
|
||||
* @param int $discount
|
||||
*/
|
||||
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $countryId, $email, $plainPassword, $reseller = 0, $sponsor = null, $discount = 0 )
|
||||
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $countryId, $email, $plainPassword = null, $reseller = 0, $sponsor = null, $discount = 0 )
|
||||
{
|
||||
$this
|
||||
->setCustomerTitleId($titleId)
|
||||
@@ -86,8 +87,15 @@ class Customer extends BaseCustomer
|
||||
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->setAlgo("PASSWORD_BCRYPT");
|
||||
return parent::setPassword(password_hash($password, PASSWORD_BCRYPT));
|
||||
if ($this->isNew() && ($password === null || trim($password) == "")) {
|
||||
throw new InvalidArgumentException("customer password is mandatory on creation");
|
||||
}
|
||||
|
||||
if($password !== null && trim($password) != "") {
|
||||
$this->setAlgo("PASSWORD_BCRYPT");
|
||||
return parent::setPassword(password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
|
||||
Reference in New Issue
Block a user