local/modules/TracabilitePP/Actions/Tracabilite.php line 60

  1. <?php
  2. /*************************************************************************************/
  3. /*      This file is part of the Thelia package.                                     */
  4. /*                                                                                   */
  5. /*      Copyright (c) OpenStudio                                                     */
  6. /*      email : dev@thelia.net                                                       */
  7. /*      web : http://www.thelia.net                                                  */
  8. /*                                                                                   */
  9. /*      For the full copyright and license information, please view the LICENSE.txt  */
  10. /*      file that was distributed with this source code.                             */
  11. /*************************************************************************************/
  12. namespace TracabilitePP\Actions;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use TracabilitePP\Model\TracabiliteQuery;
  16. use TracabilitePP\Events\TracabilitePPCreateEvent;
  17. use TracabilitePP\Events\TracabilitePPUpdateEvent;
  18. use TracabilitePP\Model\Tracabilite as ModelTracabilite;
  19. use Thelia\Log\Tlog;
  20. use TracabilitePP\Events\TracabilitePPEvents;
  21. use TracabilitePP\Events\TracabilitePPDeleteEvent;
  22. /**
  23.  * Class Tracabilite
  24.  *
  25.  * @package TracabilitePP\Actions
  26.  * @author  François  Carfantan <f.carfantan@orange.fr>
  27.  */
  28. class Tracabilite implements EventSubscriberInterface
  29. {
  30.     public function create(TracabilitePPCreateEvent $event$eventNameEventDispatcherInterface $dispatcher)
  31.     {
  32.         $tracabilite = new ModelTracabilite();
  33.         $tracabilite
  34.             ->setLotCode($event->getLotCode())
  35.             ->setInitialStock($event->getInitialStock())
  36.             ->setDirectStock($event->getDirectStock())
  37.             ->setOnlineStock($event->getOnlineStock())
  38.             ->setDirectSaleCount(0)
  39.             ->setOnlineSaleCount(0)
  40.             ->setStartDate($event->getstartDate())
  41.             ->setProductId($event->getProduct())
  42.             ->save();
  43.         $event->stopPropagation();
  44.         $event->setTracabilite($tracabilite);
  45.        
  46.     }
  47.     /**
  48.      * process update tracabilite
  49.      *
  50.      * @param TracabilitePPUpdateEvent $event
  51.      * @param $eventName
  52.      * @param EventDispatcherInterface $dispatcher
  53.      */
  54.     public function update(TracabilitePPUpdateEvent $event)
  55.     {
  56.         if (null !== $tracabilite TracabiliteQuery::create()->findPk($event->getTracabiliteId())) {
  57.             $tracabilite
  58.                 ->setDirectSaleCount($event->getDirectSaleCount())
  59.                 ->setDirectStock($event->getDirectStock())
  60.                 ->setOnlineStock($event->getOnlineStock())
  61.                 ->setEndDate($event->getEndDate())
  62.                 ->save();
  63.             $event->setTracabilite($tracabilite);
  64.         }
  65.     }
  66.     public function delete(TracabilitePPDeleteEvent $event)
  67.     {
  68.         if (null !== $tracabilite TracabiliteQuery::create()->findPk($event->getTracabiliteID())) {
  69.             $tracabilite->delete();
  70.         }
  71.     }
  72.     /**
  73.      * {@inheritdoc}
  74.      */
  75.     public static function getSubscribedEvents()
  76.     {
  77.         return array(
  78.             TracabilitePPEvents::TRACABILITE_CREATE => array('create'128),
  79.             TracabilitePPEvents::TRACABILITE_UPDATE => array('update'128),
  80.             TracabilitePPEvents::TRACABILITE_DELETE => array('delete'128)
  81.         );
  82.     }
  83. }