<?php
declare(strict_types=1);
namespace CnhProductExporter\Subscriber;
use CnhProductExporter\Services\API\TransferService;
use Shopware\Core\Content\Product\ProductEvents;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ProductSubscriber implements EventSubscriberInterface
{
/**
* @var TransferService
*/
private TransferService $transferService;
public function __construct(TransferService $transferService)
{
$this->transferService = $transferService;
}
public static function getSubscribedEvents(): array
{
return [
ProductEvents::PRODUCT_WRITTEN_EVENT => 'onProductWrite'
];
}
public function onProductWrite(EntityWrittenEvent $event)
{
foreach ($event->getIds() as $productId) {
$this->transferService->transferProduct($productId);
}
}
}