vendor/thelia/core/lib/Thelia/Action/Tax.php line 27

Open in your IDE?
  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.     /**
  21.      * @param $eventName
  22.      */
  23.     public function create(TaxEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  24.     {
  25.         $tax = new TaxModel();
  26.         $tax
  27.             ->setRequirements($event->getRequirements())
  28.             ->setType($event->getType())
  29.             ->setLocale($event->getLocale())
  30.             ->setTitle($event->getTitle())
  31.             ->setDescription($event->getDescription())
  32.         ;
  33.         $tax->save();
  34.         $event->setTax($tax);
  35.     }
  36.     /**
  37.      * @param $eventName
  38.      */
  39.     public function update(TaxEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  40.     {
  41.         if (null !== $tax TaxQuery::create()->findPk($event->getId())) {
  42.             $tax
  43.                 ->setRequirements($event->getRequirements())
  44.                 ->setType($event->getType())
  45.                 ->setLocale($event->getLocale())
  46.                 ->setTitle($event->getTitle())
  47.                 ->setDescription($event->getDescription())
  48.             ;
  49.             $tax->save();
  50.             $event->setTax($tax);
  51.         }
  52.     }
  53.     public function delete(TaxEvent $event): void
  54.     {
  55.         if (null !== $tax TaxQuery::create()->findPk($event->getId())) {
  56.             $tax
  57.                 ->delete()
  58.             ;
  59.             $event->setTax($tax);
  60.         }
  61.     }
  62.     /**
  63.      * {@inheritDoc}
  64.      */
  65.     public static function getSubscribedEvents()
  66.     {
  67.         return [
  68.             TheliaEvents::TAX_CREATE => ['create'128],
  69.             TheliaEvents::TAX_UPDATE => ['update'128],
  70.             TheliaEvents::TAX_DELETE => ['delete'128],
  71.         ];
  72.     }
  73. }