custom/plugins/CrayssnLabsConfigurator/src/Storefront/Subscriber/OrderStateSubscriber.php line 36

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace CrayssnLabsConfigurator\Storefront\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
  5. /**
  6.  * Class OrderStateSubscriber
  7.  *
  8.  * @package   CrayssnLabsConfigurator\Storefront\Subscriber
  9.  *
  10.  * @author    Sebastian Ludwig <dev@cl.team>
  11.  * @copyright Copyright (c) 2022, CrayssnLabs Ludwig Wiegler GbR
  12.  */
  13. class OrderStateSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * Function getSubscribedEvents
  17.      *
  18.      * @return string[]
  19.      */
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         // Return the events to listen to as array like this:  <event to listen to> => <method to execute>
  23.         return [
  24.             'state_enter.order_transaction.state.paid' => 'onOrderStateChangedPaid'
  25.         ];
  26.     }
  27.     /**
  28.      * Function onOrderStateChanged
  29.      *
  30.      * @param \Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent $event
  31.      */
  32.     public function onOrderStateChangedPaid(OrderStateMachineStateChangeEvent $event)
  33.     {
  34.         $logDirectory __DIR__ '/../../../log';
  35.         if(!is_dir($logDirectory))
  36.         {
  37.             mkdir($logDirectory);
  38.         }
  39.         $logDirectory .= '/command';
  40.         if(!is_dir($logDirectory))
  41.         {
  42.             mkdir($logDirectory);
  43.         }
  44.         $logFile $logDirectory '/' $event->getOrder()->getOrderNumber() . '.log';
  45.         $command __DIR__ '/../../../../../../bin/console cl-configurator:create-print-data ' $event->getOrder()->getId() . " 2>&1 ";
  46.         exec('nohup ' $command ' >> ' $logFile ' 2>&1 & echo $!');
  47.     }
  48. }