diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 6feb39185..60150b3fa 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -43,7 +43,7 @@
- Thelia\Controller\Admin\CustomerController::viewAction
+ Thelia\Controller\Admin\CustomerController::updateAction
\d+
diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php
index ddf4681b9..ab897d24b 100644
--- a/core/lib/Thelia/Controller/Admin/CustomerController.php
+++ b/core/lib/Thelia/Controller/Admin/CustomerController.php
@@ -22,6 +22,13 @@
/*************************************************************************************/
namespace Thelia\Controller\Admin;
+use Propel\Runtime\Exception\PropelException;
+use Symfony\Component\Form\Form;
+use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
+use Thelia\Core\Event\TheliaEvents;
+use Thelia\Form\CustomerModification;
+use Thelia\Form\Exception\FormValidationException;
+use Thelia\Model\CustomerQuery;
/**
* Class CustomerController
@@ -38,9 +45,96 @@ class CustomerController extends BaseAdminController
public function viewAction($customer_id)
{
+ if (null !== $response = $this->checkAuth("admin.customers.view")) return $response;
return $this->render("customer-edit", array(
"customer_id" => $customer_id
));
}
+
+ public function updateAction($customer_id)
+ {
+ if (null !== $response = $this->checkAuth("admin.customers.update")) return $response;
+
+ $message = false;
+
+ $customerModification = new CustomerModification($this->getRequest());
+
+ try {
+ $customer = CustomerQuery::create()->findPk($customer_id);
+
+ if(null === $customer) {
+ throw new \InvalidArgumentException(sprintf("%d customer id does not exists", $customer_id));
+ }
+
+ $form = $this->validateForm($customerModification);
+
+ $event = $this->createEventInstance($form->getData());
+ $event->setCustomer($customer);
+
+ $this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $event);
+
+ $customerUpdated = $event->getCustomer();
+
+ $this->adminLogAppend(sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId()));
+
+ if($this->getRequest()->get("save_mode") == "close") {
+ $this->redirectToRoute("admin.customers");
+ } else {
+ $this->redirectSuccess($customerModification);
+ }
+
+ } catch (FormValidationException $e) {
+ $message = sprintf("Please check your input: %s", $e->getMessage());
+ } catch (PropelException $e) {
+ $message = $e->getMessage();
+ } catch (\Exception $e) {
+ $message = sprintf("Sorry, an error occured: %s", $e->getMessage()." ".$e->getFile());
+ }
+
+ if ($message !== false) {
+ \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer login process : %s.", $message));
+
+ $customerModification->setErrorMessage($message);
+
+ $this->getParserContext()
+ ->addForm($customerModification)
+ ->setGeneralError($message)
+ ;
+ }
+
+ return $this->render("customer-edit", array(
+ "customer_id" => $customer_id
+ ));
+ }
+
+ /**
+ * @param $data
+ * @return CustomerCreateOrUpdateEvent
+ */
+ private function createEventInstance($data)
+ {
+ $customerCreateEvent = new CustomerCreateOrUpdateEvent(
+ $data["title"],
+ $data["firstname"],
+ $data["lastname"],
+ $data["address1"],
+ $data["address2"],
+ $data["address3"],
+ $data["phone"],
+ $data["cellphone"],
+ $data["zipcode"],
+ $data["city"],
+ $data["country"],
+ isset($data["email"])?$data["email"]:null,
+ isset($data["password"]) ? $data["password"]:null,
+ $this->getRequest()->getSession()->getLang()->getId(),
+ isset($data["reseller"])?$data["reseller"]:null,
+ isset($data["sponsor"])?$data["sponsor"]:null,
+ isset($data["discount"])?$data["discount"]:null,
+ isset($data["company"])?$data["company"]:null
+ );
+
+ return $customerCreateEvent;
+ }
}
\ 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 56ac47f67..3b8c2ccff 100755
--- a/core/lib/Thelia/Controller/Front/CustomerController.php
+++ b/core/lib/Thelia/Controller/Front/CustomerController.php
@@ -22,7 +22,6 @@
/*************************************************************************************/
namespace Thelia\Controller\Front;
-use Symfony\Component\Form\Form;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\CustomerLoginEvent;
use Thelia\Core\Event\LostPasswordEvent;
@@ -98,7 +97,7 @@ class CustomerController extends BaseFrontController
try {
$form = $this->validateForm($customerCreation, "post");
- $customerCreateEvent = $this->createEventInstance($form);
+ $customerCreateEvent = $this->createEventInstance($form->getData());
$this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
@@ -147,7 +146,7 @@ class CustomerController extends BaseFrontController
$form = $this->validateForm($customerModification, "post");
- $customerChangeEvent = $this->createEventInstance($form);
+ $customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
@@ -260,27 +259,27 @@ class CustomerController extends BaseFrontController
* @param $data
* @return CustomerCreateOrUpdateEvent
*/
- private function createEventInstance(Form $form)
+ private function createEventInstance($data)
{
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
- $form->get("title")->getData(),
- $form->get("firstname")->getData(),
- $form->get("lastname")->getData(),
- $form->get("address1")->getData(),
- $form->get("address2")->getData(),
- $form->get("address3")->getData(),
- $form->get("phone")->getData(),
- $form->get("cellphone")->getData(),
- $form->get("zipcode")->getData(),
- $form->get("city")->getData(),
- $form->get("country")->getData(),
- $form->get("email")->getData(),
- $form->get("password")->getData(),
+ $data["title"],
+ $data["firstname"],
+ $data["lastname"],
+ $data["address1"],
+ $data["address2"],
+ $data["address3"],
+ $data["phone"],
+ $data["cellphone"],
+ $data["zipcode"],
+ $data["city"],
+ $data["country"],
+ isset($data["email"])?$data["email"]:null,
+ isset($data["password"]) ? $data["password"]:null,
$this->getRequest()->getSession()->getLang()->getId(),
- $form->get("reseller")->getData(),
- $form->get("sponsor")->getData(),
- $form->get("discount")->getData(),
- $form->get("company")->getData()
+ isset($data["reseller"])?$data["reseller"]:null,
+ isset($data["sponsor"])?$data["sponsor"]:null,
+ isset($data["discount"])?$data["discount"]:null,
+ isset($data["company"])?$data["company"]:null
);
return $customerCreateEvent;
diff --git a/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php
index c0de9075f..8269cecf3 100755
--- a/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php
+++ b/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php
@@ -74,6 +74,7 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
$this->cellphone = $cellphone;
$this->title = $title;
$this->zipcode = $zipcode;
+ $this->city = $city;
$this->reseller = $reseller;
$this->sponsor = $sponsor;
$this->discount = $discount;
diff --git a/core/lib/Thelia/Form/CustomerModification.php b/core/lib/Thelia/Form/CustomerModification.php
index 358154a18..4f12c6013 100755
--- a/core/lib/Thelia/Form/CustomerModification.php
+++ b/core/lib/Thelia/Form/CustomerModification.php
@@ -58,6 +58,12 @@ class CustomerModification extends BaseForm
$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()
diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html
index 48ccb3dc3..fef3b1d4f 100644
--- a/templates/admin/default/customer-edit.html
+++ b/templates/admin/default/customer-edit.html
@@ -29,7 +29,7 @@
{form name="thelia.customer.modification"}
-