allow to create a new area
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Action;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Area\AreaAddCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaCreateEvent;
|
||||
use Thelia\Core\Event\Area\AreaDeleteEvent;
|
||||
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
|
||||
@@ -31,6 +32,7 @@ use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\AreaQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Action\BaseAction;
|
||||
use Thelia\Model\Area as AreaModel;
|
||||
|
||||
|
||||
/**
|
||||
@@ -83,6 +85,18 @@ class Area extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function create(AreaCreateEvent $event)
|
||||
{
|
||||
$area = new AreaModel();
|
||||
|
||||
$area
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setName($event->getAreaName())
|
||||
->save();
|
||||
|
||||
$event->setArea($area);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
@@ -110,7 +124,8 @@ class Area extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128),
|
||||
TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128),
|
||||
TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128),
|
||||
TheliaEvents::AREA_DELETE => array('delete', 128)
|
||||
TheliaEvents::AREA_DELETE => array('delete', 128),
|
||||
TheliaEvents::AREA_CREATE => array('create', 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -700,6 +700,10 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\AreaController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.shipping-configuration.create" path="/admin/configuration/shipping_configuration/create">
|
||||
<default key="_controller">Thelia\Controller\Admin\AreaController::createAction</default>
|
||||
</route>
|
||||
|
||||
<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>
|
||||
<requirement key="area_id">\d+</requirement>
|
||||
|
||||
@@ -126,7 +126,7 @@ class AreaController extends AbstractCrudController
|
||||
|
||||
private function hydrateEvent($event, $formData)
|
||||
{
|
||||
$event->setName($formData['name']);
|
||||
$event->setAreaName($formData['name']);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class AreaCreateEvent extends AreaEvent
|
||||
/**
|
||||
* @param mixed $name
|
||||
*/
|
||||
public function setName($name)
|
||||
public function setAreaName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class AreaCreateEvent extends AreaEvent
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getName()
|
||||
public function getAreaName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user