From 0c1ed8e702993a9cffd040b0e9042e41d6bc79df Mon Sep 17 00:00:00 2001 From: touffies Date: Tue, 22 Oct 2013 09:44:45 +0200 Subject: [PATCH] Cleanup : - I made the form id different between the front and the back office - I renamed a few files to use the same convention (create / update) --- core/lib/Thelia/Config/Resources/config.xml | 25 +- core/lib/Thelia/Form/AddressCreateForm.php | 219 +++++++++--------- core/lib/Thelia/Form/AddressUpdateForm.php | 129 +---------- ...merCreation.php => CustomerCreateForm.php} | 142 ++---------- core/lib/Thelia/Form/CustomerLogin.php | 43 +++- core/lib/Thelia/Form/CustomerModification.php | 164 ------------- .../Form/CustomerPasswordUpdateForm.php | 99 ++++++++ .../Thelia/Form/CustomerProfilUpdateForm.php | 71 ++++++ core/lib/Thelia/Form/CustomerUpdateForm.php | 155 ++++++++++--- .../default/ajax/address-update-modal.html | 2 +- templates/admin/default/customer-edit.html | 4 +- templates/admin/default/customers.html | 2 +- templates/default/account-update.html | 2 +- templates/default/address-update.html | 2 +- templates/default/address.html | 2 +- templates/default/layout.tpl | 2 +- templates/default/login.html | 4 +- templates/default/password.html | 2 +- templates/default/register.html | 2 +- 19 files changed, 489 insertions(+), 582 deletions(-) rename core/lib/Thelia/Form/{CustomerCreation.php => CustomerCreateForm.php} (50%) delete mode 100755 core/lib/Thelia/Form/CustomerModification.php create mode 100755 core/lib/Thelia/Form/CustomerPasswordUpdateForm.php create mode 100755 core/lib/Thelia/Form/CustomerProfilUpdateForm.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index e343cc4ce..87da0b1e9 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -52,18 +52,27 @@ + +
+ + + + + + + + + + - - - - - - - - + + + + + diff --git a/core/lib/Thelia/Form/AddressCreateForm.php b/core/lib/Thelia/Form/AddressCreateForm.php index 0774f253d..902663f43 100644 --- a/core/lib/Thelia/Form/AddressCreateForm.php +++ b/core/lib/Thelia/Form/AddressCreateForm.php @@ -22,6 +22,8 @@ /*************************************************************************************/ namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Core\Translation\Translator; @@ -57,115 +59,122 @@ class AddressCreateForm extends BaseForm { $this->formBuilder ->add("label", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Address label"), - "label_attr" => array( - "for" => "label_create" - ), - "required" => true - )) + "constraints" => array( + new NotBlank() + ), + "label" => Translator::getInstance()->trans("Address label"), + "label_attr" => array( + "for" => "address_label" + ) + )) ->add("title", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Title"), - "label_attr" => array( - "for" => "title_create" - ) - )) + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Title"), + "label_attr" => array( + "for" => "title" + ) + )) ->add("firstname", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Firstname"), - "label_attr" => array( - "for" => "firstname_create" - ) - )) + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("First Name"), + "label_attr" => array( + "for" => "firstname" + ) + )) ->add("lastname", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Lastname"), - "label_attr" => array( - "for" => "lastname_create" - ) - )) - ->add("address1", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Street Address"), - "label_attr" => array( - "for" => "address1_create" - ) - )) - ->add("address2", "text", array( - "label" => Translator::getInstance()->trans("Additional address"), - "label_attr" => array( - "for" => "address2_create" - ) - )) - ->add("address3", "text", array( - "label" => Translator::getInstance()->trans("Additional address"), - "label_attr" => array( - "for" => "address3_create" - ) - )) - ->add("zipcode", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Zip code"), - "label_attr" => array( - "for" => "zipcode_create" - ) - )) - ->add("city", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("City"), - "label_attr" => array( - "for" => "city_create" - ) - )) - ->add("country", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Country"), - "label_attr" => array( - "for" => "country_create" - ) - )) - ->add("phone", "text", array( - "label" => Translator::getInstance()->trans("Phone"), - "label_attr" => array( - "for" => "phone_create" - ) - )) - ->add("cellphone", "text", array( - "label" => Translator::getInstance()->trans("Cellphone"), - "label_attr" => array( - "for" => "cellphone_create" - ) - )) + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Last Name"), + "label_attr" => array( + "for" => "lastname" + ) + )) ->add("company", "text", array( - "label" => Translator::getInstance()->trans("Company"), - "label_attr" => array( - "for" => "company_create" - ) - )) - ->add("is_default", "integer", array( - "label" => Translator::getInstance()->trans("Make this address has my primary address"), - "label_attr" => array( - "for" => "default_address" - ) - )) - ; + "label" => Translator::getInstance()->trans("Company Name"), + "label_attr" => array( + "for" => "company" + ), + "required" => false + )) + ->add("address1", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Street Address"), + "label_attr" => array( + "for" => "address1" + ) + )) + ->add("address2", "text", array( + "label" => Translator::getInstance()->trans("Address Line 2"), + "label_attr" => array( + "for" => "address2" + ), + "required" => false + )) + ->add("address3", "text", array( + "label" => Translator::getInstance()->trans("Address Line 3"), + "label_attr" => array( + "for" => "address3" + ), + "required" => false + )) + ->add("city", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("City"), + "label_attr" => array( + "for" => "city" + ) + )) + ->add("zipcode", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Zip code"), + "label_attr" => array( + "for" => "zipcode" + ) + )) + ->add("country", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Country"), + "label_attr" => array( + "for" => "country" + ) + )) + // Phone + ->add("phone", "text", array( + "label" => Translator::getInstance()->trans("Phone"), + "label_attr" => array( + "for" => "phone" + ), + "required" => false + )) + ->add("cellphone", "text", array( + "label" => Translator::getInstance()->trans("Cellphone"), + "label_attr" => array( + "for" => "cellphone" + ), + "required" => false + )) + // Default address + ->add("is_default", "checkbox", array( + "label" => Translator::getInstance()->trans("Make this address has my primary address"), + "label_attr" => array( + "for" => "default_address" + ), + "required" => false + )) + ; } /** diff --git a/core/lib/Thelia/Form/AddressUpdateForm.php b/core/lib/Thelia/Form/AddressUpdateForm.php index 055b233c9..258fbc357 100644 --- a/core/lib/Thelia/Form/AddressUpdateForm.php +++ b/core/lib/Thelia/Form/AddressUpdateForm.php @@ -22,8 +22,6 @@ /*************************************************************************************/ namespace Thelia\Form; -use Symfony\Component\Validator\Constraints\NotBlank; -use Thelia\Core\Translation\Translator; /** * Class AddressUpdateForm @@ -32,136 +30,11 @@ use Thelia\Core\Translation\Translator; */ 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(); - $this->formBuilder - ->add("label", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Address label *"), - "label_attr" => array( - "for" => "label_update" - ), - "required" => true - )) - ->add("title", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Title"), - "label_attr" => array( - "for" => "title_update" - ) - )) - ->add("firstname", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Firstname"), - "label_attr" => array( - "for" => "firstname_update" - ) - )) - ->add("lastname", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Lastname"), - "label_attr" => array( - "for" => "lastname_update" - ) - )) - ->add("address1", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Street Address"), - "label_attr" => array( - "for" => "address1_update" - ) - )) - ->add("address2", "text", array( - "label" => Translator::getInstance()->trans("Additional address"), - "label_attr" => array( - "for" => "address2_update" - ) - )) - ->add("address3", "text", array( - "label" => Translator::getInstance()->trans("Additional address"), - "label_attr" => array( - "for" => "address3_update" - ) - )) - ->add("zipcode", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Zip code"), - "label_attr" => array( - "for" => "zipcode_update" - ) - )) - ->add("city", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("City"), - "label_attr" => array( - "for" => "city_update" - ) - )) - ->add("country", "text", array( - "constraints" => array( - new NotBlank() - ), - "label" => Translator::getInstance()->trans("Country"), - "label_attr" => array( - "for" => "country_update" - ) - )) - ->add("phone", "text", array( - "label" => Translator::getInstance()->trans("Phone"), - "label_attr" => array( - "for" => "phone_update" - ) - )) - ->add("cellphone", "text", array( - "label" => Translator::getInstance()->trans("Cellphone"), - "label_attr" => array( - "for" => "cellphone_update" - ) - )) - ->add("company", "text", array( - "label" => Translator::getInstance()->trans("Compagny"), - "label_attr" => array( - "for" => "company_update" - ) - )) - ; - } /** diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreateForm.php similarity index 50% rename from core/lib/Thelia/Form/CustomerCreation.php rename to core/lib/Thelia/Form/CustomerCreateForm.php index d728a515d..2860b3b0c 100755 --- a/core/lib/Thelia/Form/CustomerCreation.php +++ b/core/lib/Thelia/Form/CustomerCreateForm.php @@ -23,51 +23,32 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Model\ConfigQuery; use Thelia\Model\CustomerQuery; use Thelia\Core\Translation\Translator; /** - * Class CustomerCreation + * Class CustomerCreateForm * @package Thelia\Form * @author Manuel Raynaud */ -class CustomerCreation extends BaseForm +class CustomerCreateForm extends AddressCreateForm { protected function buildForm() { + parent::buildForm(); + $this->formBuilder + // Remove From Address create form + ->remove("label") + ->remove("is_default") + + // Add ->add("auto_login", "integer") - // Personal Informations - ->add("title", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Title"), - "label_attr" => array( - "for" => "title" - ) - )) - ->add("firstname", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("First Name"), - "label_attr" => array( - "for" => "firstname" - ) - )) - ->add("lastname", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Last Name"), - "label_attr" => array( - "for" => "lastname" - ) - )) + // Add Email address ->add("email", "email", array( "constraints" => array( new Constraints\NotBlank(), @@ -84,90 +65,7 @@ class CustomerCreation extends BaseForm "for" => "email" ) )) -/* ->add("email_confirm", "email", array( - "constraints" => array( - new Constraints\Callback(array( - "methods" => array( - array($this, - "verifyEmailField") - ) - )) - ), - "label" => "email confirmation" - ))*/ - ->add("phone", "text", array( - "label" => Translator::getInstance()->trans("Phone"), - "label_attr" => array( - "for" => "phone" - ), - "required" => false - )) - ->add("cellphone", "text", array( - "label" => Translator::getInstance()->trans("Cellphone"), - "label_attr" => array( - "for" => "cellphone" - ), - "required" => false - )) - // Delivery Informations - ->add("company", "text", array( - "label" => Translator::getInstance()->trans("Company Name"), - "label_attr" => array( - "for" => "company" - ), - "required" => false - )) - ->add("address1", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Street Address"), - "label_attr" => array( - "for" => "address1" - ) - )) - ->add("address2", "text", array( - "label" => Translator::getInstance()->trans("Address Line 2"), - "label_attr" => array( - "for" => "address2" - ), - "required" => false - )) - ->add("address3", "text", array( - "label" => Translator::getInstance()->trans("Address Line 3"), - "label_attr" => array( - "for" => "address3" - ), - "required" => false - )) - ->add("city", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("City"), - "label_attr" => array( - "for" => "city" - ) - )) - ->add("zipcode", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Zip code"), - "label_attr" => array( - "for" => "zipcode" - ) - )) - ->add("country", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Country"), - "label_attr" => array( - "for" => "country" - ) - )) - // Login Information + // Add Login Information ->add("password", "password", array( "constraints" => array( new Constraints\NotBlank(), @@ -191,6 +89,7 @@ class CustomerCreation extends BaseForm "for" => "password_confirmation" ) )) + // Add terms & conditions ->add("agreed", "checkbox", array( "constraints" => array( new Constraints\True(array("message" => "Please accept the Terms and conditions in order to register.")) @@ -206,16 +105,7 @@ class CustomerCreation extends BaseForm $data = $context->getRoot()->getData(); if ($data["password"] != $data["password_confirm"]) { - $context->addViolation("password confirmation is not the same as password field"); - } - } - - public function verifyEmailField($value, ExecutionContextInterface $context) - { - $data = $context->getRoot()->getData(); - - if ($data["email"] != $data["email_confirm"]) { - $context->addViolation("email confirmation is not the same as email field"); + $context->addViolation("password confirmation is not the same as password field."); } } @@ -223,12 +113,12 @@ class CustomerCreation extends BaseForm { $customer = CustomerQuery::create()->findOneByEmail($value); if ($customer) { - $context->addViolation("This email already exists"); + $context->addViolation("This email already exists."); } } public function getName() { - return "thelia_customer_creation"; + return "thelia_customer_create"; } } diff --git a/core/lib/Thelia/Form/CustomerLogin.php b/core/lib/Thelia/Form/CustomerLogin.php index 78f4c3d33..587e87294 100755 --- a/core/lib/Thelia/Form/CustomerLogin.php +++ b/core/lib/Thelia/Form/CustomerLogin.php @@ -22,6 +22,8 @@ /*************************************************************************************/ namespace Thelia\Form; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\Email; @@ -56,13 +58,13 @@ class CustomerLogin extends BaseForm ) )) ->add("account", "choice", array( - "constraints" => array( + /*"constraints" => array( new Constraints\Callback(array( "methods" => array( array($this, "verifyAccount") ) )) - ), + ),*/ "choices" => array( 0 => Translator::getInstance()->trans("No, I am a new customer."), 1 => Translator::getInstance()->trans("Yes, I have a password :") @@ -70,12 +72,21 @@ class CustomerLogin extends BaseForm "label_attr" => array( "for" => "account" ), - "data" => 0 + "data" => 0, + 'validation_groups' => function(FormInterface $form) { + $account = $form->getData(); + if ($account === 1) + return 'existing_customer'; + else + return 'Default'; + } )) ->add("password", "password", array( - /*"constraints" => array( - new Constraints\NotBlank() - ),*/ + "constraints" => array( + new Constraints\NotBlank(array( + 'groups' => array('existing_customer'), + )) + ), "label" => Translator::getInstance()->trans("Please enter your password"), "label_attr" => array( "for" => "password" @@ -120,6 +131,26 @@ class CustomerLogin extends BaseForm } } + + /** + * {@inheritdoc} + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + //'cascade_validation' => true, + // 'csrf_protection' => true, + //'csrf_field_name' => '_token', + 'validation_groups' => function(FormInterface $form) { + $data = $form->getData(); + if ($data->getAccount() == 1) + return array('Default', 'existing_customer'); + else + return 'Default'; + } + )); + } + public function getName() { return "thelia_customer_login"; diff --git a/core/lib/Thelia/Form/CustomerModification.php b/core/lib/Thelia/Form/CustomerModification.php deleted file mode 100755 index 4f12c6013..000000000 --- a/core/lib/Thelia/Form/CustomerModification.php +++ /dev/null @@ -1,164 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Thelia\Form; - -use Symfony\Component\Validator\Constraints; -use Thelia\Core\Translation\Translator; - -/** - * Class CustomerModification - * @package Thelia\Form - * @author Manuel Raynaud - */ -class CustomerModification 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->form attribute : - * - * $this->form->add("name", "text") - * ->add("email", "email", array( - * "attr" => array( - * "class" => "field" - * ), - * "label" => "email", - * "constraints" => array( - * new NotBlank() - * ) - * ) - * ) - * ->add('age', 'integer'); - * - * @return null - */ - protected function buildForm() - { - - $this->formBuilder - ->add('update_logged_in_user', 'integer') // In a front office context, update the in-memory logged-in user data - ->add("company", "text", array( - "label" => Translator::getInstance()->trans("Company"), - "label_attr" => array( - "for" => "company" - ) - )) - ->add("firstname", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("First Name"), - "label_attr" => array( - "for" => "firstname" - ) - )) - ->add("lastname", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Last Name"), - "label_attr" => array( - "for" => "lastname" - ) - )) - ->add("address1", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label_attr" => array( - "for" => "address" - ), - "label" => Translator::getInstance()->trans("Street Address") - )) - ->add("address2", "text", array( - "label" => Translator::getInstance()->trans("Address Line 2"), - "label_attr" => array( - "for" => "address2" - ) - )) - ->add("address3", "text", array( - "label" => Translator::getInstance()->trans("Address Line 3"), - "label_attr" => array( - "for" => "address3" - ) - )) - ->add("phone", "text", array( - "label" => Translator::getInstance()->trans("Phone"), - "label_attr" => array( - "for" => "phone" - ) - )) - ->add("cellphone", "text", array( - "label" => Translator::getInstance()->trans("Cellphone"), - "label_attr" => array( - "for" => "cellphone" - ) - )) - ->add("zipcode", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Zip code"), - "label_attr" => array( - "for" => "zipcode" - ) - )) - ->add("city", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("City"), - "label_attr" => array( - "for" => "city" - ) - )) - ->add("country", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Country"), - "label_attr" => array( - "for" => "country" - ) - )) - ->add("title", "text", array( - "constraints" => array( - new Constraints\NotBlank() - ), - "label" => Translator::getInstance()->trans("Title"), - "label_attr" => array( - "for" => "title" - ) - )) - ; - } - - /** - * @return string the name of you form. This name must be unique - */ - public function getName() - { - return "thelia_customer_modification"; - } -} diff --git a/core/lib/Thelia/Form/CustomerPasswordUpdateForm.php b/core/lib/Thelia/Form/CustomerPasswordUpdateForm.php new file mode 100755 index 000000000..b8310d697 --- /dev/null +++ b/core/lib/Thelia/Form/CustomerPasswordUpdateForm.php @@ -0,0 +1,99 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\ExecutionContextInterface; +use Thelia\Model\ConfigQuery; +use Thelia\Model\CustomerQuery; +use Thelia\Core\Translation\Translator; + +/** + * Class CustomerPasswordUpdateForm + * @package Thelia\Form + * @author Christophe Laffont + */ +class CustomerPasswordUpdateForm extends BaseForm +{ + + protected function buildForm() + { + $this->formBuilder + + // Login Information + ->add("password_old", "password", array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback(array("methods" => array( + array($this, "verifyCurrentPasswordField") + ))) + ), + "label" => Translator::getInstance()->trans("Current Password"), + "label_attr" => array( + "for" => "password_old" + ) + )) + ->add("password", "password", array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))) + ), + "label" => Translator::getInstance()->trans("New Password"), + "label_attr" => array( + "for" => "password" + ) + )) + ->add("password_confirm", "password", array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))), + new Constraints\Callback(array("methods" => array( + array($this, "verifyPasswordField") + ))) + ), + "label" => "Password confirmation", + "label_attr" => array( + "for" => "password_confirmation" + ) + )); + } + + public function verifyCurrentPasswordField($value, ExecutionContextInterface $context) + { + + } + + public function verifyPasswordField($value, ExecutionContextInterface $context) + { + $data = $context->getRoot()->getData(); + + if ($data["password"] != $data["password_confirm"]) { + $context->addViolation("password confirmation is not the same as password field."); + } + } + + public function getName() + { + return "thelia_customer_password_update"; + } +} diff --git a/core/lib/Thelia/Form/CustomerProfilUpdateForm.php b/core/lib/Thelia/Form/CustomerProfilUpdateForm.php new file mode 100755 index 000000000..74e888e5b --- /dev/null +++ b/core/lib/Thelia/Form/CustomerProfilUpdateForm.php @@ -0,0 +1,71 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Thelia\Model\ConfigQuery; +use Thelia\Core\Translation\Translator; + +/** + * Class CustomerProfilUpdateForm + * @package Thelia\Form + * @author Christophe Laffont + */ +class CustomerProfilUpdateForm extends CustomerCreateForm +{ + + protected function buildForm() + { + parent::buildForm(); + + $this->formBuilder + ->remove("auto_login") + // Remove From Personal Informations + ->remove("phone") + ->remove("cellphone") + // Remove Delivery Informations + ->remove("company") + ->remove("address1") + ->remove("address2") + ->remove("address3") + ->remove("city") + ->remove("zipcode") + ->remove("country") + // Remove Terms & conditions + ->remove("agreed") + + // Add Newsletter + ->add("newsletter", "checkbox", array( + "label" => "I would like to receive the newsletter our the latest news.", + "label_attr" => array( + "for" => "newsletter" + ), + "required" => false + )); + } + + public function getName() + { + return "thelia_customer_profil_update"; + } +} diff --git a/core/lib/Thelia/Form/CustomerUpdateForm.php b/core/lib/Thelia/Form/CustomerUpdateForm.php index b02c7e31e..06e094ec7 100755 --- a/core/lib/Thelia/Form/CustomerUpdateForm.php +++ b/core/lib/Thelia/Form/CustomerUpdateForm.php @@ -1,10 +1,10 @@ . */ +/* along with this program. If not, see . */ /* */ /*************************************************************************************/ + namespace Thelia\Form; use Symfony\Component\Validator\Constraints; -use Thelia\Model\ConfigQuery; use Thelia\Core\Translation\Translator; /** * Class CustomerUpdateForm * @package Thelia\Form - * @author Christophe Laffont + * @author Manuel Raynaud */ -class CustomerUpdateForm extends CustomerCreation +class CustomerUpdateForm 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->form attribute : + * + * $this->form->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ protected function buildForm() { - parent::buildForm(); - $this->formBuilder - ->remove("auto_login") - // Remove From Personal Informations - ->remove("phone") - ->remove("cellphone") - // Remove Delivery Informations - ->remove("company") - ->remove("address1") - ->remove("address2") - ->remove("address3") - ->remove("city") - ->remove("zipcode") - ->remove("country") - // Remove Login Information - ->remove("password") - ->remove("password_confirm") - // Remove Terms & conditions - ->remove("agreed") - - // Add Newsletter - ->add("newsletter", "checkbox", array( - "label" => "I would like to receive the newsletter our the latest news.", + ->add('update_logged_in_user', 'integer') // In a front office context, update the in-memory logged-in user data + ->add("company", "text", array( + "label" => Translator::getInstance()->trans("Company"), "label_attr" => array( - "for" => "newsletter" + "for" => "company" + ) + )) + ->add("firstname", "text", array( + "constraints" => array( + new Constraints\NotBlank() ), - "required" => false - )); + "label" => Translator::getInstance()->trans("First Name"), + "label_attr" => array( + "for" => "firstname" + ) + )) + ->add("lastname", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Last Name"), + "label_attr" => array( + "for" => "lastname" + ) + )) + ->add("address1", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label_attr" => array( + "for" => "address" + ), + "label" => Translator::getInstance()->trans("Street Address") + )) + ->add("address2", "text", array( + "label" => Translator::getInstance()->trans("Address Line 2"), + "label_attr" => array( + "for" => "address2" + ) + )) + ->add("address3", "text", array( + "label" => Translator::getInstance()->trans("Address Line 3"), + "label_attr" => array( + "for" => "address3" + ) + )) + ->add("phone", "text", array( + "label" => Translator::getInstance()->trans("Phone"), + "label_attr" => array( + "for" => "phone" + ) + )) + ->add("cellphone", "text", array( + "label" => Translator::getInstance()->trans("Cellphone"), + "label_attr" => array( + "for" => "cellphone" + ) + )) + ->add("zipcode", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Zip code"), + "label_attr" => array( + "for" => "zipcode" + ) + )) + ->add("city", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("City"), + "label_attr" => array( + "for" => "city" + ) + )) + ->add("country", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Country"), + "label_attr" => array( + "for" => "country" + ) + )) + ->add("title", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Title"), + "label_attr" => array( + "for" => "title" + ) + )) + ; } + /** + * @return string the name of you form. This name must be unique + */ public function getName() { return "thelia_customer_update"; diff --git a/templates/admin/default/ajax/address-update-modal.html b/templates/admin/default/ajax/address-update-modal.html index 39bafccea..687c51b57 100644 --- a/templates/admin/default/ajax/address-update-modal.html +++ b/templates/admin/default/ajax/address-update-modal.html @@ -1,6 +1,6 @@ {* Update an Address *} -{form name="thelia.address.update"} +{form name="thelia.admin.address.update"} {* Capture the dialog body, to pass it to the generic dialog *} {capture "edit_address_dialog"} diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index 69e1815f3..64126e053 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -28,7 +28,7 @@
- {form name="thelia.customer.modification"} + {form name="thelia.admin.customer.modification"}
@@ -221,7 +221,7 @@
{* Add an Address *} - {form name="thelia.address.create"} + {form name="thelia.admin.address.create"} {* Capture the dialog body, to pass it to the generic dialog *} {capture "address_creation_dialog"} diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index cfa332ae4..c5d5d2e60 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -161,7 +161,7 @@ {* Adding a new Category *} - {form name="thelia.customer.creation"} + {form name="thelia.admin.customer.create"} {* Capture the dialog body, to pass it to the generic dialog *} {capture "customer_creation_dialog"} diff --git a/templates/default/account-update.html b/templates/default/account-update.html index d14db6681..7488e9b31 100644 --- a/templates/default/account-update.html +++ b/templates/default/account-update.html @@ -19,7 +19,7 @@

{intl l="Update Profil"}

- {form name="thelia.customer.update"} + {form name="thelia.front.customer.profil.update"} {assign var="isPost" value="{$smarty.post|count}"} {form_field form=$form field='success_url'} diff --git a/templates/default/address-update.html b/templates/default/address-update.html index cd64ade1d..965cdc1be 100644 --- a/templates/default/address-update.html +++ b/templates/default/address-update.html @@ -21,7 +21,7 @@

{intl l="Create New Address"}

- {form name="thelia.address.update"} + {form name="thelia.front.address.update"} {loop name="customer.update" type="address" customer="current" id="{$address_id}"} {form_field form=$form field='success_url'} diff --git a/templates/default/address.html b/templates/default/address.html index 6b0245956..8b7423c0e 100644 --- a/templates/default/address.html +++ b/templates/default/address.html @@ -21,7 +21,7 @@

{intl l="Create New Address"}

- {form name="thelia.address.create"} + {form name="thelia.front.address.create"} {form_field form=$form field='success_url'} {* the url the user is redirected to on login success *} diff --git a/templates/default/layout.tpl b/templates/default/layout.tpl index 647b3267a..319e1342c 100644 --- a/templates/default/layout.tpl +++ b/templates/default/layout.tpl @@ -76,7 +76,7 @@ URL: http://www.thelia.net