# How to use shop instance in CLI context?

**URL:** https://forum.shopware.com/t/how-to-use-shop-instance-in-cli-context/60286
**Category:** Plugins
**Created:** [4. Juli 2019 um 11:10 UTC](https://forum.shopware.com/t/how-to-use-shop-instance-in-cli-context/60286 "2019-07-04T11:10:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)
#### Post date: [4. Juli 2019 um 11:10 UTC](https://forum.shopware.com/t/how-to-use-shop-instance-in-cli-context/60286/1 "2019-07-04T11:10:55Z")

</div>

I have created a plugin. and i use Shopware()-\>Shop()-\>getCurrency()-\>getId() inside a function not in constructor i got the following error.

You have requested a non-existent service “shop”.

Is there any way to use this shop instance in my plugin? I am running the plugin via CLI

I am using shopware 5.5.6.

---

<div class="post-metadata">

### Author: ![vanwittlaer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/vanwittlaer/32/8499_2.png) [@vanwittlaer](https://forum.shopware.com/u/vanwittlaer)
#### Post date: [4. Juli 2019 um 12:07 UTC](https://forum.shopware.com/t/how-to-use-shop-instance-in-cli-context/60286/2 "2019-07-04T12:07:49Z")

</div>

Well, when you are in CLI, the actual shop is not defined. If you want&nbsp;to refer to a particular one, you’d neet to create the shop context first. It is feasible but perhaps a bit tricky.

---

<div class="post-metadata">

### Author: ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)
#### Post date: [4. Juli 2019 um 12:19 UTC](https://forum.shopware.com/t/how-to-use-shop-instance-in-cli-context/60286/3 "2019-07-04T12:19:24Z")

</div>

How we can create&nbsp;shop context for a particular shop?

---

<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: [18. Juli 2019 um 08:28 UTC](https://forum.shopware.com/t/how-to-use-shop-instance-in-cli-context/60286/4 "2019-07-18T08:28:09Z")

</div>

Hello,

it is already mentioned several times here in the forum, but in German, so maybe you couldn’t find it&nbsp; ![Smile](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/bac5f5766b6a20565a8fb995345b4e41d24daac0.png "Smile")

```
$repository = Shopware()->Container()->get('models')->getRepository(Shopware\Models\Shop\Shop::class);
$shopId = 1; // use your correct shop ID here
$shop = $repository->getActiveById($shopId);
$shop->registerResources();
$context = \Shopware\Components\Routing\Context::createFromShop(
    $shop,
    Shopware()->Container()->get('config')
);

```

Attention here: Since Shopware 5.6 the&nbsp;registerResources is deprecated. Use the&nbsp;shopware.components.shop\_registration\_service instead.&nbsp;

Best regards from Schöppingen

![cool](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "cool")&nbsp;Michael Telgmann
