<?php
namespace Boldr\Shop\ReceiptPrinterMultishopBundle\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PrinterEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
QueueReceiptEvent::class => ['onReceiptQueued']
];
}
public function onReceiptQueued(QueueReceiptEvent $event)
{
$shop = $this->em->getRepository(OrderShop::class)->find($event->getOrder())?->getShop();
if ($shop === null)
{
return;
}
$printerShops = $this->em->getRepository(PrinterShop::class)->findBy([
'printer' => $event->getPrinter(),
'shop' => $shop
]);
if (count($printerShops) === 0)
{
$event->stopPropagation();
}
}
}