<?php declare(strict_types=1);
namespace CrayssnLabsConfigurator\Storefront\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
/**
* Class OrderStateSubscriber
*
* @package CrayssnLabsConfigurator\Storefront\Subscriber
*
* @author Sebastian Ludwig <dev@cl.team>
* @copyright Copyright (c) 2022, CrayssnLabs Ludwig Wiegler GbR
*/
class OrderStateSubscriber implements EventSubscriberInterface
{
/**
* Function getSubscribedEvents
*
* @return string[]
*/
public static function getSubscribedEvents(): array
{
// Return the events to listen to as array like this: <event to listen to> => <method to execute>
return [
'state_enter.order_transaction.state.paid' => 'onOrderStateChangedPaid'
];
}
/**
* Function onOrderStateChanged
*
* @param \Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent $event
*/
public function onOrderStateChangedPaid(OrderStateMachineStateChangeEvent $event)
{
$logDirectory = __DIR__ . '/../../../log';
if(!is_dir($logDirectory))
{
mkdir($logDirectory);
}
$logDirectory .= '/command';
if(!is_dir($logDirectory))
{
mkdir($logDirectory);
}
$logFile = $logDirectory . '/' . $event->getOrder()->getOrderNumber() . '.log';
$command = __DIR__ . '/../../../../../../bin/console cl-configurator:create-print-data ' . $event->getOrder()->getId() . " 2>&1 ";
exec('nohup ' . $command . ' >> ' . $logFile . ' 2>&1 & echo $!');
}
}