local/modules/TracabilitePP/Actions/Tracabilite.php line 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 TracabilitePP\Actions;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use TracabilitePP\Model\TracabiliteQuery;
use TracabilitePP\Events\TracabilitePPCreateEvent;
use TracabilitePP\Events\TracabilitePPUpdateEvent;
use TracabilitePP\Model\Tracabilite as ModelTracabilite;
use Thelia\Log\Tlog;
use TracabilitePP\Events\TracabilitePPEvents;
use TracabilitePP\Events\TracabilitePPDeleteEvent;
/**
* Class Tracabilite
*
* @package TracabilitePP\Actions
* @author François Carfantan <f.carfantan@orange.fr>
*/
class Tracabilite implements EventSubscriberInterface
{
public function create(TracabilitePPCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$tracabilite = new ModelTracabilite();
$tracabilite
->setLotCode($event->getLotCode())
->setInitialStock($event->getInitialStock())
->setDirectStock($event->getDirectStock())
->setOnlineStock($event->getOnlineStock())
->setDirectSaleCount(0)
->setOnlineSaleCount(0)
->setStartDate($event->getstartDate())
->setProductId($event->getProduct())
->save();
$event->stopPropagation();
$event->setTracabilite($tracabilite);
}
/**
* process update tracabilite
*
* @param TracabilitePPUpdateEvent $event
* @param $eventName
* @param EventDispatcherInterface $dispatcher
*/
public function update(TracabilitePPUpdateEvent $event)
{
if (null !== $tracabilite = TracabiliteQuery::create()->findPk($event->getTracabiliteId())) {
$tracabilite
->setDirectSaleCount($event->getDirectSaleCount())
->setDirectStock($event->getDirectStock())
->setOnlineStock($event->getOnlineStock())
->setEndDate($event->getEndDate())
->save();
$event->setTracabilite($tracabilite);
}
}
public function delete(TracabilitePPDeleteEvent $event)
{
if (null !== $tracabilite = TracabiliteQuery::create()->findPk($event->getTracabiliteID())) {
$tracabilite->delete();
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(
TracabilitePPEvents::TRACABILITE_CREATE => array('create', 128),
TracabilitePPEvents::TRACABILITE_UPDATE => array('update', 128),
TracabilitePPEvents::TRACABILITE_DELETE => array('delete', 128)
);
}
}