diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php
index ddb1fcdf5..a6de7d3e7 100644
--- a/core/lib/Thelia/Action/Area.php
+++ b/core/lib/Thelia/Action/Area.php
@@ -24,6 +24,7 @@
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Area\AreaAddCountryEvent;
+use Thelia\Core\Event\Area\AreaDeleteEvent;
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
use Thelia\Core\Event\TheliaEvents;
@@ -43,6 +44,7 @@ class Area extends BaseAction implements EventSubscriberInterface
public function addCountry(AreaAddCountryEvent $event)
{
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
+ $country->setDispatcher($this->getDispatcher());
$country->setAreaId($event->getAreaId())
->save();
@@ -53,6 +55,7 @@ class Area extends BaseAction implements EventSubscriberInterface
public function removeCountry(AreaRemoveCountryEvent $event)
{
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
+ $country->setDispatcher($this->getDispatcher());
$country->setAreaId(null)
->save();
}
@@ -61,6 +64,7 @@ class Area extends BaseAction implements EventSubscriberInterface
public function updatePostage(AreaUpdatePostageEvent $event)
{
if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) {
+ $area->setDispatcher($this->getDispatcher());
$area
->setPostage($event->getPostage())
->save();
@@ -69,6 +73,16 @@ class Area extends BaseAction implements EventSubscriberInterface
}
}
+ public function delete(AreaDeleteEvent $event)
+ {
+ if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) {
+ $area->setDispatcher($this->getDispatcher());
+ $area->delete();
+
+ $event->setArea($area);
+ }
+ }
+
/**
* Returns an array of event names this subscriber wants to listen to.
@@ -95,7 +109,8 @@ class Area extends BaseAction implements EventSubscriberInterface
return array(
TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128),
TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128),
- TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128)
+ TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128),
+ TheliaEvents::AREA_DELETE => array('delete', 128)
);
}
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index e69853d99..9ff5516d7 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -696,6 +696,10 @@
\d+
+
+ Thelia\Controller\Admin\AreaController::deleteAction
+
+
Thelia\Controller\Admin\AreaController::updatePostageAction
\d+
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index 9d9e484ef..a21431bbc 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -242,6 +242,15 @@ final class TheliaEvents
const AREA_REMOVE_COUNTRY = 'action.area.removeCountry';
const AREA_POSTAGE_UPDATE = 'action.area.postageUpdate';
+ const BEFORE_CREATEAREA = 'action.before_createArea';
+ const AFTER_CREATEAREA = 'action.after_createArea';
+
+ const BEFORE_UPDATEAREA = 'action.before_updateArea';
+ const AFTER_UPDATEAREA = 'action.after_updateArea';
+
+ const BEFORE_DELETEAREA = 'action.before_deleteArea';
+ const AFTER_DELETEAREA = 'action.after_deleteArea';
+
// -- Categories Associated Content ----------------------------------------
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
diff --git a/core/lib/Thelia/Model/Area.php b/core/lib/Thelia/Model/Area.php
index 2a91e7cd3..f826c0fcd 100755
--- a/core/lib/Thelia/Model/Area.php
+++ b/core/lib/Thelia/Model/Area.php
@@ -2,8 +2,49 @@
namespace Thelia\Model;
+use Propel\Runtime\Connection\ConnectionInterface;
+use Thelia\Core\Event\Area\AreaEvent;
+use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\Area as BaseArea;
class Area extends BaseArea {
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
+
+ public function preInsert(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_CREATEAREA, new AreaEvent($this));
+
+ return true;
+ }
+
+ public function postInsert(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_CREATEAREA, new AreaEvent($this));
+ }
+
+ public function preUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_UPDATEAREA, new AreaEvent($this));
+
+ return true;
+ }
+
+ public function postUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_UPDATEAREA, new AreaEvent($this));
+ }
+
+ public function preDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_DELETEAREA, new AreaEvent($this));
+
+ return true;
+ }
+
+ public function postDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_DELETEAREA, new AreaEvent($this));
+ }
+
}