From 8b8ea994ef7012f282df201ed986e9064914ab16 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 3 Jul 2013 10:33:25 +0200 Subject: [PATCH] allow to reuse creation customer method for modification. Password is not mandatory --- core/lib/Thelia/Model/Customer.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index e295bb215..ca3cc7882 100755 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -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)