Initial commit

This commit is contained in:
2020-01-27 08:56:08 +01:00
commit b7525048d6
27129 changed files with 3409855 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
<?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 WithdrawalInStore\Action;
use WithdrawalInStore\Event\WithdrawalInStoreDeleteEvent;
use WithdrawalInStore\Event\WithdrawalInStoreEvents;
use WithdrawalInStore\Event\WithdrawalInStoreUpdateEvent;
use WithdrawalInStore\Model\WithdrawalInStore;
use WithdrawalInStore\Model\WithdrawalInStoreQuery;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Action\BaseAction;
use Thelia\Model\Base\AreaQuery;
/**
*
* WithdrawalInStoreAction class where all actions are managed
*
* Class WithdrawalInStoreAction
* @package WithdrawalInStore\Action
* @author Michaël Espeche <mespeche@openstudio.fr>
*/
class WithdrawalInStoreAction extends BaseAction implements EventSubscriberInterface
{
public function createRule(WithdrawalInStoreEvents $event)
{
$rule = new WithdrawalInStore();
$WithdrawalInStoreArea = WithdrawalInStoreQuery::create()->findOneByAreaId($event->getArea());
if (null === $WithdrawalInStoreArea) {
$rule
->setAmount($event->getAmount())
->setAreaId($event->getArea())
->save();
} else {
$area = AreaQuery::create()->findOneById($event->getArea());
throw new \Exception(sprintf("A Withdrawal In Store rule already exists for the '%s' area", $area->getName()));
}
}
public function updateRule(WithdrawalInStoreUpdateEvent $event)
{
$areaId = $event->getArea();
$WithdrawalInStoreArea = WithdrawalInStoreQuery::create()->findOneByAreaId($areaId);
if (null === $WithdrawalInStoreArea || $WithdrawalInStoreArea->getAmount() !== $event->getAmount() ) {
$id = $event->getRuleId();
if (null !== $WithdrawalInStore = WithdrawalInStoreQuery::create()->findPk($id)) {
$WithdrawalInStore->setDispatcher($event->getDispatcher());
$WithdrawalInStore
->setAreaId($event->getArea())
->setAmount($event->getAmount())
->save();
$event->setRule($WithdrawalInStore);
}
} else {
$area = AreaQuery::create()->findOneById($areaId);
throw new \Exception(sprintf("A Withdrawal In Store rule already exists for the '%s' area", $area->getName()));
}
}
public function deleteRule(WithdrawalInStoreDeleteEvent $event)
{
$id = $event->getWithdrawalInStoreId();
if (null !== $WithdrawalInStore = WithdrawalInStoreQuery::create()->findPk($id)) {
$WithdrawalInStore->setDispatcher($event->getDispatcher())
->delete();
}
}
/**
* 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(
WithdrawalInStoreEvents::WITHDRAWAL_IN_STORE_RULE_CREATE => array('createRule', 128),
WithdrawalInStoreUpdateEvent::WITHDRAWAL_IN_STORE_RULE_UPDATE => array('updateRule', 128),
WithdrawalInStoreDeleteEvent::WITHDRAWAL_IN_STORE_RULE_DELETE => array('deleteRule', 128)
);
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<dwsync>
<file name="WithdrawalInStoreAction.php" server="51.254.220.106//web/" local="131379675097031250" remote="131383879200000000" />
<file name="WithdrawalInStoreAction.php" server="37.187.178.154//web/" local="131351945400000000" remote="131378968800000000" />
</dwsync>