validate create and update address in front context

This commit is contained in:
Manuel Raynaud
2013-09-04 17:52:58 +02:00
parent 3cb4e6ff2e
commit ceb02841e1
21 changed files with 482 additions and 65 deletions

View File

@@ -22,6 +22,11 @@
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
</service> </service>
<service id="thelia.action.address" class="Thelia\Action\Address">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.image" class="Thelia\Action\Image"> <service id="thelia.action.image" class="Thelia\Action\Image">
<argument type="service" id="service_container"/> <argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>

View File

@@ -43,6 +43,9 @@
<form name="thelia.customer.login" class="Thelia\Form\CustomerLogin"/> <form name="thelia.customer.login" class="Thelia\Form\CustomerLogin"/>
<form name="thelia.admin.login" class="Thelia\Form\AdminLogin"/> <form name="thelia.admin.login" class="Thelia\Form\AdminLogin"/>
<form name="thelia.address.create" class="Thelia\Form\AddressCreateForm" />
<form name="thelia.address.update" class="Thelia\Form\AddressUpdateForm" />
<form name="thelia.admin.category.creation" class="Thelia\Form\CategoryCreationForm"/> <form name="thelia.admin.category.creation" class="Thelia\Form\CategoryCreationForm"/>
<form name="thelia.admin.category.deletion" class="Thelia\Form\CategoryDeletionForm"/> <form name="thelia.admin.category.deletion" class="Thelia\Form\CategoryDeletionForm"/>

View File

@@ -30,7 +30,17 @@
<!-- customer address routes --> <!-- customer address routes -->
<route id="address.create" path="/address/create" > <route id="address.create" path="/address/create" >
<default key="_controller">Thelia\Controller\Front\CustomerAddressController::createAction</default> <default key="_controller">Thelia\Controller\Front\AddressController::createAction</default>
<default key="_view">address</default>
</route>
<route id="address.edit" path="/address/edit/{address_id}">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">address_edit</default>
</route>
<route id="address.update" path="/address/update" >
<default key="_controller">Thelia\Controller\Front\AddressController::updateAction</default>
</route> </route>
<!-- end customer address routes --> <!-- end customer address routes -->
@@ -50,7 +60,7 @@
<default key="_view">cart</default> <default key="_view">cart</default>
</route> </route>
<route id="url-rewriting.check" path="/{rewritten_url}" methods="GET"> <!-- <route id="url-rewriting.check" path="/{rewritten_url}" methods="GET">
<default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default> <default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default>
</route> </route>-->
</routes> </routes>

View File

@@ -24,33 +24,41 @@
namespace Thelia\Controller\Front; namespace Thelia\Controller\Front;
use Thelia\Core\Event\AddressCreateOrUpdateEvent; use Thelia\Core\Event\AddressCreateOrUpdateEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\AddressForm; use Thelia\Form\AddressCreateForm;
use Thelia\Form\AddressUpdateForm;
use Thelia\Form\Exception\FormValidationException; use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Base\AddressQuery;
use Thelia\Model\Customer; use Thelia\Model\Customer;
use Thelia\Tools\URL; use Thelia\Tools\URL;
/** /**
* Class CustomerAddressController * Class AddressController
* @package Thelia\Controller\Front * @package Thelia\Controller\Front
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class CustomerAddressController extends BaseFrontController class AddressController extends BaseFrontController
{ {
/**
* Create controller.
* Check if customer is logged in
*
* Dispatch TheliaEvents::ADDRESS_CREATE event
*/
public function createAction() public function createAction()
{ {
if ($this->getSecurityContext()->hasCustomerUser() === false) { if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirect(URL::getIndexPage()); $this->redirect(URL::getIndexPage());
} }
$addressCreate = new AddressForm($this->getRequest()); $addressCreate = new AddressCreateForm($this->getRequest());
try { try {
$customer = $this->getSecurityContext()->getCustomerUser(); $customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressCreate, "post"); $form = $this->validateForm($addressCreate, "post");
$event = $this->createAddressEvent($form->getData()); $event = $this->createAddressEvent($form);
$event->setCustomer($customer); $event->setCustomer($customer);
$this->dispatch(TheliaEvents::ADDRESS_CREATE, $event); $this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);
@@ -77,25 +85,74 @@ class CustomerAddressController extends BaseFrontController
public function updateAction() public function updateAction()
{ {
$request = $this->getRequest();
if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirectToRoute("home");
}
if(null === $address_id = $request->get("address_id")) {
$this->redirectToRoute("home");
}
$addressUpdate = new AddressUpdateForm($request);
try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressUpdate);
$address = AddressQuery::create()->findPk($address_id);
if (null === $address) {
$this->redirectToRoute("home");
}
if($address->getCustomer()->getId() != $customer->getId()) {
$this->redirectToRoute("home");
}
$event = $this->createAddressEvent($form);
$event->setAddress($address);
$this->dispatch(TheliaEvents::ADDRESS_UPDATE, $event);
$this->redirectSuccess($addressUpdate);
}catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $e->getMessage());
}
catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
$addressUpdate->setErrorMessage($message);
$this->getParserContext()
->addForm($addressUpdate)
->setGeneralError($message)
;
}
} }
protected function createAddressEvent($data) protected function createAddressEvent($form)
{ {
return new AddressCreateOrUpdateEvent( return new AddressCreateOrUpdateEvent(
$data["label"], $form->get("label")->getData(),
$data["title"], $form->get("title")->getData(),
$data["firstname"], $form->get("firstname")->getData(),
$data["lastname"], $form->get("lastname")->getData(),
$data["address1"], $form->get("address1")->getData(),
$data["address2"], $form->get("address2")->getData(),
$data["address3"], $form->get("address3")->getData(),
$data["zipcode"], $form->get("zipcode")->getData(),
$data["city"], $form->get("city")->getData(),
$data["country"], $form->get("country")->getData(),
$data["cellpone"], $form->get("cellphone")->getData(),
$data["phone"], $form->get("phone")->getData(),
$data["company"] $form->get("company")->getData()
); );
} }
} }

View File

@@ -23,6 +23,7 @@
namespace Thelia\Controller\Front; namespace Thelia\Controller\Front;
use Thelia\Controller\BaseController; use Thelia\Controller\BaseController;
use Thelia\Tools\URL;
class BaseFrontController extends BaseController class BaseFrontController extends BaseController
{ {

View File

@@ -56,13 +56,16 @@ class DefaultController extends BaseFrontController
} }
} }
$view = null;
if (! $view = $request->query->get('view')) { if (! $view = $request->query->get('view')) {
$view = "index";
if ($request->request->has('view')) { if ($request->request->has('view')) {
$view = $request->request->get('view'); $view = $request->request->get('view');
} }
} }
if(!is_null($view)) {
$request->attributes->set('_view', $view);
}
$request->attributes->set('_view', $view);
} }
} }

View File

@@ -0,0 +1,54 @@
<?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\Core\Event;
use Symfony\Component\EventDispatcher\Event;
use Thelia\Model\Address;
/**
* Class AddressEvent
* @package Thelia\Core\Event
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AddressEvent extends ActionEvent
{
/**
* @var \Thelia\Model\Address
*/
protected $address;
function __construct(Address $address)
{
$this->address = $address;
}
/**
* @return \Thelia\Model\Address
*/
public function getAddress()
{
return $this->address;
}
}

View File

@@ -88,12 +88,13 @@ final class TheliaEvents
/** /**
* Sent once the customer change form has been successfully validated, and before customer update in the database. * Sent once the customer change form has been successfully validated, and before customer update in the database.
*/ */
const BEFORE_CHANGECUSTOMER = "action.before_updateCustomer"; const BEFORE_UPDATECUSTOMER = "action.before_updateCustomer";
/** /**
* Sent just after a successful update of a customer in the database. * Sent just after a successful update of a customer in the database.
*/ */
const AFTER_CHANGECUSTOMER = "action.after_updateCustomer"; const AFTER_UPDATECUSTOMER = "action.after_updateCustomer";
// -- ADDRESS MANAGEMENT ---------------------------------------------------------
/** /**
* sent for address creation * sent for address creation
*/ */
@@ -104,6 +105,17 @@ final class TheliaEvents
*/ */
const ADDRESS_UPDATE = "action.updateAddress"; const ADDRESS_UPDATE = "action.updateAddress";
const BEFORE_CREATEADDRESS = "action.before_createAddress";
const AFTER_CREATEADDRESS = "action.after_createAddress";
const BEFORE_UPDATEADDRESS = "action.before_updateAddress";
const AFTER_UPDATEADDRESS = "action.after_updateAddress";
const BEFORE_DELETEADDRESS = "action.before_deleteAddress";
const AFTER_DELETEADDRESS = "action.after_deleteAddress";
// -- END ADDRESS MANAGEMENT ---------------------------------------------------------
/** /**
* Sent once the category creation form has been successfully validated, and before category insertion in the database. * Sent once the category creation form has been successfully validated, and before category insertion in the database.
*/ */

View File

@@ -61,7 +61,7 @@ class Address extends BaseLoop
), ),
'current' 'current'
), ),
Argument::createBooleanTypeArgument('default'), Argument::createBooleanTypeArgument('default', false),
Argument::createIntListTypeArgument('exclude') Argument::createIntListTypeArgument('exclude')
); );
} }
@@ -96,10 +96,9 @@ class Address extends BaseLoop
$default = $this->getDefault(); $default = $this->getDefault();
if ($default === true) { if ($default === true) {
$search->filterByIsDefault(1, Criteria::EQUAL); $search->filterByIsDefault(1, Criteria::EQUAL);
} elseif ($default === false) {
$search->filterByIsDefault(1, Criteria::NOT_EQUAL);
} }
$exclude = $this->getExclude(); $exclude = $this->getExclude();
@@ -116,7 +115,7 @@ class Address extends BaseLoop
$loopResultRow = new LoopResultRow(); $loopResultRow = new LoopResultRow();
$loopResultRow $loopResultRow
->set("ID", $address->getId()) ->set("ID", $address->getId())
->set("NAME", $address->getName()) ->set("LABEL", $address->getLabel())
->set("CUSTOMER", $address->getCustomerId()) ->set("CUSTOMER", $address->getCustomerId())
->set("TITLE", $address->getTitleId()) ->set("TITLE", $address->getTitleId())
->set("COMPANY", $address->getCompany()) ->set("COMPANY", $address->getCompany())

View File

@@ -26,11 +26,11 @@ use Symfony\Component\Validator\Constraints\NotBlank;
/** /**
* Class AddressForm * Class AddressCreateForm
* @package Thelia\Form * @package Thelia\Form
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class AddressForm extends BaseForm class AddressCreateForm extends BaseForm
{ {
/** /**
@@ -60,7 +60,8 @@ class AddressForm extends BaseForm
"constraints" => array( "constraints" => array(
new NotBlank() new NotBlank()
), ),
"label" => "address name" "label" => "address name",
"required" => true
)) ))
->add("title", "text", array( ->add("title", "text", array(
"constraints" => array( "constraints" => array(

View File

@@ -0,0 +1,69 @@
<?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\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Class AddressUpdateForm
* @package Thelia\Form
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AddressUpdateForm extends AddressCreateForm {
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
parent::buildForm();
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_address_update";
}
}

View File

@@ -4,21 +4,12 @@ namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\AddressEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\Address as BaseAddress; use Thelia\Model\Base\Address as BaseAddress;
class Address extends BaseAddress { class Address extends BaseAddress {
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
protected $dispatcher;
public function setDispatcher(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}
public function getDispatcher()
{
return $this->dispatcher;
}
/** /**
* Code to be run before inserting to database * Code to be run before inserting to database
@@ -27,6 +18,7 @@ class Address extends BaseAddress {
*/ */
public function preInsert(ConnectionInterface $con = null) public function preInsert(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEADDRESS, new AddressEvent($this));
return true; return true;
} }
@@ -36,7 +28,7 @@ class Address extends BaseAddress {
*/ */
public function postInsert(ConnectionInterface $con = null) public function postInsert(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::AFTER_CREATEADDRESS, new AddressEvent($this));
} }
/** /**
@@ -46,6 +38,7 @@ class Address extends BaseAddress {
*/ */
public function preUpdate(ConnectionInterface $con = null) public function preUpdate(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEADDRESS, new AddressEvent($this));
return true; return true;
} }
@@ -55,7 +48,7 @@ class Address extends BaseAddress {
*/ */
public function postUpdate(ConnectionInterface $con = null) public function postUpdate(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEADDRESS, new AddressEvent($this));
} }
/** /**
@@ -65,6 +58,7 @@ class Address extends BaseAddress {
*/ */
public function preDelete(ConnectionInterface $con = null) public function preDelete(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEADDRESS, new AddressEvent($this));
return true; return true;
} }
@@ -74,7 +68,7 @@ class Address extends BaseAddress {
*/ */
public function postDelete(ConnectionInterface $con = null) public function postDelete(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::AFTER_DELETEADDRESS, new AddressEvent($this));
} }
} }

View File

@@ -2,7 +2,7 @@
namespace Thelia\Model; namespace Thelia\Model;
use Symfony\Component\Config\Definition\Exception\Exception; use Propel\Runtime\Exception\PropelException;
use Thelia\Model\AddressQuery; use Thelia\Model\AddressQuery;
use Thelia\Model\Base\Customer as BaseCustomer; use Thelia\Model\Base\Customer as BaseCustomer;
@@ -115,7 +115,7 @@ class Customer extends BaseCustomer implements UserInterface
$con->commit(); $con->commit();
} catch(Exception $e) { } catch(PropelException $e) {
$con->rollback(); $con->rollback();
throw $e; throw $e;
} }
@@ -225,7 +225,7 @@ class Customer extends BaseCustomer implements UserInterface
*/ */
public function preUpdate(ConnectionInterface $con = null) public function preUpdate(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::BEFORE_CHANGECUSTOMER, new CustomerEvent($this)); $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECUSTOMER, new CustomerEvent($this));
return true; return true;
} }
@@ -234,7 +234,7 @@ class Customer extends BaseCustomer implements UserInterface
*/ */
public function postUpdate(ConnectionInterface $con = null) public function postUpdate(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::AFTER_CHANGECUSTOMER, new CustomerEvent($this)); $this->dispatchEvent(TheliaEvents::AFTER_UPDATECUSTOMER, new CustomerEvent($this));
} }
/** /**

View File

@@ -1631,8 +1631,8 @@
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_ADMIN_LOGIN" class="">ADMIN_LOGIN</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_ADMIN_LOGIN" class="">ADMIN_LOGIN</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_CREATECUSTOMER" class="">BEFORE_CREATECUSTOMER</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_CREATECUSTOMER" class="">BEFORE_CREATECUSTOMER</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CREATECUSTOMER" class="">AFTER_CREATECUSTOMER</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CREATECUSTOMER" class="">AFTER_CREATECUSTOMER</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_CHANGECUSTOMER" class="">BEFORE_CHANGECUSTOMER</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_CHANGECUSTOMER" class="">BEFORE_UPDATECUSTOMER</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CHANGECUSTOMER" class="">AFTER_CHANGECUSTOMER</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CHANGECUSTOMER" class="">AFTER_UPDATECUSTOMER</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_CREATECATEGORY" class="">BEFORE_CREATECATEGORY</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_CREATECATEGORY" class="">BEFORE_CREATECATEGORY</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CREATECATEGORY" class="">AFTER_CREATECATEGORY</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CREATECATEGORY" class="">AFTER_CREATECATEGORY</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_DELETECATEGORY" class="">BEFORE_DELETECATEGORY</a><br /> <a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_DELETECATEGORY" class="">BEFORE_DELETECATEGORY</a><br />
@@ -1891,8 +1891,8 @@
<div class="span8 content class"> <div class="span8 content class">
<a id="constant_BEFORE_CHANGECUSTOMER" name="constant_BEFORE_CHANGECUSTOMER" class="anchor"></a> <a id="constant_BEFORE_CHANGECUSTOMER" name="constant_BEFORE_CHANGECUSTOMER" class="anchor"></a>
<article id="constant_BEFORE_CHANGECUSTOMER" class="constant"> <article id="constant_BEFORE_CHANGECUSTOMER" class="constant">
<h3 class="">BEFORE_CHANGECUSTOMER</h3> <h3 class="">BEFORE_UPDATECUSTOMER</h3>
<pre class="signature">BEFORE_CHANGECUSTOMER</pre> <pre class="signature">BEFORE_UPDATECUSTOMER</pre>
<p><em>Sent once the customer change form has been successfully validated, and before customer update in the database.</em></p> <p><em>Sent once the customer change form has been successfully validated, and before customer update in the database.</em></p>
@@ -1913,8 +1913,8 @@
<div class="span8 content class"> <div class="span8 content class">
<a id="constant_AFTER_CHANGECUSTOMER" name="constant_AFTER_CHANGECUSTOMER" class="anchor"></a> <a id="constant_AFTER_CHANGECUSTOMER" name="constant_AFTER_CHANGECUSTOMER" class="anchor"></a>
<article id="constant_AFTER_CHANGECUSTOMER" class="constant"> <article id="constant_AFTER_CHANGECUSTOMER" class="constant">
<h3 class="">AFTER_CHANGECUSTOMER</h3> <h3 class="">AFTER_UPDATECUSTOMER</h3>
<pre class="signature">AFTER_CHANGECUSTOMER</pre> <pre class="signature">AFTER_UPDATECUSTOMER</pre>
<p><em>Sent just after a successful update of a customer in the database.</em></p> <p><em>Sent just after a successful update of a customer in the database.</em></p>

View File

@@ -109,7 +109,7 @@ class Category extends BaseAction implements EventSubscriberInterface
$customer = CustomerQuery::create()->findPk(1); $customer = CustomerQuery::create()->findPk(1);
try { try {
$customerEvent = new CustomerEvent($customer); $customerEvent = new CustomerEvent($customer);
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent); $event->getDispatcher()->dispatch(TheliaEvents::BEFORE_UPDATECUSTOMER, $customerEvent);
$data = $form->getData(); $data = $form->getData();
@@ -127,7 +127,7 @@ class Category extends BaseAction implements EventSubscriberInterface
); );
$customerEvent->customer = $customer; $customerEvent->customer = $customer;
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECUSTOMER, $customerEvent); $event->getDispatcher()->dispatch(TheliaEvents::AFTER_UPDATECUSTOMER, $customerEvent);
// Update the logged-in user, and redirect to the success URL (exits) // Update the logged-in user, and redirect to the success URL (exits)
// We don-t send the login event, as the customer si already logged. // We don-t send the login event, as the customer si already logged.

View File

@@ -78,11 +78,11 @@ final class TheliaEvents
/** /**
* Sent once the customer change form has been successfully validated, and before customer update in the database. * Sent once the customer change form has been successfully validated, and before customer update in the database.
*/ */
const BEFORE_CHANGECUSTOMER = "action.before_changecustomer"; const BEFORE_UPDATECUSTOMER = "action.before_changecustomer";
/** /**
* Sent just after a successful update of a customer in the database. * Sent just after a successful update of a customer in the database.
*/ */
const AFTER_CHANGECUSTOMER = "action.after_changecustomer"; const AFTER_UPDATECUSTOMER = "action.after_changecustomer";
/** /**
* Sent once the category creation form has been successfully validated, and before category insertion in the database. * Sent once the category creation form has been successfully validated, and before category insertion in the database.

View File

@@ -125,7 +125,7 @@ class Customer extends BaseCustomer implements UserInterface
public function preUpdate(ConnectionInterface $con = null) public function preUpdate(ConnectionInterface $con = null)
{ {
$customerEvent = new CustomerEvent($this); $customerEvent = new CustomerEvent($this);
$this->dispatchEvent(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent); $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECUSTOMER, $customerEvent);
return true; return true;
} }
@@ -133,7 +133,7 @@ class Customer extends BaseCustomer implements UserInterface
public function postUpdate(ConnectionInterface $con = null) public function postUpdate(ConnectionInterface $con = null)
{ {
$customerEvent = new CustomerEvent($this); $customerEvent = new CustomerEvent($this);
$this->dispatchEvent(TheliaEvents::AFTER_CHANGECUSTOMER, $customerEvent); $this->dispatchEvent(TheliaEvents::AFTER_UPDATECUSTOMER, $customerEvent);
} }
protected function dispatchEvent($eventName, CustomerEvent $customerEvent) protected function dispatchEvent($eventName, CustomerEvent $customerEvent)

View File

@@ -0,0 +1,99 @@
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
{include file="includes/header.html"}
{$page_title="{intl l='My Account'}"}
{form name="thelia.address.create"}
{if $form_error}<div class="alert alert-block alert-error">{$form_error_message}</div>{/if}
{* We use {navigate to="index"} as form action to avoid mixing post and get data *}
<form action="{url path="/address/create" }" method="post" {form_enctype form=$form}>
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{viewurl view="address_list"}" />
{/form_field}
{form_hidden_fields form=$form}
{form_field form=$form field="label"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="title"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<select name="{$name}">
{loop type="title" name="title1"}
<option value="#ID">#LONG</option>
{/loop}
</select>
<br />
{/form_field}
{form_field form=$form field="firstname"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="lastname"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="address1"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="zipcode"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="city"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="country"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<select name="{$name}">
{loop type="country" name="country1"}
<option value="#ID">#TITLE</option>
{/loop}
</select>
<br />
{/form_field}
{form_field form=$form field="phone"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
<input type="submit" value="submit">
</form>
{/form}
{include file="includes/footer.html"}

View File

@@ -0,0 +1,100 @@
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
{include file="includes/header.html"}
{$page_title="{intl l='My Account'}"}
{form name="thelia.address.update"}
{if $form_error}<div class="alert alert-block alert-error">{$form_error_message}</div>{/if}
{* We use {navigate to="index"} as form action to avoid mixing post and get data *}
<form action="{url path="/address/update" }" method="post" {form_enctype form=$form}>
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{viewurl view="address_list"}" />
{/form_field}
<input type="hidden" name="address_id" value="5" />
{form_hidden_fields form=$form}
{form_field form=$form field="label"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="title"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<select name="{$name}">
{loop type="title" name="title1"}
<option value="#ID">#LONG</option>
{/loop}
</select>
<br />
{/form_field}
{form_field form=$form field="firstname"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="lastname"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="address1"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="zipcode"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="city"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
{form_field form=$form field="country"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<select name="{$name}">
{loop type="country" name="country1"}
<option value="#ID">#TITLE</option>
{/loop}
</select>
<br />
{/form_field}
{form_field form=$form field="phone"}
{if $error}{$message}{/if}
<label> <span>{intl l="{$label}"} : </span></label>
<input type="text" name="{$name}" value="{$value}" {$attr}>
<br />
{/form_field}
<input type="submit" value="submit">
</form>
{/form}
{include file="includes/footer.html"}

View File

@@ -0,0 +1,11 @@
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
{include file="includes/header.html"}
{$page_title="{intl l='My Account'}"}
<ul>
{loop type="address" name="customer_list" customer="current"}
<li>{#LABEL} - {#FIRSTNAME} {#LASTNAME} - <a href="{url path="/address/edit/{#ID}"}">edit</a></li>
{/loop}
</ul>
{include file="includes/footer.html"}

View File

@@ -7,7 +7,6 @@
The two fields below are not par of the form, they are here to defines The two fields below are not par of the form, they are here to defines
the action to process, and the view to render once the form is submited the action to process, and the view to render once the form is submited
*} *}
<input type="hidden" name="action" value="createCustomer" /> {* the action triggered by this form *}
{* {*
This field is common to all BaseForm instances (thus, this one), and defines This field is common to all BaseForm instances (thus, this one), and defines