# Resource "shop" not found failure in console plugin

**URL:** <https://forum.shopware.com/t/resource-shop-not-found-failure-in-console-plugin/38798>\
**Category:** Programmierung\
**Created:** [5. August 2016 um 06:38 UTC](https://forum.shopware.com/t/resource-shop-not-found-failure-in-console-plugin/38798 "2016-08-05T06:38:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wontfix](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@wontfix](https://forum.shopware.com/u/wontfix)\
**Post date:** [5. August 2016 um 06:38 UTC](https://forum.shopware.com/t/resource-shop-not-found-failure-in-console-plugin/38798/1 "2016-08-05T06:38:58Z")

</div>

ich versuche das code von [shopware sitemapxml controller](https://github.com/shopware/shopware/blob/5.1/engine/Shopware/Controllers/Frontend/SitemapXml.php#L43)&nbsp;in eine console plugin zu benutzen, aber es kommt ein fehler:

```
[Exception]
Resource "shop" not found failure

```

ich vermute wir müssen&nbsp;in console plugins sagen welche shop wir meinen, aber wie?  
oder was genau heißt diese fehler?

hier mein test code:

```
subscribeEvent(
            'Shopware_Console_Add_Command',
            'onAddConsoleCommand'
        );
        return true;
    }

    public function onAddConsoleCommand(Enlight_Event_EventArgs $args)
    {
        return new ArrayCollection([
            new SitemapCommand()
        ]);
    }
}

use Shopware\Commands\ShopwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SitemapCommand extends ShopwareCommand
{
    protected function configure ()
    {
        $this->setName("holabe:sitemap");
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $sitemaprepo = $this->container->get('sitemapxml.repository');
        $sitemap = $sitemaprepo->getSitemapContent();
        print_r($sitemap);
    }
}

```

ps. FWIW wir sind immernoch auf shopware 5.1.x

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [5. August 2016 um 08:05 UTC](https://forum.shopware.com/t/resource-shop-not-found-failure-in-console-plugin/38798/2 "2016-08-05T08:05:54Z")

</div>

Hi wontfix,

das SitemapXMLRepository erzeugt die Sitemap auf Grundlage eines Shops. Im Kontext eines CLI Commands hast du natürlich kein&nbsp;Shop Objekt. Daher taucht die eingangs von dir erwähnte Fehlermeldung auf.&nbsp;

Du musst dir also selbst ein Shop Objekt erzeugen. Falls du die Shop ID zur Verfügung hast, kannst du mal folgenden Code am Anfang deiner execute Methode ausprobieren:

```
/** @var \Shopware\Models\Shop\Repository $repository */
$repository = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');
$shop = $repository->getActiveById($shopId);

$shop->registerResources(Shopware()->Bootstrap());

```

Dadurch wird ein Shop mit der gegebenen ID initialisiert und dein Aufruf &nbsp;auf das SitemapXMLRepository sollte funktionieren

Viele Grüße aus Schöppingen

![cool](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![wontfix](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@wontfix](https://forum.shopware.com/u/wontfix)\
**Post date:** [5. August 2016 um 08:20 UTC](https://forum.shopware.com/t/resource-shop-not-found-failure-in-console-plugin/38798/3 "2016-08-05T08:20:26Z")

</div>

cool, danke!

FWIW, wir haben nur ein shop (per shopware code base) und diese zeile (hab von irgendwo kopiert) gibt uns denn shop ohne shopId:

```
$shop = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop')->getActiveDefault();

```

&nbsp;
