ElasticsearchIndexerLanguageCriteriaEvent example


class ElasticsearchIndexerLanguageCriteriaEventTest extends TestCase
{
    public function testEvent(): void
    {
        $criteria = new Criteria();
        $context = Context::createDefaultContext();

        $event = new ElasticsearchIndexerLanguageCriteriaEvent($criteria$context);
        static::assertSame($criteria$event->getCriteria());
        static::assertSame($context$event->getContext());
    }
}

    public function __construct(private readonly EntityRepository $languageRepositoryprivate readonly EventDispatcherInterface $eventDispatcher)
    {
    }

    public function getLanguages(Context $context): LanguageCollection
    {
        $criteria = new Criteria();
        $criteria->addFilter(new NandFilter([new EqualsFilter('salesChannels.id', null)]));
        $criteria->addSorting(new FieldSorting('id'));

        $this->eventDispatcher->dispatch(new ElasticsearchIndexerLanguageCriteriaEvent($criteria$context));

        /** @var LanguageCollection $languages */
        $languages = $this->languageRepository
            ->search($criteria$context)
            ->getEntities();

        return $languages;
    }
}
Home | Imprint | This part of the site doesn't use cookies.