【发布时间】:2021-01-11 09:05:54
【问题描述】:
我想在我的插件中使用Shopware\Core\Content\Category\Event\CategoryIndexerEvent.php。
有人知道如何使用这个活动吗?
【问题讨论】:
标签: shopware6
我想在我的插件中使用Shopware\Core\Content\Category\Event\CategoryIndexerEvent.php。
有人知道如何使用这个活动吗?
【问题讨论】:
标签: shopware6
您需要创建一个EventSubscriber。对于您提到的事件,这看起来像这样。
首先你需要一个事件订阅者:
<?php declare(strict_types=1);
namespace MyPlugin;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Content\Category\CategoryEvents;
use Shopware\Core\Content\Category\Event\CategoryIndexerEvent;
class MySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
CategoryEvents::CATEGORY_INDEXER_EVENT => 'doMyStuff'
];
}
public function doMyStuff(CategoryIndexerEvent $event): void
{
$indexedCategories = $event->getIds();
// Do stuff
}
}
其次,您需要在 DIC 中注册此订阅者(plugin/src/Resources/config/services.xml):
<!-- ... -->
<service id="MyPlugin\MySubscriber">
<tag name="kernel.event_subscriber"/>
</service>
<!-- ... -->
【讨论】: