refactor action customer

This commit is contained in:
Manuel Raynaud
2013-08-16 14:04:44 +02:00
parent 5b23e1ca41
commit 4f31627301
6 changed files with 147 additions and 69 deletions

View File

@@ -6,7 +6,7 @@ use Symfony\Component\Config\Definition\Exception\Exception;
use Thelia\Core\Event\Internal\CustomerEvent;
use Thelia\Model\Base\Customer as BaseCustomer;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Thelia\Model\Exception\InvalidArgumentException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\CustomRefEvent;
@@ -56,7 +56,7 @@ class Customer extends BaseCustomer implements UserInterface
* @param int $discount
* @throws \Exception|\Symfony\Component\Config\Definition\Exception\Exception
*/
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0)
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0)
{
$this
->setTitleId($titleId)
@@ -169,6 +169,21 @@ class Customer extends BaseCustomer implements UserInterface
return $this;
}
public function setEmail($email, $force = false)
{
$email = trim($email);
if ($this->isNew() && ($email === null || $email == "")) {
throw new InvalidArgumentException("customer email is mandatory on creation");
}
if (!$this->isNew() && $force === false) {
return $this;
}
return parent::setEmail($email);
}
public function setDispatcher(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;

View File

@@ -0,0 +1,27 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Model\Exception;
class InvalidArgumentException extends ModelException
{}

View File

@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Model\Exception;
class ModelException extends \RuntimeException
{
}