Rajout du code core qui n'était pas gitté
This commit is contained in:
147
core/lib/Thelia/Action/OrderStatus.php
Normal file
147
core/lib/Thelia/Action/OrderStatus.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusCreateEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusDeleteEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\OrderStatus as OrderStatusModel;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
|
||||
/**
|
||||
* Class OrderStatus
|
||||
* @package Thelia\Action
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
* @since 2.4
|
||||
*/
|
||||
class OrderStatus extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @param OrderStatusCreateEvent $event
|
||||
*/
|
||||
public function create(OrderStatusCreateEvent $event)
|
||||
{
|
||||
$this->createOrUpdate($event, new OrderStatusModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderStatusUpdateEvent $event
|
||||
*/
|
||||
public function update(OrderStatusUpdateEvent $event)
|
||||
{
|
||||
$orderStatus = $this->getOrderStatus($event);
|
||||
$this->createOrUpdate($event, $orderStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderStatusDeleteEvent $event
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(OrderStatusDeleteEvent $event)
|
||||
{
|
||||
$orderStatus = $this->getOrderStatus($event);
|
||||
|
||||
if ($orderStatus->getProtectedStatus()) {
|
||||
throw new \Exception(
|
||||
Translator::getInstance()->trans('This status is protected.')
|
||||
. ' ' . Translator::getInstance()->trans('You can not delete it.')
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== OrderQuery::create()->findOneByStatusId($orderStatus->getId())) {
|
||||
throw new \Exception(
|
||||
Translator::getInstance()->trans('Some commands use this status.')
|
||||
. ' ' . Translator::getInstance()->trans('You can not delete it.')
|
||||
);
|
||||
}
|
||||
|
||||
$orderStatus->delete();
|
||||
|
||||
$event->setOrderStatus($orderStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::ORDER_STATUS_CREATE => ["create", 128],
|
||||
TheliaEvents::ORDER_STATUS_UPDATE => ["update", 128],
|
||||
TheliaEvents::ORDER_STATUS_DELETE => ["delete", 128],
|
||||
TheliaEvents::ORDER_STATUS_UPDATE_POSITION => ["updatePosition", 128]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderStatusEvent $event
|
||||
* @param OrderStatusModel $orderStatus
|
||||
*/
|
||||
protected function createOrUpdate(OrderStatusEvent $event, OrderStatusModel $orderStatus)
|
||||
{
|
||||
$orderStatus
|
||||
->setCode(!$orderStatus->getProtectedStatus() ? $event->getCode() : $orderStatus->getCode())
|
||||
->setColor($event->getColor())
|
||||
// i18n
|
||||
->setLocale($event->getLocale())
|
||||
->setTitle($event->getTitle())
|
||||
->setDescription($event->getDescription())
|
||||
->setPostscriptum($event->getPostscriptum())
|
||||
->setChapo($event->getChapo());
|
||||
|
||||
if ($orderStatus->getId() === null) {
|
||||
$orderStatus->setPosition(
|
||||
OrderStatusQuery::create()->orderByPosition(Criteria::DESC)->findOne()->getPosition() + 1
|
||||
);
|
||||
}
|
||||
|
||||
$orderStatus->save();
|
||||
|
||||
$event->setOrderStatus($orderStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param UpdatePositionEvent $event
|
||||
* @param $eventName
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->genericUpdatePosition(OrderStatusQuery::create(), $event, $dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderStatusUpdateEvent $event
|
||||
* @return OrderStatusModel
|
||||
*/
|
||||
protected function getOrderStatus(OrderStatusUpdateEvent $event)
|
||||
{
|
||||
if (null === $orderStatus = OrderStatusQuery::create()->findOneById($event->getId())) {
|
||||
throw new \LogicException(
|
||||
"Order status not found"
|
||||
);
|
||||
}
|
||||
|
||||
return $orderStatus;
|
||||
}
|
||||
}
|
||||
293
core/lib/Thelia/Controller/Admin/OrderStatusController.php
Normal file
293
core/lib/Thelia/Controller/Admin/OrderStatusController.php
Normal file
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusCreateEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusDeleteEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Form\Definition\AdminForm;
|
||||
use Thelia\Form\OrderStatus\OrderStatusModificationForm;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Model\OrderStatus;
|
||||
|
||||
/**
|
||||
* Class OrderStatusController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.com>
|
||||
* @since 2.4
|
||||
*/
|
||||
class OrderStatusController extends AbstractCrudController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'orderstatus',
|
||||
'manual',
|
||||
'order',
|
||||
AdminResources::ORDER_STATUS,
|
||||
TheliaEvents::ORDER_STATUS_CREATE,
|
||||
TheliaEvents::ORDER_STATUS_UPDATE,
|
||||
TheliaEvents::ORDER_STATUS_DELETE,
|
||||
null,
|
||||
TheliaEvents::ORDER_STATUS_UPDATE_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return $this->createForm(AdminForm::ORDER_STATUS_CREATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the update form for this object
|
||||
*/
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return $this->createForm(AdminForm::ORDER_STATUS_MODIFICATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the update form for this object, before passing it to the update template
|
||||
*
|
||||
* @param OrderStatus $object
|
||||
* @return OrderStatusModificationForm $object
|
||||
*/
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = [
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'color' => $object->getColor(),
|
||||
'code' => $object->getCode()
|
||||
];
|
||||
|
||||
$form = $this->createForm(AdminForm::ORDER_STATUS_MODIFICATION, "form", $data);
|
||||
|
||||
// Setup the object form
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the creation event with the provided form data
|
||||
*
|
||||
* @param array $formData
|
||||
* @return OrderStatusCreateEvent
|
||||
*/
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$orderStatusCreateEvent = new OrderStatusCreateEvent();
|
||||
|
||||
$orderStatusCreateEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setTitle($formData['title'])
|
||||
->setCode($formData['code'])
|
||||
->setColor($formData['color'])
|
||||
;
|
||||
|
||||
return $orderStatusCreateEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the update event with the provided form data
|
||||
*
|
||||
* @param array $formData
|
||||
* @return OrderStatusUpdateEvent
|
||||
*/
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$orderStatusUpdateEvent = new OrderStatusUpdateEvent($formData['id']);
|
||||
|
||||
$orderStatusUpdateEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setTitle($formData['title'])
|
||||
->setChapo($formData['chapo'])
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
->setCode($formData['code'])
|
||||
->setColor($formData['color'])
|
||||
;
|
||||
|
||||
return $orderStatusUpdateEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the delete event with the provided form data
|
||||
*
|
||||
* @return OrderStatusDeleteEvent
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new OrderStatusDeleteEvent((int) $this->getRequest()->get('order_status_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param OrderStatusEvent $event
|
||||
* @return bool
|
||||
*/
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasOrderStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param $event \Thelia\Core\Event\OrderStatus\OrderStatusEvent
|
||||
*
|
||||
* @return null|OrderStatus
|
||||
*/
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->getOrderStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*
|
||||
* @return \Thelia\Model\OrderStatus
|
||||
*/
|
||||
protected function getExistingObject()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()
|
||||
->findOneById($this->getRequest()->get('order_status_id', 0));
|
||||
|
||||
if (null !== $orderStatus) {
|
||||
$orderStatus->setLocale($this->getCurrentEditionLocale());
|
||||
}
|
||||
|
||||
return $orderStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object label form the object event (name, title, etc.)
|
||||
*
|
||||
* @param OrderStatus $object
|
||||
*
|
||||
* @return string order status title
|
||||
*/
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object ID from the object
|
||||
*
|
||||
* @param OrderStatus $object
|
||||
*
|
||||
* @return int order status id
|
||||
*/
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the main list template
|
||||
*
|
||||
* @param string $currentOrder , if any, null otherwise.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
$this->getListOrderFromSession('orderstatus', 'order', 'manual');
|
||||
|
||||
return $this->render('order-status', [
|
||||
'order' => $currentOrder,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getEditionArguments()
|
||||
{
|
||||
return [
|
||||
'order_status_id' => $this->getRequest()->get('order_status_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('order-status-edit', $this->getEditionArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
return $this->generateRedirectFromRoute(
|
||||
'admin.order-status.update',
|
||||
[],
|
||||
$this->getEditionArguments()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
return $this->generateRedirectFromRoute('admin.order-status.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $positionChangeMode
|
||||
* @param $positionValue
|
||||
* @return UpdatePositionEvent|void
|
||||
*/
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('order_status_id', null),
|
||||
$positionChangeMode,
|
||||
$positionValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event \Thelia\Core\Event\UpdatePositionEvent
|
||||
* @return null|Response
|
||||
*/
|
||||
protected function performAdditionalUpdatePositionAction($event)
|
||||
{
|
||||
$folder = OrderStatusQuery::create()->findPk($event->getObjectId());
|
||||
|
||||
if ($folder != null) {
|
||||
return $this->generateRedirectFromRoute(
|
||||
'admin.order-status.default'
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\OrderStatus;
|
||||
|
||||
/**
|
||||
* Class OrderStatusCreateEvent
|
||||
* @package Thelia\Core\Event\OrderStatus
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
*/
|
||||
class OrderStatusCreateEvent extends OrderStatusEvent
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\OrderStatus;
|
||||
|
||||
/**
|
||||
* Class OrderStatusDeleteEvent
|
||||
* @package Thelia\Core\Event\OrderStatus
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
*/
|
||||
class OrderStatusDeleteEvent extends OrderStatusUpdateEvent
|
||||
{
|
||||
}
|
||||
221
core/lib/Thelia/Core/Event/OrderStatus/OrderStatusEvent.php
Normal file
221
core/lib/Thelia/Core/Event/OrderStatus/OrderStatusEvent.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\OrderStatus;
|
||||
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\OrderStatus;
|
||||
|
||||
/**
|
||||
* Class OrderStatusEvent
|
||||
* @package Thelia\Core\Event\OrderStatus
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
*/
|
||||
class OrderStatusEvent extends ActionEvent
|
||||
{
|
||||
/** @var string */
|
||||
protected $code;
|
||||
|
||||
/** @var string */
|
||||
protected $title;
|
||||
|
||||
/** @var string */
|
||||
protected $description;
|
||||
|
||||
/** @var string */
|
||||
protected $chapo;
|
||||
|
||||
/** @var string */
|
||||
protected $postscriptum;
|
||||
|
||||
/** @var string */
|
||||
protected $color;
|
||||
|
||||
/** @var string */
|
||||
protected $locale = 'en_US';
|
||||
|
||||
/** @var OrderStatus */
|
||||
protected $orderStatus;
|
||||
|
||||
/** @var int */
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $position
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setPosition($position)
|
||||
{
|
||||
$this->position = $position;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasOrderStatus()
|
||||
{
|
||||
return null !== $this->orderStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrderStatus
|
||||
*/
|
||||
public function getOrderStatus()
|
||||
{
|
||||
return $this->orderStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderStatus $orderStatus
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setOrderStatus($orderStatus)
|
||||
{
|
||||
$this->orderStatus = $orderStatus;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getColor()
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $color
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setColor($color)
|
||||
{
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getChapo()
|
||||
{
|
||||
return $this->chapo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $chapo
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setChapo($chapo)
|
||||
{
|
||||
$this->chapo = $chapo;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPostscriptum()
|
||||
{
|
||||
return $this->postscriptum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $postscriptum
|
||||
* @return OrderStatusEvent
|
||||
*/
|
||||
public function setPostscriptum($postscriptum)
|
||||
{
|
||||
$this->postscriptum = $postscriptum;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\OrderStatus;
|
||||
|
||||
/**
|
||||
* Class OrderStatusUpdateEvent
|
||||
* @package Thelia\Core\Event\OrderStatus
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
*/
|
||||
class OrderStatusUpdateEvent extends OrderStatusEvent
|
||||
{
|
||||
/** @var int */
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* OrderStatusUpdateEvent constructor.
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return OrderStatusUpdateEvent
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Template;
|
||||
|
||||
class TemplateDuplicateEvent extends TemplateEvent
|
||||
{
|
||||
/** @var int */
|
||||
protected $sourceTemplateId;
|
||||
|
||||
/** @var string */
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* TemplateCreateEvent constructor.
|
||||
* @param int $sourceTemplateId
|
||||
*/
|
||||
public function __construct($sourceTemplateId, $locale)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->sourceTemplateId = $sourceTemplateId;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSourceTemplateId()
|
||||
{
|
||||
return $this->sourceTemplateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
}
|
||||
67
core/lib/Thelia/Core/Event/ViewCheckEvent.php
Normal file
67
core/lib/Thelia/Core/Event/ViewCheckEvent.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
class ViewCheckEvent extends ActionEvent
|
||||
{
|
||||
protected $view;
|
||||
|
||||
protected $view_id;
|
||||
|
||||
public function __construct($view, $view_id)
|
||||
{
|
||||
$this->view = $view;
|
||||
|
||||
$this->view_id = $view_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getView()
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $view
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setView($view)
|
||||
{
|
||||
$this->view = $view;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getViewId()
|
||||
{
|
||||
return $this->view_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $view_id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setViewId($view_id)
|
||||
{
|
||||
$this->view_id = $view_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Security\Exception;
|
||||
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
/**
|
||||
* Class CustomerNotConfirmedException
|
||||
* @package Thelia\Core\Security\Exception
|
||||
* @author Baixas Alban <abaixas@openstudio.fr>
|
||||
*/
|
||||
class CustomerNotConfirmedException extends AuthenticationException
|
||||
{
|
||||
/** @var Customer */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $user
|
||||
* @return $this
|
||||
*/
|
||||
public function setUser(Customer $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Element;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
trait StandardI18nFieldsSearchTrait
|
||||
{
|
||||
protected static $standardI18nSearchFields = [
|
||||
"title",
|
||||
"chapo",
|
||||
"description",
|
||||
"postscriptum"
|
||||
];
|
||||
|
||||
protected function getStandardI18nSearchFields()
|
||||
{
|
||||
return self::$standardI18nSearchFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModelCriteria $search
|
||||
* @param $searchTerm
|
||||
* @param $searchCriteria
|
||||
*/
|
||||
protected function addStandardI18nSearch(&$search, $searchTerm, $searchCriteria)
|
||||
{
|
||||
foreach (self::$standardI18nSearchFields as $index => $searchInElement) {
|
||||
if ($index > 0) {
|
||||
$search->_or();
|
||||
}
|
||||
|
||||
$this->addSearchInI18nColumn($search, strtoupper($searchInElement), $searchCriteria, $searchTerm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the search clause for an I18N column, taking care of the back/front context, as default_locale_i18n is
|
||||
* not defined in the backEnd I18N context.
|
||||
*
|
||||
* @param ModelCriteria $search
|
||||
* @param string $columnName the column to search into, such as TITLE
|
||||
* @param string $searchCriteria the search criteria, such as Criterial::LIKE, Criteria::EQUAL, etc.
|
||||
* @param string $searchTerm the searched term
|
||||
*/
|
||||
public abstract function addSearchInI18nColumn($search, $columnName, $searchCriteria, $searchTerm);
|
||||
}
|
||||
41
core/lib/Thelia/Form/MessageSendSampleForm.php
Normal file
41
core/lib/Thelia/Form/MessageSendSampleForm.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class MessageSendSampleForm extends BaseForm
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_message_send_sample";
|
||||
}
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
"recipient_email",
|
||||
"email",
|
||||
[
|
||||
"constraints" => array(new NotBlank()),
|
||||
"label" => Translator::getInstance()->trans('Send test e-mail to:'),
|
||||
"attr" => [
|
||||
'placeholder' => Translator::getInstance()->trans('Recipient e-mail address')
|
||||
]
|
||||
]
|
||||
);
|
||||
;
|
||||
}
|
||||
}
|
||||
157
core/lib/Thelia/Form/OrderStatus/OrderStatusCreationForm.php
Normal file
157
core/lib/Thelia/Form/OrderStatus/OrderStatusCreationForm.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Form\OrderStatus;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Form\StandardDescriptionFieldsTrait;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
|
||||
/**
|
||||
* Class OrderStatusCreationForm
|
||||
* @package Thelia\Form\OrderStatus
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
* @since 2.4
|
||||
*/
|
||||
class OrderStatusCreationForm extends BaseForm
|
||||
{
|
||||
use StandardDescriptionFieldsTrait;
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
'title',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [ new NotBlank() ],
|
||||
'required' => true,
|
||||
'label' => Translator::getInstance()->trans('Order status name'),
|
||||
'label_attr' => [
|
||||
'for' => 'title',
|
||||
'help' => Translator::getInstance()->trans(
|
||||
'Enter here the order status name in the default language (%title%)',
|
||||
[ '%title%' => Lang::getDefaultLanguage()->getTitle()]
|
||||
),
|
||||
],
|
||||
'attr' => [
|
||||
'placeholder' => Translator::getInstance()->trans('The order status name or title'),
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'code',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [
|
||||
new Callback([
|
||||
'methods' => [
|
||||
[$this, 'checkUniqueCode'],
|
||||
[$this, 'checkFormatCode'],
|
||||
[$this, 'checkIsRequiredCode']
|
||||
]
|
||||
])
|
||||
],
|
||||
'required' => true,
|
||||
'label' => Translator::getInstance()->trans('Order status code'),
|
||||
'label_attr' => [
|
||||
'for' => 'title',
|
||||
'help' => Translator::getInstance()->trans('Enter here the order status code'),
|
||||
],
|
||||
'attr' => [
|
||||
'placeholder' => Translator::getInstance()->trans('The order status code'),
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'color',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new Callback([
|
||||
'methods' => [[$this, 'checkColor']]
|
||||
])
|
||||
],
|
||||
'required' => false,
|
||||
'label' => Translator::getInstance()->trans('Order status color'),
|
||||
'label_attr' => [
|
||||
'for' => 'title',
|
||||
'help' => Translator::getInstance()->trans('Choice a color for this order status code'),
|
||||
],
|
||||
'attr' => [
|
||||
'placeholder' => Translator::getInstance()->trans('#000000'),
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$this->addStandardDescFields(['title', 'description', 'chapo', 'postscriptum']);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_order_status_creation';
|
||||
}
|
||||
|
||||
public function checkColor($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!preg_match("/^#[0-9a-fA-F]{6}$/", $value)) {
|
||||
$context->addViolation(
|
||||
Translator::getInstance()->trans("This is not a hexadecimal color.")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkUniqueCode($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$query = OrderStatusQuery::create()
|
||||
->filterByCode($value);
|
||||
|
||||
if ($this->form->has('id')) {
|
||||
$query->filterById($this->form->get('id')->getData(), Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
if ($query->findOne()) {
|
||||
$context->addViolation(
|
||||
Translator::getInstance()->trans("This code is already used.")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkFormatCode($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!empty($value) && !preg_match('/^\w+$/', $value)) {
|
||||
$context->addViolation(
|
||||
Translator::getInstance()->trans("This is not a valid code.")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkIsRequiredCode($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if ($this->form->has('id')) {
|
||||
if (null !== $orderStatus = OrderStatusQuery::create()->findOneById($this->form->get('id')->getData())) {
|
||||
if (!$orderStatus->getProtectedStatus() && empty($this->form->get('code')->getData())) {
|
||||
$context->addViolation(
|
||||
Translator::getInstance()->trans("This value should not be blank.")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Form\OrderStatus;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
|
||||
/**
|
||||
* Class OrderStatusModificationForm
|
||||
* @package Thelia\Form\OrderStatus
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
* @since 2.4
|
||||
*/
|
||||
class OrderStatusModificationForm extends OrderStatusCreationForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder->add("id", "hidden", [
|
||||
'required' => true,
|
||||
"constraints" => [
|
||||
new GreaterThan(['value' => 0])
|
||||
]
|
||||
]);
|
||||
|
||||
parent::buildForm();
|
||||
|
||||
$this->addStandardDescFields();
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_order_status_modification';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user