core/lib/Thelia/Action/Tax.php line 42

  1. <?php
  2. /*
  3.  * This file is part of the Thelia package.
  4.  * http://www.thelia.net
  5.  *
  6.  * (c) OpenStudio <info@thelia.net>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Thelia\Action;
  12. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Thelia\Core\Event\Tax\TaxEvent;
  15. use Thelia\Core\Event\TheliaEvents;
  16. use Thelia\Model\Tax as TaxModel;
  17. use Thelia\Model\TaxQuery;
  18. class Tax extends BaseAction implements EventSubscriberInterface
  19. {
  20.     public function create(TaxEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  21.     {
  22.         $tax = new TaxModel();
  23.         $tax
  24.             ->setRequirements($event->getRequirements())
  25.             ->setType($event->getType())
  26.             ->setLocale($event->getLocale())
  27.             ->setTitle($event->getTitle())
  28.             ->setDescription($event->getDescription())
  29.         ;
  30.         $tax->save();
  31.         $event->setTax($tax);
  32.     }
  33.     public function update(TaxEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  34.     {
  35.         if (null !== $tax TaxQuery::create()->findPk($event->getId())) {
  36.             $tax
  37.                 ->setRequirements($event->getRequirements())
  38.                 ->setType($event->getType())
  39.                 ->setLocale($event->getLocale())
  40.                 ->setTitle($event->getTitle())
  41.                 ->setDescription($event->getDescription())
  42.             ;
  43.             $tax->save();
  44.             $event->setTax($tax);
  45.         }
  46.     }
  47.     public function delete(TaxEvent $event): void
  48.     {
  49.         if (null !== $tax TaxQuery::create()->findPk($event->getId())) {
  50.             $tax
  51.                 ->delete()
  52.             ;
  53.             $event->setTax($tax);
  54.         }
  55.     }
  56.     /**
  57.      * {@inheritDoc}
  58.      */
  59.     public static function getSubscribedEvents()
  60.     {
  61.         return [
  62.             TheliaEvents::TAX_CREATE => ['create'128],
  63.             TheliaEvents::TAX_UPDATE => ['update'128],
  64.             TheliaEvents::TAX_DELETE => ['delete'128],
  65.         ];
  66.     }
  67. }