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 Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CustomerCreateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\CustomerCreation;
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\UsernameNotFoundException;
use Propel\Runtime\Exception\PropelException;
use Thelia\Action\Exception\FormValidationException;
class Customer extends BaseAction implements EventSubscriberInterface
{
public function create(ActionEvent $event)
public function create(CustomerCreateEvent $event)
{
$request = $event->getRequest();
try {
$customerCreationForm = new CustomerCreation($request);
$customer = new CustomerModel();
$customer->setDispatcher($this->getDispatcher());
$form = $this->validateForm($customerCreationForm, "POST");
$customer->createOrUpdate(
$event->getTitle(),
$event->getFirstname(),
$event->getLastname(),
$event->getAddress1(),
$event->getAddress2(),
$event->getAddress3(),
$event->getPhone(),
$event->getCellphone(),
$event->getZipcode(),
$event->getCity(),
$event->getCountry(),
$event->getEmail(),
$event->getPassword(),
$event->getLang(),
$event->getReseller(),
$event->getSponsor(),
$event->getDiscount()
);
$data = $form->getData();
$customer = new CustomerModel();
$customer->setDispatcher($event->getDispatcher());
$customer->createOrUpdate(
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
$data["address2"],
$data["address3"],
$data["phone"],
$data["cellphone"],
$data["zipcode"],
$data["country"],
$data["email"],
$data["password"],
$request->getSession()->getLang()
);
$event->customer = $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);
$event->setCustomer($customer);
}
public function modify(ActionEvent $event)

View File

@@ -22,9 +22,12 @@
/*************************************************************************************/
namespace Thelia\Controller\Front;
use Propel\Runtime\Exception\PropelException;
use Thelia\Core\Event\CustomerCreateEvent;
use Thelia\Core\Event\CustomerEvent;
use Thelia\Core\Security\SecurityContext;
use Thelia\Form\CustomerCreation;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer;
use Thelia\Core\Event\TheliaEvents;
@@ -34,8 +37,41 @@ class CustomerController extends BaseFrontController
{
$request = $this->getRequest();
$customerCreation = new CustomerCreation($$request);
try {
$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) {
}
$form = $this->validateForm($customerCreation, "post");
}

View File

@@ -10,7 +10,12 @@
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 $firstname;
protected $lastname;
@@ -18,11 +23,22 @@ class CustomerCreateEvent {
protected $address2;
protected $address3;
protected $phone;
protected $cellphone;
protected $zipcode;
protected $city;
protected $country;
protected $email;
protected $password;
protected $lang;
protected $reseller;
protected $sponsor;
protected $discount;
/**
* @var \Thelia\Model\Customer
*/
protected $customer;
/**
* @param int $title the title customer id
@@ -32,13 +48,18 @@ class CustomerCreateEvent {
* @param string $address2
* @param string $address3
* @param string $phone
* @param string $cellphone
* @param string $zipcode
* @param string $city
* @param int $country the country id
* @param string $email
* @param string $password plain password, don't put hash password, it will hashes again
* @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->address2 = $address2;
@@ -50,8 +71,12 @@ class CustomerCreateEvent {
$this->lastname = $lastname;
$this->password = $password;
$this->phone = $phone;
$this->cellphone = $cellphone;
$this->title = $title;
$this->zipcode = $zipcode;
$this->reseller = $reseller;
$this->sponsor = $sponsor;
$this->discount = $discount;
}
/**
@@ -134,6 +159,14 @@ class CustomerCreateEvent {
return $this->phone;
}
/**
* @return string
*/
public function getCellphone()
{
return $this->cellphone;
}
/**
* @return int
*/
@@ -150,6 +183,55 @@ class CustomerCreateEvent {
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;
}
/**
* @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";
/**
* sent on customer account creation
*/
const CUSTOMER_CREATEACCOUNT = "action.createCustomer";
/**
* Sent before the logout of the administrator.
*/

View File

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