add address create controller and event

This commit is contained in:
Manuel Raynaud
2013-09-03 16:13:17 +02:00
parent 394b533dd7
commit 5c3ac1561d
9 changed files with 471 additions and 11 deletions

View File

@@ -0,0 +1,84 @@
<?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\Controller\Front;
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\AddressForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer;
use Thelia\Tools\URL;
/**
* Class CustomerAddressController
* @package Thelia\Controller\Front
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class CustomerAddressController extends BaseFrontController
{
public function createAction()
{
if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirect(URL::getIndexPage());
}
$addressCreate = new AddressForm($this->getRequest());
try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressCreate, "post");
$event = $this->createAddressEvent($form->getData(), $customer);
$this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);
}catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $e->getMessage());
}
catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}
}
protected function createAddressEvent($data, Customer $customer)
{
return new AddressCreateOrUpdateEvent(
$data["label"],
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
$data["address2"],
$data["address3"],
$data["zipcode"],
$data["city"],
$data["country"],
$data["cellpone"],
$data["phone"],
$data["company"],
$customer
);
}
}

View File

@@ -71,10 +71,10 @@ class CustomerController extends BaseFrontController
$this->redirectSuccess($customerCreation);
}
catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $ex->getMessage());
$message = sprintf("Please check your input: %s", $e->getMessage());
}
catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $ex->getMessage());
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}
if ($message !== false) {
@@ -119,14 +119,14 @@ class CustomerController extends BaseFrontController
}
catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $ex->getMessage());
$message = sprintf("Please check your input: %s", $e->getMessage());
}
catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $ex->getMessage());
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s. Exception was %s", $message, $e->getMessage()));
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message));
$customerModification->setErrorMessage($message);
@@ -167,7 +167,7 @@ class CustomerController extends BaseFrontController
}
catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $ex->getMessage());
$message = sprintf("Please check your input: %s", $e->getMessage());
}
catch(UsernameNotFoundException $e) {
$message = "This customer email was not found.";
@@ -179,7 +179,7 @@ class CustomerController extends BaseFrontController
$message = "Sorry, we failed to authentify you. Please try again.";
}
catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $ex->getMessage());
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}
if ($message !== false) {