Update profile - new method [Not finished yet]

This commit is contained in:
touffies
2013-10-18 09:47:11 +02:00
parent 871bc217a4
commit 9b617755ca

View File

@@ -31,10 +31,11 @@ use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Thelia\Form\CustomerCreation; use Thelia\Form\CustomerCreation;
use Thelia\Form\CustomerLogin; use Thelia\Form\CustomerLogin;
use Thelia\Form\CustomerLostPasswordForm; use Thelia\Form\CustomerLostPasswordForm;
use Thelia\Form\CustomerModification; use Thelia\Form\CustomerUpdateForm;
use Thelia\Form\Exception\FormValidationException; use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer; use Thelia\Model\Customer;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\CustomerQuery;
use Thelia\Tools\URL; use Thelia\Tools\URL;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Core\Security\Exception\WrongPasswordException; use Thelia\Core\Security\Exception\WrongPasswordException;
@@ -128,32 +129,56 @@ class CustomerController extends BaseFrontController
} }
} }
protected function getExistingCustomer($customer_id)
{
return CustomerQuery::create()
->findOneById($customer_id);
}
/** /**
* Update customer data. On success, redirect to success_url if exists. * Update customer data. On success, redirect to success_url if exists.
* Otherwise, display the same view again. * Otherwise, display the same view again.
*/ */
public function viewAction()
{
$this->checkAuth();
$customer = $this->getSecurityContext()->getCustomerUser();
$data = array(
'id' => $customer->getId(),
'title' => $customer->getTitleId(),
'firstname' => $customer->getFirstName(),
'lastname' => $customer->getLastName(),
'email' => $customer->getEmail(),
);
$customerUpdateForm = new CustomerUpdateForm($this->getRequest(), 'form', $data);
// Pass it to the parser
$this->getParserContext()->addForm($customerUpdateForm);
}
public function updateAction() public function updateAction()
{ {
if ($this->getSecurityContext()->hasCustomerUser()) { if ($this->getSecurityContext()->hasCustomerUser()) {
$message = false; $message = false;
$customerModification = new CustomerModification($this->getRequest()); $customerUpdateForm = new CustomerUpdateForm($this->getRequest());
try { try {
$customer = $this->getSecurityContext()->getCustomerUser(); $customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($customerModification, "post"); $form = $this->validateForm($customerUpdateForm, "post");
$customerChangeEvent = $this->createEventInstance($form->getData()); $customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer); $customerChangeEvent->setCustomer($customer);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent); $this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
$this->processLogin($customerChangeEvent->getCustomer()); $this->processLogin($customerChangeEvent->getCustomer());
$this->redirectSuccess($customerModification); $this->redirectSuccess($customerUpdateForm);
} catch (FormValidationException $e) { } catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $e->getMessage()); $message = sprintf("Please check your input: %s", $e->getMessage());
@@ -164,10 +189,10 @@ class CustomerController extends BaseFrontController
if ($message !== false) { if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message)); Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message));
$customerModification->setErrorMessage($message); $customerUpdateForm->setErrorMessage($message);
$this->getParserContext() $this->getParserContext()
->addForm($customerModification) ->addForm($customerUpdateForm)
->setGeneralError($message) ->setGeneralError($message)
; ;
} }
@@ -267,14 +292,14 @@ class CustomerController extends BaseFrontController
$data["title"], $data["title"],
$data["firstname"], $data["firstname"],
$data["lastname"], $data["lastname"],
$data["address1"], isset($data["address1"])?$data["address1"]:null,
$data["address2"], isset($data["address2"])?$data["address2"]:null,
$data["address3"], isset($data["address3"])?$data["address3"]:null,
$data["phone"], isset($data["phone"])?$data["phone"]:null,
$data["cellphone"], isset($data["cellphone"])?$data["cellphone"]:null,
$data["zipcode"], isset($data["zipcode"])?$data["zipcode"]:null,
$data["city"], isset($data["city"])?$data["city"]:null,
$data["country"], isset($data["country"])?$data["country"]:null,
isset($data["email"])?$data["email"]:null, isset($data["email"])?$data["email"]:null,
isset($data["password"]) ? $data["password"]:null, isset($data["password"]) ? $data["password"]:null,
$this->getRequest()->getSession()->getLang()->getId(), $this->getRequest()->getSession()->getLang()->getId(),