Merge branch 'country'

This commit is contained in:
Manuel Raynaud
2013-10-14 17:47:29 +02:00
38 changed files with 2178 additions and 324 deletions

View File

@@ -0,0 +1,131 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\AreaQuery;
use Thelia\Model\CountryQuery;
use Thelia\Action\BaseAction;
use Thelia\Model\Area as AreaModel;
/**
* Class Area
* @package Thelia\Action
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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();
$event->setArea($country->getArea());
}
}
public function removeCountry(AreaRemoveCountryEvent $event)
{
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
$country->setDispatcher($this->getDispatcher());
$country->setAreaId(null)
->save();
}
}
public function updatePostage(AreaUpdatePostageEvent $event)
{
if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) {
$area->setDispatcher($this->getDispatcher());
$area
->setPostage($event->getPostage())
->save();
$event->setArea($area);
}
}
public function delete(AreaDeleteEvent $event)
{
if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) {
$area->setDispatcher($this->getDispatcher());
$area->delete();
$event->setArea($area);
}
}
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.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
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_DELETE => array('delete', 128),
TheliaEvents::AREA_CREATE => array('create', 128)
);
}
}

View File

@@ -59,7 +59,19 @@ class Country extends BaseAction implements EventSubscriberInterface
public function update(CountryUpdateEvent $event)
{
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
$country
->setIsocode($event->getIsocode())
->setIsoalpha2($event->getIsoAlpha2())
->setIsoalpha3($event->getIsoAlpha3())
->setLocale($event->getLocale())
->setTitle($event->getTitle())
->setChapo($event->getChapo())
->setDescription($event->getDescription())
->save();
$event->setCountry($country);
}
}
public function delete(CountryDeleteEvent $event)

View File

@@ -0,0 +1,92 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\AreaDeliveryModule;
use Thelia\Model\AreaDeliveryModuleQuery;
/**
* Class ShippingZone
* @package Thelia\Action
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ShippingZone extends BaseAction implements EventSubscriberInterface
{
public function addArea(ShippingZoneAddAreaEvent $event)
{
$areaDelivery = new AreaDeliveryModule();
$areaDelivery
->setAreaId($event->getAreaId())
->setDeliveryModuleId($event->getShoppingZoneId())
->save();
}
public function removeArea(ShippingZoneRemoveAreaEvent $event)
{
$areaDelivery = AreaDeliveryModuleQuery::create()
->filterByAreaId($event->getAreaId())
->filterByDeliveryModuleId($event->getShoppingZoneId())
->findOne();
if($areaDelivery) {
$areaDelivery->delete();
} else {
throw new \RuntimeException(sprintf('areaDeliveryModule not found with area_id = %d and delivery_module_id = %d', $event->getAreaId(), $event->getShoppingZoneId()));
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
return array(
TheliaEvents::SHIPPING_ZONE_ADD_AREA => array('addArea', 128),
TheliaEvents::SHIPPING_ZONE_REMOVE_AREA => array('removeArea', 128),
);
}
}

View File

@@ -126,6 +126,16 @@
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.area" class="Thelia\Action\Area">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.shippingZone" class="Thelia\Action\ShippingZone">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
</services>
</config>

View File

@@ -7,6 +7,7 @@
<loops>
<loop class="Thelia\Core\Template\Loop\Accessory" name="accessory"/>
<loop class="Thelia\Core\Template\Loop\Address" name="address"/>
<loop class="Thelia\Core\Template\Loop\Area" name="area"/>
<loop class="Thelia\Core\Template\Loop\AssociatedContent" name="associated_content"/>
<loop class="Thelia\Core\Template\Loop\Attribute" name="attribute"/>
<loop class="Thelia\Core\Template\Loop\AttributeAvailability" name="attribute_availability"/>
@@ -125,6 +126,13 @@
<form name="thelia.admin.profile.modification" class="Thelia\Form\ProfileModificationForm"/>
<form name="thelia.admin.area.create" class="Thelia\Form\Area\AreaCreateForm"/>
<form name="thelia.admin.area.modification" class="Thelia\Form\Area\AreaModificationForm"/>
<form name="thelia.admin.area.country" class="Thelia\Form\Area\AreaCountryForm"/>
<form name="thelia.admin.area.postage" class="Thelia\Form\Area\AreaPostageForm"/>
<form name="thelia.shopping_zone_area" class="Thelia\Form\ShippingZone\ShippingZoneAddArea"/>
<form name="thelia.shopping_zone_remove_area" class="Thelia\Form\ShippingZone\ShippingZoneRemoveArea"/>
</forms>

View File

@@ -405,29 +405,6 @@
<default key="_controller">Thelia\Controller\Admin\FolderController::updatePositionAction</default>
</route>
<!-- Countries routes management -->
<route id="admin.configuration.countries.default" path="/admin/configuration/countries">
<default key="_controller">Thelia\Controller\Admin\CountryController::defaultAction</default>
</route>
<route id="admin.configuration.countries.create" path="/admin/configuration/countries/create">
<default key="_controller">Thelia\Controller\Admin\CountryController::createAction</default>
</route>
<route id="admin.configuration.countries.update" path="/admin/configuration/country/update/{country_id}">
<default key="_controller">Thelia\Controller\Admin\CountryController::updateAction</default>
<requirement key="country_id">\d+</requirement>
</route>
<route id="admin.configuration.countries.delete" path="/admin/configuration/countries/delete">
<default key="_controller">Thelia\Controller\Admin\CountryController::deleteAction</default>
</route>
<route id="admin.configuration.toggle-default" path="/admin/configuration/country/toggleDefault">
<default key="_controller">Thelia\Controller\Admin\CountryController::toggleDefaultAction</default>
</route>
<!-- content routes management -->
<route id="admin.content.create" path="/admin/content/create">
<default key="_controller">Thelia\Controller\Admin\ContentController::createAction</default>
@@ -706,21 +683,79 @@
<requirement key="shipping_zones_id">\d+</requirement>
</route>
<route id="admin.configuration.shipping-zones.area.add" path="/admin/configuration/shipping_zones/area/add" methods="post">
<default key="_controller">Thelia\Controller\Admin\ShippingZoneController::addArea</default>
</route>
<route id="admin.configuration.shipping-zones.area.remove" path="/admin/configuration/shipping_zones/area/remove">
<default key="_controller">Thelia\Controller\Admin\ShippingZoneController::removeArea</default>
</route>
<!-- end shipping routes management -->
<!-- Shipping zones routes management -->
<route id="admin.configuration.shipping-configuration.default" path="/admin/configuration/shipping_configuration">
<default key="_controller">Thelia\Controller\Admin\ShippingConfigurationController::indexAction</default>
<default key="_controller">Thelia\Controller\Admin\AreaController::defaultAction</default>
</route>
<route id="admin.configuration.shipping-configuration.update.view" path="/admin/configuration/shipping_configuration/update/{shipping_configuration_id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\ShippingConfigurationController::updateAction</default>
<requirement key="shipping_configuration_id">\d+</requirement>
<route id="admin.configuration.shipping-configuration.update.view" path="/admin/configuration/shipping_configuration/update/{area_id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\AreaController::updateAction</default>
<requirement key="area_id">\d+</requirement>
</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.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>
</route>
<route id="admin.configuration.shipping-configuration.country.add" path="/admin/configuration/shipping_configuration/country/add" methods="post">
<default key="_controller">Thelia\Controller\Admin\AreaController::addCountry</default>
</route>
<route id="admin.configuration.shipping-configuration.country.remove" path="/admin/configuration/shipping_configuration/country/remove" methods="post">
<default key="_controller">Thelia\Controller\Admin\AreaController::removeCountry</default>
</route>
<!-- end shipping routes management -->
<!-- Countries routes management -->
<route id="admin.configuration.countries.default" path="/admin/configuration/countries">
<default key="_controller">Thelia\Controller\Admin\CountryController::defaultAction</default>
</route>
<route id="admin.configuration.countries.create" path="/admin/configuration/countries/create">
<default key="_controller">Thelia\Controller\Admin\CountryController::createAction</default>
</route>
<route id="admin.configuration.countries.update" path="/admin/configuration/country/update/{country_id}">
<default key="_controller">Thelia\Controller\Admin\CountryController::updateAction</default>
<requirement key="country_id">\d+</requirement>
</route>
<route id="admin.configuration.countries.save" path="/admin/configuration/country/save/{country_id}">
<default key="_controller">Thelia\Controller\Admin\CountryController::processUpdateAction</default>
<requirement key="country_id">\d+</requirement>
</route>
<route id="admin.configuration.countries.delete" path="/admin/configuration/countries/delete">
<default key="_controller">Thelia\Controller\Admin\CountryController::deleteAction</default>
</route>
<route id="admin.configuration.countries.toggle-default" path="/admin/configuration/country/toggleDefault">
<default key="_controller">Thelia\Controller\Admin\CountryController::toggleDefaultAction</default>
</route>
<!-- end countries routes management -->
<!-- feature and features value management -->

View File

@@ -0,0 +1,326 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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\AreaRemoveCountryEvent;
use Thelia\Core\Event\Area\AreaUpdateEvent;
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\Area\AreaCountryForm;
use Thelia\Form\Area\AreaCreateForm;
use Thelia\Form\Area\AreaModificationForm;
use Thelia\Form\Area\AreaPostageForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\AreaQuery;
/**
* Class AreaController
* @package Thelia\Controller\Admin
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaController extends AbstractCrudController
{
public function __construct()
{
parent::__construct(
'area',
null,
null,
'admin.area.default',
'admin.area.create',
'admin.area.update',
'admin.area.delete',
TheliaEvents::AREA_CREATE,
TheliaEvents::AREA_UPDATE,
TheliaEvents::AREA_DELETE
);
}
protected function getAreaId()
{
return $this->getRequest()->get('area_id', 0);
}
/**
* Return the creation form for this object
*/
protected function getCreationForm()
{
return new AreaCreateForm($this->getRequest());
}
/**
* Return the update form for this object
*/
protected function getUpdateForm()
{
return new AreaModificationForm($this->getRequest());
}
/**
* Hydrate the update form for this object, before passing it to the update template
*
* @param unknown $object
*/
protected function hydrateObjectForm($object)
{
$data = array(
'name' => $object->getName()
);
return new AreaModificationForm($this->getRequest(), 'form', $data);
}
/**
* Creates the creation event with the provided form data
*
* @param unknown $formData
*
* @return \Thelia\Core\Event\Area\AreaCreateEvent
*/
protected function getCreationEvent($formData)
{
$event = new AreaCreateEvent();
return $this->hydrateEvent($event, $formData);
}
/**
* Creates the update event with the provided form data
*
* @param unknown $formData
*/
protected function getUpdateEvent($formData)
{
$event = new AreaUpdateEvent();
return $this->hydrateEvent($event, $formData);
}
private function hydrateEvent($event, $formData)
{
$event->setAreaName($formData['name']);
return $event;
}
/**
* Creates the delete event with the provided form data
*/
protected function getDeleteEvent()
{
return new AreaDeleteEvent($this->getAreaId());
}
/**
* Return true if the event contains the object, e.g. the action has updated the object in the event.
*
* @param \Thelia\Core\Event\Area\AreaEvent $event
*/
protected function eventContainsObject($event)
{
return $event->hasArea();
}
/**
* Get the created object from an event.
*
* @param \Thelia\Core\Event\Area\AreaEvent $event
*/
protected function getObjectFromEvent($event)
{
return $event->getArea();
}
/**
* Load an existing object from the database
*/
protected function getExistingObject()
{
return AreaQuery::create()->findPk($this->getAreaId());
}
/**
* Returns the object label form the object event (name, title, etc.)
*
* @param \Thelia\Model\Area $object
*/
protected function getObjectLabel($object)
{
return $object->getName();
}
/**
* Returns the object ID from the object
*
* @param \Thelia\Model\Area $object
*/
protected function getObjectId($object)
{
return $object->getId();
}
/**
* Render the main list template
*
* @param unknown $currentOrder, if any, null otherwise.
*/
protected function renderListTemplate($currentOrder)
{
return $this->render("shipping-configuration");
}
/**
* Render the edition template
*/
protected function renderEditionTemplate()
{
return $this->render('shipping-configuration-edit',array(
'area_id' => $this->getAreaId()
));
}
/**
* Redirect to the edition template
*/
protected function redirectToEditionTemplate()
{
$this->redirectToRoute('admin.configuration.shipping-configuration.update.view', array(), array(
"area_id" => $this->getAreaId()
)
);
}
/**
* Redirect to the list template
*/
protected function redirectToListTemplate()
{
$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, new country added", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
}
// 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();
}
public function removeCountry()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
$request = $this->getRequest();
$removeCountryEvent = new AreaRemoveCountryEvent($request->request->get('areai_id', 0), $request->request->get('country_id', 0));
$this->dispatch(TheliaEvents::AREA_REMOVE_COUNTRY, $removeCountryEvent);
$this->redirectToEditionTemplate();
}
public function updatePostageAction()
{
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
$areaUpdateForm = new AreaPostageForm($this->getRequest());
$error_msg = null;
try {
$form = $this->validateForm($areaUpdateForm);
$event = new AreaUpdatePostageEvent($form->get('area_id')->getData());
$event->setPostage($form->get('postage')->getData());
$this->dispatch(TheliaEvents::AREA_POSTAGE_UPDATE, $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, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
}
// Redirect to the success URL
$this->redirect($areaUpdateForm->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, $areaUpdateForm);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
}
}

View File

@@ -246,7 +246,7 @@ class BaseAdminController extends BaseController
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
*/
public function redirectToRoute($routeId, $urlParameters = array(), $routeParameters = array())
public function redirectToRoute($routeId, array $urlParameters = array(), array $routeParameters = array())
{
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, $routeParameters), $urlParameters));
}

View File

@@ -39,24 +39,6 @@ use Thelia\Model\CountryQuery;
class CountryController extends AbstractCrudController
{
/**
* @param string $objectName the lower case object name. Example. "message"
*
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
* @param string $orderRequestParameterName Name of the request parameter that set the list order (null if list is not sortable)
*
* @param string $viewPermissionIdentifier the 'view' permission identifier. Example: "admin.configuration.message.view"
* @param string $createPermissionIdentifier the 'create' permission identifier. Example: "admin.configuration.message.create"
* @param string $updatePermissionIdentifier the 'update' permission identifier. Example: "admin.configuration.message.update"
* @param string $deletePermissionIdentifier the 'delete' permission identifier. Example: "admin.configuration.message.delete"
*
* @param string $createEventIdentifier the dispatched create TheliaEvent identifier. Example: TheliaEvents::MESSAGE_CREATE
* @param string $updateEventIdentifier the dispatched update TheliaEvent identifier. Example: TheliaEvents::MESSAGE_UPDATE
* @param string $deleteEventIdentifier the dispatched delete TheliaEvent identifier. Example: TheliaEvents::MESSAGE_DELETE
*
* @param string $visibilityToggleEventIdentifier the dispatched visibility toggle TheliaEvent identifier, or null if the object has no visible options. Example: TheliaEvents::MESSAGE_TOGGLE_VISIBILITY
* @param string $changePositionEventIdentifier the dispatched position change TheliaEvent identifier, or null if the object has no position. Example: TheliaEvents::MESSAGE_UPDATE_POSITION
*/
public function __construct()
{
parent::__construct(
@@ -129,7 +111,7 @@ class CountryController extends AbstractCrudController
*/
protected function getUpdateEvent($formData)
{
$event = new CountryUpdateEvent();
$event = new CountryUpdateEvent($formData['id']);
return $this->hydrateEvent($event, $formData);
}
@@ -139,6 +121,8 @@ class CountryController extends AbstractCrudController
$event
->setLocale($formData['locale'])
->setTitle($formData['title'])
->setChapo($formData['chapo'])
->setDescription($formData['description'])
->setIsocode($formData['isocode'])
->setIsoAlpha2($formData['isoalpha2'])
->setIsoAlpha3($formData['isoalpha3'])
@@ -236,7 +220,10 @@ class CountryController extends AbstractCrudController
*/
protected function redirectToEditionTemplate()
{
$this->redirectToRoute('admin.configuration.countries.update', array(), $this->getRequest()->get('country_id', 0));
$this->redirectToRoute('admin.configuration.countries.update', array(), array(
"country_id" => $this->getRequest()->get('country_id', 0)
)
);
}
/**

View File

@@ -22,6 +22,12 @@
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Form\ShippingZone\ShippingZoneAddArea;
use Thelia\Form\ShippingZone\ShippingZoneRemoveArea;
/**
* Class ShippingZoneController
@@ -30,6 +36,8 @@ namespace Thelia\Controller\Admin;
*/
class ShippingZoneController extends BaseAdminController
{
public $objectName = 'areaDeliveryModule';
public function indexAction()
{
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
@@ -38,8 +46,99 @@ class ShippingZoneController extends BaseAdminController
public function updateAction($shipping_zones_id)
{
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
return $this->render("shipping-zones-edit", array(
"shipping_zones_id" => $shipping_zones_id
));
}
/**
* @return mixed|\Symfony\Component\HttpFoundation\Response
*/
public function addArea()
{
if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
$shippingAreaForm = new ShippingZoneAddArea($this->getRequest());
$error_msg = null;
try {
$form = $this->validateForm($shippingAreaForm);
$event = new ShippingZoneAddAreaEvent(
$form->get('area_id')->getData(),
$form->get('shipping_zone_id')->getData()
);
$this->dispatch(TheliaEvents::SHIPPING_ZONE_ADD_AREA, $event);
// Redirect to the success URL
$this->redirect($shippingAreaForm->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, $shippingAreaForm);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
}
public function removeArea()
{
if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
$shippingAreaForm = new ShippingZoneRemoveArea($this->getRequest());
$error_msg = null;
try {
$form = $this->validateForm($shippingAreaForm);
$event = new ShippingZoneRemoveAreaEvent(
$form->get('area_id')->getData(),
$form->get('shipping_zone_id')->getData()
);
$this->dispatch(TheliaEvents::SHIPPING_ZONE_REMOVE_AREA, $event);
// Redirect to the success URL
$this->redirect($shippingAreaForm->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, $shippingAreaForm);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
}
/**
* Render the edition template
*/
protected function renderEditionTemplate()
{
return $this->render("shipping-zones-edit", array(
"shipping_zones_id" => $this->getShippingZoneId()
));
}
protected function getShippingZoneId()
{
return $this->getRequest()->get('shipping_zone_id', 0);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Area;
/**
* Class AreaAddCountryEvent
* @package Thelia\Core\Event\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaAddCountryEvent extends AreaEvent
{
protected $area_id;
protected $country_id;
function __construct($area_id, $country_id)
{
$this->area_id = $area_id;
$this->country_id = $country_id;
}
/**
* @param mixed $area_id
*
* @return $this
*/
public function setAreaId($area_id)
{
$this->area_id = $area_id;
return $this;
}
/**
* @return mixed
*/
public function getAreaId()
{
return $this->area_id;
}
/**
* @param mixed $country_id
*
* @return $this
*/
public function setCountryId($country_id)
{
$this->country_id = $country_id;
return $this;
}
/**
* @return mixed
*/
public function getCountryId()
{
return $this->country_id;
}
}

View File

@@ -1,7 +1,7 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
@@ -17,29 +17,37 @@
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
namespace Thelia\Core\Event\Area;
/**
* Class ShippingConfigurationController
* @package Thelia\Controller\Admin
* Class AreaCreateEvent
* @package Thelia\Core\Event\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ShippingConfigurationController extends BaseAdminController
class AreaCreateEvent extends AreaEvent
{
public function indexAction()
protected $name;
/**
* @param mixed $name
*/
public function setAreaName($name)
{
if (null !== $response = $this->checkAuth("admin.shipping-configuration.view")) return $response;
return $this->render("shipping-configuration", array("display_shipping_configuration" => 20));
$this->name = $name;
}
public function updateAction($shipping_configuration_id)
/**
* @return mixed
*/
public function getAreaName()
{
return $this->render("shipping-configuration-edit", array(
"shipping_configuration_id" => $shipping_configuration_id
));
return $this->name;
}
}
}

View File

@@ -0,0 +1,65 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Area;
/**
* Class AreaDeleteEvent
* @package Thelia\Core\Event\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaDeleteEvent extends AreaEvent
{
/**
* @var int area id
*/
protected $area_id;
public function __construct($area_id)
{
$this->area_id = $area_id;
}
/**
* @param null $area_id
*
* @return $this
*/
public function setAreaId($area_id)
{
$this->area_id = $area_id;
return $this;
}
/**
* @return null
*/
public function getAreaId()
{
return $this->area_id;
}
}

View File

@@ -0,0 +1,66 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Area;
use Thelia\Core\Event\ActionEvent;
/**
* Class AreaEvent
* @package Thelia\Core\Event\Shipping
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaEvent extends ActionEvent
{
protected $area;
public function __construct($area = null)
{
$this->area = $area;
}
/**
* @param mixed $area
*
* @return $this
*/
public function setArea($area)
{
$this->area = $area;
return $this;
}
/**
* @return mixed
*/
public function getArea()
{
return $this->area;
}
public function hasArea()
{
return null !== $this->area;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Area;
/**
* Class AreaRemoveCountryEvent
* @package Thelia\Core\Event\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaRemoveCountryEvent extends AreaAddCountryEvent
{
}

View File

@@ -0,0 +1,35 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Area;
/**
* Class AreaUpdateEvent
* @package Thelia\Core\Event\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaUpdateEvent extends AreaCreateEvent
{
}

View File

@@ -0,0 +1,85 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Area;
/**
* Class AreaUpdatePostageEvent
* @package Thelia\Core\Event\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaUpdatePostageEvent extends AreaEvent
{
protected $area_id;
protected $postage;
function __construct($area_id)
{
$this->area_id = $area_id;
}
/**
* @param mixed $area_id
*
* @return $this
*/
public function setAreaId($area_id)
{
$this->area_id = $area_id;
return $this;
}
/**
* @return mixed
*/
public function getAreaId()
{
return $this->area_id;
}
/**
* @param mixed $postage
*
* @return $this
*/
public function setPostage($postage)
{
$this->postage = $postage;
return $this;
}
/**
* @return mixed
*/
public function getPostage()
{
return $this->postage;
}
}

View File

@@ -31,5 +31,90 @@ namespace Thelia\Core\Event\Country;
*/
class CountryUpdateEvent extends CountryCreateEvent
{
protected $country_id;
protected $chapo;
protected $description;
protected $postscriptum;
function __construct($country_id)
{
$this->country_id = $country_id;
}
/**
* @param mixed $chapo
*/
public function setChapo($chapo)
{
$this->chapo = $chapo;
return $this;
}
/**
* @return mixed
*/
public function getChapo()
{
return $this->chapo;
}
/**
* @param mixed $description
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $postscriptum
*/
public function setPostscriptum($postscriptum)
{
$this->postscriptum = $postscriptum;
return $this;
}
/**
* @return mixed
*/
public function getPostscriptum()
{
return $this->postscriptum;
}
/**
* @param mixed $country_id
*/
public function setCountryId($country_id)
{
$this->country_id = $country_id;
return $this;
}
/**
* @return mixed
*/
public function getCountryId()
{
return $this->country_id;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\ShippingZone;
use Thelia\Core\Event\ActionEvent;
/**
* Class ShippingZoneAddAreaEvent
* @package Thelia\Core\Event\ShippingZone
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ShippingZoneAddAreaEvent extends ActionEvent
{
protected $area_id;
protected $shopping_zone_id;
function __construct($area_id, $shopping_zone_id)
{
$this->area_id = $area_id;
$this->shopping_zone_id = $shopping_zone_id;
}
/**
* @param mixed $area_id
*
* @return $this
*/
public function setAreaId($area_id)
{
$this->area_id = $area_id;
return $this;
}
/**
* @return mixed
*/
public function getAreaId()
{
return $this->area_id;
}
/**
* @param mixed $shopping_zone_id
*
* @return $this
*/
public function setShoppingZoneId($shopping_zone_id)
{
$this->shopping_zone_id = $shopping_zone_id;
return $this;
}
/**
* @return mixed
*/
public function getShoppingZoneId()
{
return $this->shopping_zone_id;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\ShippingZone;
/**
* Class ShippingZoneRemoveAreaEvent
* @package Thelia\Core\Event\ShippingZone
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ShippingZoneRemoveAreaEvent extends ShippingZoneAddAreaEvent
{
}

View File

@@ -232,6 +232,30 @@ final class TheliaEvents
const BEFORE_UPDATECOUNTRY = "action.before_updateCountry";
const AFTER_UPDATECOUNTRY = "action.after_updateCountry";
// -- AREA CONFIGURATION MANAGEMENT
const AREA_CREATE = 'action.createArea';
const AREA_UPDATE = 'action.updateArea';
const AREA_DELETE = 'action.deleteArea';
const AREA_ADD_COUNTRY = 'action.area.addCountry';
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';
// -- SHIPPING ZONE MANAGEMENT
const SHIPPING_ZONE_ADD_AREA = 'action.shippingZone.addArea';
const SHIPPING_ZONE_REMOVE_AREA = 'action.shippingZone.removeArea';
// -- Categories Associated Content ----------------------------------------
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";

View File

@@ -0,0 +1,144 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\AreaQuery;
/**
* Class Area
* @package Thelia\Core\Template\Loop
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class Area extends BaseLoop
{
public $timestampable = true;
/**
*
* define all args used in your loop
*
*
* example :
*
* public function getArgDefinitions()
* {
* return new ArgumentCollection(
* Argument::createIntListTypeArgument('id'),
* new Argument(
* 'ref',
* new TypeCollection(
* new Type\AlphaNumStringListType()
* )
* ),
* Argument::createIntListTypeArgument('category'),
* Argument::createBooleanTypeArgument('new'),
* Argument::createBooleanTypeArgument('promo'),
* Argument::createFloatTypeArgument('min_price'),
* Argument::createFloatTypeArgument('max_price'),
* Argument::createIntTypeArgument('min_stock'),
* Argument::createFloatTypeArgument('min_weight'),
* Argument::createFloatTypeArgument('max_weight'),
* Argument::createBooleanTypeArgument('current'),
*
* );
* }
*
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntTypeArgument('with_zone'),
Argument::createIntTypeArgument('without_zone')
);
}
/**
*
* this function have to be implement in your own loop class.
*
* All loops parameters can be accessible via getter.
*
* for example, ref parameter is accessible through getRef method
*
* @param $pagination
*
* @return mixed
*/
public function exec(&$pagination)
{
$id = $this->getId();
$search = AreaQuery::create();
if ($id) {
$search->filterById($id, Criteria::IN);
}
$withZone = $this->getWith_zone();
if ($withZone) {
$search->joinAreaDeliveryModule('with_zone')
->where('`with_zone`.delivery_module_id '.Criteria::EQUAL.' ?', $withZone, \PDO::PARAM_INT);
}
$withoutZone = $this->getWithout_zone();
if($withoutZone)
{
$search->joinAreaDeliveryModule('without_zone', Criteria::LEFT_JOIN)
->addJoinCondition('without_zone', 'delivery_module_id '.Criteria::EQUAL.' ?', $withoutZone, null, \PDO::PARAM_INT)
->where('`without_zone`.delivery_module_id '.Criteria::ISNULL);
}
//echo $search->toString(); exit;
$areas = $this->search($search, $pagination);
$loopResult = new LoopResult($areas);
foreach ($areas as $area) {
$loopResultRow = new LoopResultRow($loopResult, $area, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set('ID', $area->getId())
->set('NAME', $area->getName())
->set('POSTAGE', $area->getPostage())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
/**
* Class AreaCountryForm
* @package Thelia\Form\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaCountryForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('area_id', 'integer', array(
'constraints' => array(
new GreaterThan(array('value' => 0)),
new NotBlank()
)
))
->add('country_id', 'integer', array(
'constraints' => array(
new GreaterThan(array('value' => 0)),
new NotBlank()
),
'label_attr' => array(
'for' => 'area_country'
),
'label' => Translator::getInstance()->trans('Country')
));
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_area_country';
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
/**
* Class AreaCreateForm
* @package Thelia\Form\Shipping
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaCreateForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('name', 'text', array(
'constraints' => array(
new NotBlank()
),
'label_attr' => array('for' => 'shipping_name'),
'label' => Translator::getInstance()->trans('shipping area name')
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_area_creation';
}
}

View File

@@ -0,0 +1,49 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Form\Area\AreaCreateForm;
/**
* Class AreaModificationForm
* @package Thelia\Form\Shipping
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaModificationForm extends AreaCreateForm
{
public function buildForm()
{
parent::buildForm();
$this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
;
}
public function getName()
{
return 'thelia_area_modification';
}
}

View File

@@ -0,0 +1,88 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Core\Translation\Translator;
/**
* Class AreaPostageForm
* @package Thelia\Form\Area
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AreaPostageForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('area_id', 'integer', array(
'constraints' => array(
new GreaterThan(array('value' => 0)),
new NotBlank()
)
))
->add('postage', 'number', array(
'constraints' => array(
new GreaterThanOrEqual(array('value' => 0)),
new NotBlank()
),
'label_attr' => array('for' => 'area_postage'),
'label' => Translator::getInstance()->trans('Postage')
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_area_postage';
}
}

View File

@@ -122,16 +122,6 @@ abstract class DocumentModification extends BaseForm
)
)
)
->add(
'postscriptum',
'text',
array(
'constraints' => array(),
'label' => Translator::getInstance()->trans('Post Scriptum'),
'label_attr' => array(
'for' => 'postscriptum'
)
)
);
;
}
}

View File

@@ -130,16 +130,6 @@ abstract class ImageModification extends BaseForm
)
)
)
->add(
'postscriptum',
'text',
array(
'constraints' => array(),
'label' => Translator::getInstance()->trans('Post Scriptum'),
'label_attr' => array(
'for' => 'postscriptum'
)
)
);
;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\ShippingZone;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
/**
* Class ShippingZoneAddArea
* @package Thelia\Form\ShippingZone
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ShippingZoneAddArea extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('area_id', 'integer', array(
'constraints' => array(
new NotBlank(),
new GreaterThan(array('value' => 0))
),
'label_attr' => array('for' => 'shipping_area'),
'label' => Translator::getInstance()->trans('Area')
))
->add('shipping_zone_id', 'integer', array(
'constraints' => array(
new NotBlank(),
new GreaterThan(array('value' => 0))
)
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_shippingzone_area';
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\ShippingZone;
/**
* Class ShippingZoneRemoveArea
* @package Thelia\Form\ShippingZone
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ShippingZoneRemoveArea extends ShippingZoneAddArea
{
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_shippingzone_remove_area';
}
}

View File

@@ -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));
}
}