# \[Solved\] ShopContext in ProductStream API

**URL:** <https://forum.shopware.com/t/solved-shopcontext-in-productstream-api/62335>\
**Category:** Programmierung\
**Created:** [13. Oktober 2019 um 16:59 UTC](https://forum.shopware.com/t/solved-shopcontext-in-productstream-api/62335 "2019-10-13T16:59:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Azd325](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/azd325/32/14050_2.png) [@Azd325](https://forum.shopware.com/u/Azd325)\
**Post date:** [13. Oktober 2019 um 16:59 UTC](https://forum.shopware.com/t/solved-shopcontext-in-productstream-api/62335/1 "2019-10-13T16:59:08Z")

</div>

```
    private function getProductStream($categoryID)
    {
        $category = Shopware()->Models()->getRepository('Shopware\Models\Category\Category')->find($categoryID);
        $criteria = new Criteria();
        $criteria->addBaseCondition(new CategoryCondition([$categoryID]));
        $criteria->offset(0)->limit(100);

        /** @var RepositoryInterface $streamRepository */
        $streamRepository = Shopware()->Container()->get('shopware_product_stream.repository');
        $streamRepository->prepareCriteria($criteria, $category->getStream());

        /** @var ProductSearchResult $result */
        $repository = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');
        $shop = $repository->getActiveDefault();
        $context = Shopware()->Container()->get('shopware_storefront.context_service')->getShopContext();

        $result = Shopware()->Container()->get('shopware_search.product_search')->search($criteria, $context);
        error_log("test");

        $count = $result->getTotalCount();
        return $count;
    }

```

&nbsp;

Ich bin gerade dabei eine ProductStream API zu bauen und stelle gerade fest das wenn ich die SuchFunktion aus dem Shopware verwenden möchte einen ShopKontext brauche.

Irgednwie schaffe ich es das nicht zu umgeben, jemand eine Idee?

&nbsp;
