add pre/post methods in Area model
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
namespace Thelia\Action;
|
namespace Thelia\Action;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Thelia\Core\Event\Area\AreaAddCountryEvent;
|
use Thelia\Core\Event\Area\AreaAddCountryEvent;
|
||||||
|
use Thelia\Core\Event\Area\AreaDeleteEvent;
|
||||||
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
|
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
|
||||||
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
|
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
@@ -43,6 +44,7 @@ class Area extends BaseAction implements EventSubscriberInterface
|
|||||||
public function addCountry(AreaAddCountryEvent $event)
|
public function addCountry(AreaAddCountryEvent $event)
|
||||||
{
|
{
|
||||||
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
|
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
|
||||||
|
$country->setDispatcher($this->getDispatcher());
|
||||||
$country->setAreaId($event->getAreaId())
|
$country->setAreaId($event->getAreaId())
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
@@ -53,6 +55,7 @@ class Area extends BaseAction implements EventSubscriberInterface
|
|||||||
public function removeCountry(AreaRemoveCountryEvent $event)
|
public function removeCountry(AreaRemoveCountryEvent $event)
|
||||||
{
|
{
|
||||||
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
|
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
|
||||||
|
$country->setDispatcher($this->getDispatcher());
|
||||||
$country->setAreaId(null)
|
$country->setAreaId(null)
|
||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
@@ -61,6 +64,7 @@ class Area extends BaseAction implements EventSubscriberInterface
|
|||||||
public function updatePostage(AreaUpdatePostageEvent $event)
|
public function updatePostage(AreaUpdatePostageEvent $event)
|
||||||
{
|
{
|
||||||
if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) {
|
if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) {
|
||||||
|
$area->setDispatcher($this->getDispatcher());
|
||||||
$area
|
$area
|
||||||
->setPostage($event->getPostage())
|
->setPostage($event->getPostage())
|
||||||
->save();
|
->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.
|
* Returns an array of event names this subscriber wants to listen to.
|
||||||
@@ -95,7 +109,8 @@ class Area extends BaseAction implements EventSubscriberInterface
|
|||||||
return array(
|
return array(
|
||||||
TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128),
|
TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128),
|
||||||
TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 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)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -696,6 +696,10 @@
|
|||||||
<requirement key="area_id">\d+</requirement>
|
<requirement key="area_id">\d+</requirement>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
|
<route id="admin.configuration.shipping-configuration..delete" path="/admin/configuration/shipping_configuration/delete">
|
||||||
|
<default key="_controller">Thelia\Controller\Admin\AreaController::deleteAction</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
<route id="admin.configuration.shipping-configuration.update.postage" path="/admin/configuration/shipping_configuration/update_postage/{area_id}">
|
<route id="admin.configuration.shipping-configuration.update.postage" path="/admin/configuration/shipping_configuration/update_postage/{area_id}">
|
||||||
<default key="_controller">Thelia\Controller\Admin\AreaController::updatePostageAction</default>
|
<default key="_controller">Thelia\Controller\Admin\AreaController::updatePostageAction</default>
|
||||||
<requirement key="area_id">\d+</requirement>
|
<requirement key="area_id">\d+</requirement>
|
||||||
|
|||||||
@@ -242,6 +242,15 @@ final class TheliaEvents
|
|||||||
const AREA_REMOVE_COUNTRY = 'action.area.removeCountry';
|
const AREA_REMOVE_COUNTRY = 'action.area.removeCountry';
|
||||||
const AREA_POSTAGE_UPDATE = 'action.area.postageUpdate';
|
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 ----------------------------------------
|
// -- Categories Associated Content ----------------------------------------
|
||||||
|
|
||||||
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
|
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
|
||||||
|
|||||||
@@ -2,8 +2,49 @@
|
|||||||
|
|
||||||
namespace Thelia\Model;
|
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;
|
use Thelia\Model\Base\Area as BaseArea;
|
||||||
|
|
||||||
class Area extends 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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user