Search code examples
phpeventsshopware

Subscribe to Event which does not have an event name


I try to subscribe to the Event in Shopware 6.3.5

\Shopware\Core\Content\ImportExport\Event\ImportExportBeforeImportRecordEvent

The class does not define an EVENT_NAME, which I seem to need according to the docs: https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/listening-to-events

public static function getSubscribedEvents(): array
{
    // Return the events to listen to as array like this:  <event to listen to> => <method to execute>
    return [
        ProductEvents::PRODUCT_LOADED_EVENT => 'onProductsLoaded'
    ];
}

What do I enter as array key for the subscribed events now?


Solution

  • It's simple - use the class name:

    use Shopware\Core\Content\ImportExport\Event\ImportExportBeforeImportRecordEvent;
    
    ...
    
    public static function getSubscribedEvents(): array
    {
        return [
            ImportExportBeforeImportRecordEvent::class 
                => 'onImportExportBeforeImportRecord'
        ];
    }