<?php
namespace App\EventListener\Custom\VinoLevice;
use App\Entity\Central\Client\Client;
use App\Entity\Client\Store\StoreHeader;
use App\EventListener\GenericEvent;
use App\Model\ShellExec;
use App\Service\ShellExecManager;
use App\Utils\ClientUtils;
use VinoLevice\Model\CustomerType;
class StoreHeaderPostListener
{
private ShellExecManager $shellExecManager;
public function __construct(ShellExecManager $shellExecManager)
{
$this->shellExecManager = $shellExecManager;
}
public function postCreate(GenericEvent $genericEvent)
{
$this->isClient($genericEvent->getAppManager()->getClient());
$entity = $genericEvent->getSubject();
if (!$entity instanceof StoreHeader || $entity->getCustomer() === null) {
return;
}
$customer = $entity->getCustomer();
$customerType = $customer->getType();
if (!in_array($customerType, [CustomerType::TYPE_BOLT, CustomerType::TYPE_WOLT])) {
return;
}
$shellExec = new ShellExec('vinolevice:header_change_price', $entity->getId() . ' --kernel=vinolevice');
$this->shellExecManager->runShellExec($shellExec, true);
}
private function isClient($client)
{
if (!$client instanceof Client || $client->getCode() !== ClientUtils::VINOLEVICE) {
throw new \Exception('Bad client');
}
}
}