# Auf aktives Plugin prüfen

**URL:** <https://forum.shopware.com/t/auf-aktives-plugin-prufen/65671>\
**Category:** Programmierung\
**Created:** [22. März 2020 um 12:15 UTC](https://forum.shopware.com/t/auf-aktives-plugin-prufen/65671 "2020-03-22T12:15:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdsw](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mdsw](https://forum.shopware.com/u/mdsw)\
**Post date:** [22. März 2020 um 12:15 UTC](https://forum.shopware.com/t/auf-aktives-plugin-prufen/65671/1 "2020-03-22T12:15:14Z")

</div>

Hallo,&nbsp;

ich habe zwei Wege gefunden, in einem Subscriber zu prüfen, ob ein Plugin aktiv ist oder nicht. Kann mir jemand sagen, welche Lösung die bessere ist und wenn ja, warum?

&nbsp;

```
/**
     * @param EventArgs $args
     * @throws \Exception
     */
    public function onFrontendPostDispatch(EventArgs $args)
    {

        /** @var \Enlight_Controller_Action $controller */
        $controller = $args->get('subject');
        
        $pluginManager = $controller->get('shopware_plugininstaller.plugin_manager');
        $pluginName = "NameDesPlugins";

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);

            if ($plugin->getActive()) {
                $view->assign($pluginName, true);
            }
        } catch (\Exception $e) {}

        /* ODER SO */

        $pluginInstalled = Shopware()->Models()->getRepository(\Shopware\Models\Plugin\Plugin::class)->findOneBy(['name' => $pluginName, 'active' => 1]);
        if($pluginInstalled) {
            $view->assign($pluginName, true);
        }
    }

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![h\_lohaus](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@h\_lohaus](https://forum.shopware.com/u/h_lohaus)\
**Post date:** [22. März 2020 um 12:31 UTC](https://forum.shopware.com/t/auf-aktives-plugin-prufen/65671/2 "2020-03-22T12:31:37Z")

</div>

Ich nutze die 2. Methode, da so das Plugin nicht geladen wird.

---

<div class="post-metadata">

**Author:** ![mdsw](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mdsw](https://forum.shopware.com/u/mdsw)\
**Post date:** [22. März 2020 um 12:37 UTC](https://forum.shopware.com/t/auf-aktives-plugin-prufen/65671/3 "2020-03-22T12:37:36Z")

</div>

Inwiefern wird es in der ersten Methode „geladen“. Was meinst Du damit?

---

<div class="post-metadata">

**Author:** ![h\_lohaus](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@h\_lohaus](https://forum.shopware.com/u/h_lohaus)\
**Post date:** [22. März 2020 um 12:50 UTC](https://forum.shopware.com/t/auf-aktives-plugin-prufen/65671/4 "2020-03-22T12:50:46Z")

</div>

&nbsp;

$plugin = $pluginManager-\>getPluginByName($pluginName);

Das lädt die Plugin instance und registriert z.B. den Autoloader.
