update customer process creation

This commit is contained in:
Manuel Raynaud
2013-08-16 11:01:32 +02:00
parent 4ca78b97b5
commit 382fbe230e
6 changed files with 161 additions and 44 deletions

View File

@@ -25,6 +25,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent; use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CustomerCreateEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\CustomerCreation; use Thelia\Form\CustomerCreation;
use Thelia\Form\CustomerModification; use Thelia\Form\CustomerModification;
@@ -37,54 +38,37 @@ use Symfony\Component\Validator\Exception\ValidatorException;
use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\UsernameNotFoundException; use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Exception\PropelException;
use Thelia\Action\Exception\FormValidationException;
class Customer extends BaseAction implements EventSubscriberInterface class Customer extends BaseAction implements EventSubscriberInterface
{ {
public function create(ActionEvent $event) public function create(CustomerCreateEvent $event)
{ {
$request = $event->getRequest();
try {
$customerCreationForm = new CustomerCreation($request);
$form = $this->validateForm($customerCreationForm, "POST");
$data = $form->getData();
$customer = new CustomerModel(); $customer = new CustomerModel();
$customer->setDispatcher($event->getDispatcher()); $customer->setDispatcher($this->getDispatcher());
$customer->createOrUpdate( $customer->createOrUpdate(
$data["title"], $event->getTitle(),
$data["firstname"], $event->getFirstname(),
$data["lastname"], $event->getLastname(),
$data["address1"], $event->getAddress1(),
$data["address2"], $event->getAddress2(),
$data["address3"], $event->getAddress3(),
$data["phone"], $event->getPhone(),
$data["cellphone"], $event->getCellphone(),
$data["zipcode"], $event->getZipcode(),
$data["country"], $event->getCity(),
$data["email"], $event->getCountry(),
$data["password"], $event->getEmail(),
$request->getSession()->getLang() $event->getPassword(),
$event->getLang(),
$event->getReseller(),
$event->getSponsor(),
$event->getDiscount()
); );
$event->customer = $customer; $event->setCustomer($customer);
} catch (PropelException $e) {
Tlog::getInstance()->error(sprintf('error during creating customer on action/createCustomer with message "%s"', $e->getMessage()));
$message = "Failed to create your account, please try again.";
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
// The form has errors, propagate it.
$this->propagateFormError($customerCreationForm, $message, $event);
} }
public function modify(ActionEvent $event) public function modify(ActionEvent $event)

View File

@@ -22,9 +22,12 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Controller\Front; namespace Thelia\Controller\Front;
use Propel\Runtime\Exception\PropelException;
use Thelia\Core\Event\CustomerCreateEvent;
use Thelia\Core\Event\CustomerEvent; use Thelia\Core\Event\CustomerEvent;
use Thelia\Core\Security\SecurityContext; use Thelia\Core\Security\SecurityContext;
use Thelia\Form\CustomerCreation; use Thelia\Form\CustomerCreation;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer; use Thelia\Model\Customer;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
@@ -34,9 +37,42 @@ class CustomerController extends BaseFrontController
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$customerCreation = new CustomerCreation($$request); $customerCreation = new CustomerCreation($$request);
try {
$form = $this->validateForm($customerCreation, "post"); $form = $this->validateForm($customerCreation, "post");
$data = $form->getData();
$customerCreateEvent = new CustomerCreateEvent(
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
$data["address2"],
$data["address3"],
$data["phone"],
$data["cellphone"],
$data["zipcode"],
$data["city"],
$data["country"],
$data["email"],
$data["password"],
$request->getSession()->getLang(),
$data["reseller"],
$data["sponsor"],
$data["discount"]
);
$this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
$this->processLogin($customerCreateEvent->getCustomer());
} catch (FormValidationException $e) {
} catch (PropelException $e) {
}
} }
public function loginAction() public function loginAction()

View File

@@ -10,7 +10,12 @@
namespace Thelia\Core\Event; namespace Thelia\Core\Event;
class CustomerCreateEvent { use Symfony\Component\EventDispatcher\Event;
use Thelia\Model\Customer;
class CustomerCreateEvent extends Event {
//base parameters for creating new customer
protected $title; protected $title;
protected $firstname; protected $firstname;
protected $lastname; protected $lastname;
@@ -18,11 +23,22 @@ class CustomerCreateEvent {
protected $address2; protected $address2;
protected $address3; protected $address3;
protected $phone; protected $phone;
protected $cellphone;
protected $zipcode; protected $zipcode;
protected $city;
protected $country; protected $country;
protected $email; protected $email;
protected $password; protected $password;
protected $lang; protected $lang;
protected $reseller;
protected $sponsor;
protected $discount;
/**
* @var \Thelia\Model\Customer
*/
protected $customer;
/** /**
* @param int $title the title customer id * @param int $title the title customer id
@@ -32,13 +48,18 @@ class CustomerCreateEvent {
* @param string $address2 * @param string $address2
* @param string $address3 * @param string $address3
* @param string $phone * @param string $phone
* @param string $cellphone
* @param string $zipcode * @param string $zipcode
* @param string $city
* @param int $country the country id * @param int $country the country id
* @param string $email * @param string $email
* @param string $password plain password, don't put hash password, it will hashes again * @param string $password plain password, don't put hash password, it will hashes again
* @param $lang * @param $lang
* @param int $reseller if customer is a reseller
* @param int $sponsor customer's id sponsor
* @param float $discount
*/ */
function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $phone, $zipcode, $country, $email, $password, $lang) function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $country, $email, $password, $lang, $reseller, $sponsor, $discount)
{ {
$this->address1 = $address1; $this->address1 = $address1;
$this->address2 = $address2; $this->address2 = $address2;
@@ -50,8 +71,12 @@ class CustomerCreateEvent {
$this->lastname = $lastname; $this->lastname = $lastname;
$this->password = $password; $this->password = $password;
$this->phone = $phone; $this->phone = $phone;
$this->cellphone = $cellphone;
$this->title = $title; $this->title = $title;
$this->zipcode = $zipcode; $this->zipcode = $zipcode;
$this->reseller = $reseller;
$this->sponsor = $sponsor;
$this->discount = $discount;
} }
/** /**
@@ -134,6 +159,14 @@ class CustomerCreateEvent {
return $this->phone; return $this->phone;
} }
/**
* @return string
*/
public function getCellphone()
{
return $this->cellphone;
}
/** /**
* @return int * @return int
*/ */
@@ -150,6 +183,55 @@ class CustomerCreateEvent {
return $this->zipcode; return $this->zipcode;
} }
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @return float
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @return int
*/
public function getReseller()
{
return $this->reseller;
}
/**
* @return int
*/
public function getSponsor()
{
return $this->sponsor;
}
/**
* @param Customer $customer
*/
public function setCustomer(Customer $customer)
{
$this->customer = $customer;
}
/**
* @return Customer
*/
public function getCustomer()
{
return $this->customer;
}
} }

View File

@@ -34,4 +34,13 @@ class CustomerEvent extends InternalEvent
$this->customer = $customer; $this->customer = $customer;
} }
/**
* @return \Thelia\Model\Customer
*/
public function getCustomer()
{
return $this->customer;
}
} }

View File

@@ -56,6 +56,11 @@ final class TheliaEvents
*/ */
const CUSTOMER_LOGIN = "action.customer_login"; const CUSTOMER_LOGIN = "action.customer_login";
/**
* sent on customer account creation
*/
const CUSTOMER_CREATEACCOUNT = "action.createCustomer";
/** /**
* Sent before the logout of the administrator. * Sent before the logout of the administrator.
*/ */

View File

@@ -54,6 +54,7 @@ class Customer extends BaseCustomer implements UserInterface
* @param int $reseller * @param int $reseller
* @param null $sponsor * @param null $sponsor
* @param int $discount * @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, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0)
{ {