1
votes

I've created a custom plugin SwagStartup in Shopware, and it works by calling an url like "shopware.project/myDemo".

Then I tried to define/use event subscriber in this plugin, following is the code:

<?php
namespace SwagStartup\Subscriber;
use Enlight\Event\SubscriberInterface;

class RoutingSubscriber implements SubscriberInterface
{
    public static function getSubscribedEvents(){
        return ['Enlight_Controller_Action_PreDispatch' => 'onPreDispatch'];
    }
    public function onPreDispatch(\Enlight_Event_EventArgs $args){
        die('here!');
    }
}

And the XML file: Resources/services.xml:

<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
        <service id="swag_startup.subscriber.routing_subscriber"
                 class="SwagStartup\Subscriber\RoutingSubscriber">
            <tag name="shopware.event_subscriber"/>
        </service>
    </services>
</container>

When I called the url like before, I expected to see the output from the die() function, cause I thought the event Enlight_Controller_Action_PreDispatch should have been caught by the subscriber and the funciton onPreDispatch() should have been called - but it was not the case.

What's wrong? Can someone tell me?

2
Looks fine on first glance. Did you clear the cache? Is the plugin installed and active?FloydThreepwood

2 Answers

0
votes

I tried the same in a testplugin and it works fine: https://github.com/mnaczenski/SubscriberTest

It seems that your subscriber is not recognised. Which shopware version do you use?

0
votes

Late reply but issue still valid with SW 6.4

What I tried to do (And worked) was

  1. remove the class from the subscriber service. Just leave the id
  2. moved the <tag above the arguments