<?php declare(strict_types=1);
namespace Swag\EnterpriseSearch\Manufacturer;
use Shopware\Core\Content\Product\Aggregate\ProductManufacturer\ProductManufacturerDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Shopware\Elasticsearch\Framework\Indexing\ElasticsearchIndexer;
use Swag\EnterpriseSearch\Common\VersionHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ManufacturerUpdater implements EventSubscriberInterface
{
/**
* @var ElasticsearchIndexer
*/
private $indexer;
/**
* @var EntityDefinition
*/
private $definition;
public function __construct(ElasticsearchIndexer $indexer, EntityDefinition $definition)
{
$this->indexer = $indexer;
$this->definition = $definition;
}
public static function getSubscribedEvents(): array
{
return [
ProductManufacturerDefinition::ENTITY_NAME . '.written' => 'update',
];
}
public function update(EntityWrittenEvent $event): void
{
if (VersionHelper::isShopware64X()) {
$this->indexer->updateIds(
$this->definition,
$event->getIds()
);
return;
}
$this->indexer->sendIndexingMessages(
$this->definition,
$event->getIds()
);
}
}