update customer general info

This commit is contained in:
Manuel Raynaud
2013-09-12 11:24:24 +02:00
parent 4b643a7a9e
commit 5d87e48ba0
6 changed files with 131 additions and 24 deletions

View File

@@ -43,7 +43,7 @@
</route> </route>
<route id="admin.customer.update.process" path="/admin/customer/update/{customer_id}" methods="post"> <route id="admin.customer.update.process" path="/admin/customer/update/{customer_id}" methods="post">
<default key="_controller">Thelia\Controller\Admin\CustomerController::viewAction</default> <default key="_controller">Thelia\Controller\Admin\CustomerController::updateAction</default>
<requirement key="customer_id">\d+</requirement> <requirement key="customer_id">\d+</requirement>
</route> </route>

View File

@@ -22,6 +22,13 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Controller\Admin; 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 * Class CustomerController
@@ -38,9 +45,96 @@ class CustomerController extends BaseAdminController
public function viewAction($customer_id) public function viewAction($customer_id)
{ {
if (null !== $response = $this->checkAuth("admin.customers.view")) return $response;
return $this->render("customer-edit", array( return $this->render("customer-edit", array(
"customer_id" => $customer_id "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;
}
} }

View File

@@ -22,7 +22,6 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Controller\Front; namespace Thelia\Controller\Front;
use Symfony\Component\Form\Form;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\CustomerLoginEvent; use Thelia\Core\Event\CustomerLoginEvent;
use Thelia\Core\Event\LostPasswordEvent; use Thelia\Core\Event\LostPasswordEvent;
@@ -98,7 +97,7 @@ class CustomerController extends BaseFrontController
try { try {
$form = $this->validateForm($customerCreation, "post"); $form = $this->validateForm($customerCreation, "post");
$customerCreateEvent = $this->createEventInstance($form); $customerCreateEvent = $this->createEventInstance($form->getData());
$this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent); $this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
@@ -147,7 +146,7 @@ class CustomerController extends BaseFrontController
$form = $this->validateForm($customerModification, "post"); $form = $this->validateForm($customerModification, "post");
$customerChangeEvent = $this->createEventInstance($form); $customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer); $customerChangeEvent->setCustomer($customer);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent); $this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
@@ -260,27 +259,27 @@ class CustomerController extends BaseFrontController
* @param $data * @param $data
* @return CustomerCreateOrUpdateEvent * @return CustomerCreateOrUpdateEvent
*/ */
private function createEventInstance(Form $form) private function createEventInstance($data)
{ {
$customerCreateEvent = new CustomerCreateOrUpdateEvent( $customerCreateEvent = new CustomerCreateOrUpdateEvent(
$form->get("title")->getData(), $data["title"],
$form->get("firstname")->getData(), $data["firstname"],
$form->get("lastname")->getData(), $data["lastname"],
$form->get("address1")->getData(), $data["address1"],
$form->get("address2")->getData(), $data["address2"],
$form->get("address3")->getData(), $data["address3"],
$form->get("phone")->getData(), $data["phone"],
$form->get("cellphone")->getData(), $data["cellphone"],
$form->get("zipcode")->getData(), $data["zipcode"],
$form->get("city")->getData(), $data["city"],
$form->get("country")->getData(), $data["country"],
$form->get("email")->getData(), isset($data["email"])?$data["email"]:null,
$form->get("password")->getData(), isset($data["password"]) ? $data["password"]:null,
$this->getRequest()->getSession()->getLang()->getId(), $this->getRequest()->getSession()->getLang()->getId(),
$form->get("reseller")->getData(), isset($data["reseller"])?$data["reseller"]:null,
$form->get("sponsor")->getData(), isset($data["sponsor"])?$data["sponsor"]:null,
$form->get("discount")->getData(), isset($data["discount"])?$data["discount"]:null,
$form->get("company")->getData() isset($data["company"])?$data["company"]:null
); );
return $customerCreateEvent; return $customerCreateEvent;

View File

@@ -74,6 +74,7 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
$this->cellphone = $cellphone; $this->cellphone = $cellphone;
$this->title = $title; $this->title = $title;
$this->zipcode = $zipcode; $this->zipcode = $zipcode;
$this->city = $city;
$this->reseller = $reseller; $this->reseller = $reseller;
$this->sponsor = $sponsor; $this->sponsor = $sponsor;
$this->discount = $discount; $this->discount = $discount;

View File

@@ -58,6 +58,12 @@ class CustomerModification extends BaseForm
$this->formBuilder $this->formBuilder
->add('update_logged_in_user', 'integer') // In a front office context, update the in-memory logged-in user data ->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( ->add("firstname", "text", array(
"constraints" => array( "constraints" => array(
new Constraints\NotBlank() new Constraints\NotBlank()

View File

@@ -29,7 +29,7 @@
<div class="col-md-12"> <div class="col-md-12">
{form name="thelia.customer.modification"} {form name="thelia.customer.modification"}
<form method="POST" action="{url path="/admin/customers/save/{$ID}"}" {form_enctype form=$form} class="clearfix"> <form method="POST" action="{url path="/admin/customer/update/{$ID}"}" {form_enctype form=$form} class="clearfix">
<div class="row inner-toolbar clearfix"> <div class="row inner-toolbar clearfix">
<div class="col-md-6 inner-actions pull-right"> <div class="col-md-6 inner-actions pull-right">
@@ -42,7 +42,7 @@
{form_hidden_fields form=$form} {form_hidden_fields form=$form}
{form_field form=$form field='success_url'} {form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{url path='/admin/customers'}" /> <input type="hidden" name="{$name}" value="{url path="/admin/customer/update/{$ID}"}" />
{/form_field} {/form_field}
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if} {if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
@@ -80,6 +80,13 @@
<p class="title title-without-tabs">{intl l="Default address"}</p> <p class="title title-without-tabs">{intl l="Default address"}</p>
{form_field form=$form field='company'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$COMPANY}" title="{intl l="{$label}"}" placeholder="{intl l='Company'}">
</div>
{/form_field}
{form_field form=$form field='address1'} {form_field form=$form field='address1'}
<div class="form-group {if $error}has-error{/if}"> <div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label> <label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>