<?php
namespace App\EventListener\Client\Supplier;
use App\Entity\Client\Supplier\SupplierOrder;
use App\EventListener\GenericEvent;
use App\Service\Central\Supplier\SupplierManager;
class SupplierOrderListener
{
private SupplierManager $supplierManager;
public function __construct(SupplierManager $supplierManager)
{
$this->supplierManager = $supplierManager;
}
public function supplierOrderProducts(GenericEvent $genericEvent)
{
$supplierOrder = $genericEvent->getSubject();
if (!$supplierOrder instanceof SupplierOrder) {
return;
}
$supplier = $supplierOrder->getSupplier();
foreach ($supplierOrder->getSupplierOrderProducts() as $supplierOrderProduct) {
$this->supplierManager->findOrCreateSupplierProduct($supplier, $supplierOrderProduct->getProduct());
}
}
}