Merge branch 'master' into template

Conflicts:
	core/lib/Thelia/Controller/Front/AddressController.php
This commit is contained in:
Manuel Raynaud
2013-09-13 12:36:56 +02:00
37 changed files with 1267 additions and 235 deletions

View File

@@ -23,11 +23,12 @@
namespace Thelia\Controller\Front;
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
use Thelia\Core\Event\AddressEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\AddressCreateForm;
use Thelia\Form\AddressUpdateForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Base\AddressQuery;
use Thelia\Model\AddressQuery;
use Thelia\Model\Customer;
use Thelia\Tools\URL;
@@ -46,14 +47,14 @@ class AddressController extends BaseFrontController
*/
public function generateModalAction($address_id)
{
if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirect(URL::getInstance()->getIndexPage());
}
$this->checkAuth();
$this->checkXmlHttpRequest();
}
/**
* Create controller.
* Check if customer is logged in
@@ -62,9 +63,8 @@ class AddressController extends BaseFrontController
*/
public function createAction()
{
if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirect(URL::getInstance()->getIndexPage());
}
$this->checkAuth();
$addressCreate = new AddressCreateForm($this->getRequest());
@@ -96,20 +96,28 @@ class AddressController extends BaseFrontController
}
}
public function updateAction()
public function updateViewAction($address_id)
{
$this->checkAuth();
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if(!$address || $customer->getId() != $address->getCustomerId()) {
$this->redirectToRoute("home");
}
$this->getParserContext()->set("address_id", $address_id);
}
public function processUpdateAction($address_id)
{
$this->checkAuth();
$request = $this->getRequest();
if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirectToRoute("home");
}
if (null === $address_id = $request->get("address_id")) {
$this->redirectToRoute("home");
}
$addressUpdate = new AddressUpdateForm($request);
try {
$customer = $this->getSecurityContext()->getCustomerUser();
@@ -136,7 +144,7 @@ class AddressController extends BaseFrontController
} catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}
$this->getParserContext()->set("address_id", $address_id);
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
@@ -149,6 +157,22 @@ class AddressController extends BaseFrontController
}
}
public function deleteAction($address_id)
{
$this->checkAuth();
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if(!$address || $customer->getId() != $address->getCustomerId()) {
$this->redirectToRoute("home");
}
$this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address));
$this->redirectToRoute("customer.account.view");
}
protected function createAddressEvent($form)
{
return new AddressCreateOrUpdateEvent(
@@ -164,7 +188,8 @@ class AddressController extends BaseFrontController
$form->get("country")->getData(),
$form->get("cellphone")->getData(),
$form->get("phone")->getData(),
$form->get("company")->getData()
$form->get("company")->getData(),
$form->get("is_default")->getData()
);
}
}

View File

@@ -50,4 +50,11 @@ class BaseFrontController extends BaseController
{
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, array(), $referenceType), $urlParameters));
}
public function checkAuth()
{
if($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirectToRoute("customer.login.view");
}
}
}