src/App/EventListener/Custom/VinoLevice/StoreHeaderPostListener.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\EventListener\Custom\VinoLevice;
  3. use App\Entity\Central\Client\Client;
  4. use App\Entity\Client\Store\StoreHeader;
  5. use App\EventListener\GenericEvent;
  6. use App\Model\ShellExec;
  7. use App\Service\ShellExecManager;
  8. use App\Utils\ClientUtils;
  9. use VinoLevice\Model\CustomerType;
  10. class StoreHeaderPostListener
  11. {
  12.     private ShellExecManager $shellExecManager;
  13.     public function __construct(ShellExecManager $shellExecManager)
  14.     {
  15.         $this->shellExecManager $shellExecManager;
  16.     }
  17.     public function postCreate(GenericEvent $genericEvent)
  18.     {
  19.         $this->isClient($genericEvent->getAppManager()->getClient());
  20.         $entity $genericEvent->getSubject();
  21.         if (!$entity instanceof StoreHeader || $entity->getCustomer() === null) {
  22.             return;
  23.         }
  24.         $customer $entity->getCustomer();
  25.         $customerType $customer->getType();
  26.         if (!in_array($customerType, [CustomerType::TYPE_BOLTCustomerType::TYPE_WOLT])) {
  27.             return;
  28.         }
  29.         $shellExec = new ShellExec('vinolevice:header_change_price'$entity->getId() . ' --kernel=vinolevice');
  30.         $this->shellExecManager->runShellExec($shellExectrue);
  31.     }
  32.     private function isClient($client)
  33.     {
  34.         if (!$client instanceof Client || $client->getCode() !== ClientUtils::VINOLEVICE) {
  35.             throw new \Exception('Bad client');
  36.         }
  37.     }
  38. }