diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 4e78afd1f..ec2e80db8 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -29,7 +29,7 @@ - + Thelia\Controller\Front\CustomerAddressController::createAction diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index d4c8b5854..c7c9f6f14 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -179,7 +179,7 @@ class BaseController extends ContainerAware */ public function redirect($url) { - Redirect::exec(URL::absoluteUrl($url)); + Redirect::exec($url); } /** diff --git a/core/lib/Thelia/Controller/Front/CustomerAddressController.php b/core/lib/Thelia/Controller/Front/CustomerAddressController.php new file mode 100644 index 000000000..4bf5faae8 --- /dev/null +++ b/core/lib/Thelia/Controller/Front/CustomerAddressController.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +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 + */ +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 + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Front/CustomerController.php b/core/lib/Thelia/Controller/Front/CustomerController.php index bcb4b820d..88e15396e 100755 --- a/core/lib/Thelia/Controller/Front/CustomerController.php +++ b/core/lib/Thelia/Controller/Front/CustomerController.php @@ -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) { diff --git a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php new file mode 100644 index 000000000..89a26d81a --- /dev/null +++ b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php @@ -0,0 +1,234 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; +use Thelia\Model\Customer; + + +/** + * Class AddressCreateOrUpdateEvent + * @package Thelia\Core\Event + * @author Manuel Raynaud + */ +class AddressCreateOrUpdateEvent { + /** + * @var string address label + */ + protected $label; + + /** + * @var int title id + */ + protected $title; + + /** + * @var string|null company name + */ + protected $company; + + /** + * @var string first name + */ + protected $firstname; + + /** + * @var string last name + */ + protected $lastname; + + /** + * @var string address + */ + protected $address1; + + /** + * @var string address line 2 + */ + protected $address2; + + /** + * @var string address line 3 + */ + protected $address3; + + /** + * @var string zipcode + */ + protected $zipcode; + + /** + * @var string city + */ + protected $city; + + /** + * @var int country id + */ + protected $country; + + /** + * @var string cell phone + */ + protected $cellphone; + + /** + * @var string phone + */ + protected $phone; + + /** + * @var \Thelia\Model\Customer + */ + protected $customer; + + function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company, Customer $customer) + { + $this->address1 = $address1; + $this->address2 = $address2; + $this->address3 = $address3; + $this->cellphone = $cellphone; + $this->city = $city; + $this->company = $company; + $this->country = $country; + $this->firstname = $firstname; + $this->label = $label; + $this->lastname = $lastname; + $this->phone = $phone; + $this->title = $title; + $this->zipcode = $zipcode; + $this->customer = $customer; + } + + /** + * @return string + */ + public function getAddress1() + { + return $this->address1; + } + + /** + * @return string + */ + public function getAddress2() + { + return $this->address2; + } + + /** + * @return string + */ + public function getAddress3() + { + return $this->address3; + } + + /** + * @return string + */ + public function getCellphone() + { + return $this->cellphone; + } + + /** + * @return string + */ + public function getCity() + { + return $this->city; + } + + /** + * @return null|string + */ + public function getCompany() + { + return $this->company; + } + + /** + * @return int + */ + public function getCountry() + { + return $this->country; + } + + /** + * @return string + */ + public function getFirstname() + { + return $this->firstname; + } + + /** + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @return string + */ + public function getLastname() + { + return $this->lastname; + } + + /** + * @return string + */ + public function getPhone() + { + return $this->phone; + } + + /** + * @return int + */ + public function getTitle() + { + return $this->title; + } + + /** + * @return string + */ + public function getZipcode() + { + return $this->zipcode; + } + + /** + * @return \Thelia\Model\Customer + */ + public function getCustomer() + { + return $this->customer; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 8bca60bb4..e32be723f 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -94,6 +94,10 @@ final class TheliaEvents */ const AFTER_CHANGECUSTOMER = "action.after_changecustomer"; + /** + * sent for address creation + */ + const ADDRESS_CREATE = "action.addressCreate"; /** * Sent once the category creation form has been successfully validated, and before category insertion in the database. @@ -223,4 +227,6 @@ final class TheliaEvents const BEFORE_DELETECURRENCY = "action.before_deleteCurrency"; const AFTER_DELETECURRENCY = "action.after_deleteCurrency"; + + } diff --git a/core/lib/Thelia/Core/Security/SecurityContext.php b/core/lib/Thelia/Core/Security/SecurityContext.php index 6ddb47f00..3f60db08f 100755 --- a/core/lib/Thelia/Core/Security/SecurityContext.php +++ b/core/lib/Thelia/Core/Security/SecurityContext.php @@ -67,7 +67,7 @@ class SecurityContext */ public function hasAdminUser() { - return $this->getSession()->getAdminUser() != null; + return $this->getSession()->getAdminUser() !== null; } /** @@ -87,7 +87,7 @@ class SecurityContext */ public function hasCustomerUser() { - return $this->getSession()->getCustomerUser() != null; + return $this->getSession()->getCustomerUser() !== null; } /** diff --git a/core/lib/Thelia/Form/AddressForm.php b/core/lib/Thelia/Form/AddressForm.php new file mode 100644 index 000000000..b98577927 --- /dev/null +++ b/core/lib/Thelia/Form/AddressForm.php @@ -0,0 +1,132 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form; +use Symfony\Component\Validator\Constraints\NotBlank; + + +/** + * Class AddressForm + * @package Thelia\Form + * @author Manuel Raynaud + */ +class AddressForm extends BaseForm +{ + + /** + * + * 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() + { + $this->formBuilder + ->add("label", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "address name" + )) + ->add("title", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "title" + )) + ->add("firstname", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "first name" + )) + ->add("lastname", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "last name" + )) + ->add("address1", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "address" + )) + ->add("address2", "text", array( + "label" => "address (line 2)" + )) + ->add("address3", "text", array( + "label" => "address (line 3)" + )) + ->add("zipcode", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "zipcode" + )) + ->add("city", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "city" + )) + ->add("country", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "country" + )) + ->add("phone", "text", array( + "label" => "phone" + )) + ->add("cellphone", "text", array( + "label" => "cellphone" + )) + ->add("company", "text", array( + "label" => "company" + )) + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return "thelia_address_creation"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index 1edd6f4ff..c8efaa9e1 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -6,4 +6,8 @@ use Thelia\Model\Base\Address as BaseAddress; class Address extends BaseAddress { + public function createOrUpdate() + { + + } }