add country to as area

This commit is contained in:
Manuel Raynaud
2013-10-14 10:04:08 +02:00
parent 97ce036cbe
commit dfee7e87a6
7 changed files with 238 additions and 4 deletions

View File

@@ -23,12 +23,15 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\Area\AreaAddCountryEvent;
use Thelia\Core\Event\Area\AreaCreateEvent;
use Thelia\Core\Event\Area\AreaDeleteEvent;
use Thelia\Core\Event\Area\AreaUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\Area\AreaCountryForm;
use Thelia\Form\Area\AreaCreateForm;
use Thelia\Form\Area\AreaModificationForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\AreaQuery;
/**
@@ -219,4 +222,53 @@ class AreaController extends AbstractCrudController
{
$this->redirectToRoute('admin.configuration.shipping-configuration.default');
}
/**
* add a country to a define area
*/
public function addCountry()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
$areaCountryForm = new AreaCountryForm($this->getRequest());
$error_msg = null;
try {
$form = $this->validateForm($areaCountryForm);
$event = new AreaAddCountryEvent($form->get('area_id')->getData(), $form->get('country_id')->getData());
$this->dispatch(TheliaEvents::AREA_ADD_COUNTRY, $event);
if (! $this->eventContainsObject($event))
throw new \LogicException(
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
// Log object modification
if (null !== $changedObject = $this->getObjectFromEvent($event)) {
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
}
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToEditionTemplate($this->getRequest());
}
// Redirect to the success URL
$this->redirect($areaCountryForm->getSuccessUrl());
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext(
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $areaCountryForm);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
}
}