# ProductStream-Erweiterung

**URL:** https://forum.shopware.com/t/productstream-erweiterung/60432
**Category:** Programmierung
**Created:** [15. Juli 2019 um 07:41 UTC](https://forum.shopware.com/t/productstream-erweiterung/60432 "2019-07-15T07:41:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mbdus](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/mbdus/32/12997_2.png) [@mbdus](https://forum.shopware.com/u/mbdus)
#### Post date: [15. Juli 2019 um 07:41 UTC](https://forum.shopware.com/t/productstream-erweiterung/60432/1 "2019-07-15T07:41:26Z")

</div>

Ich würde gerne ganz allgemein die Product-Stream-Queries erweitern. Zumindest aber mal in den Einkaufswelten und in den Kategorien.

Dazu habe ich mir überlegt, den ProductNumberSearch-Service oder die QueryBuilderFactory zu dekorieren. Damit komme ich zwar an die Query, um diese zu erweitern, aber ich kann nicht abfragen, ob es sich um einen ProductStream handelt.

So würde es bspw. in einer Kategorie funktionieren:

```
originalService = $service;
		$this->connection = $connection;
	}
	
	public function createProductQuery(Criteria $criteria, ShopContextInterface $context)
	{
		$query = $this->originalService->createProductQuery($criteria, $context);
	
		$categoryID = Shopware ()->Front ()->Request()->getParam('sCategory');
		
		if(!empty($categoryID)){
			$productStreamId = $this->findStreamIdByCategoryId($categoryID);
			if(!empty($productStreamId)){
				// Modify query
				$orderArray = $query->getQueryPart('orderBy');
				array_unshift($orderArray, 'product.name ASC');
				$query->add('orderBy', $orderArray);
			}
		}
	
		return $query;
	}
	
	/**
	 * {@inheritdoc}
	 */
	public function createQueryWithSorting(Criteria $criteria, ShopContextInterface $context)
	{
		$query = $this->originalService->createQueryWithSorting($criteria, $context);
	
		return $query;
	}
	
	/**
	 * {@inheritdoc}
	 *
	 * @throws \Exception
	 */
	public function createQuery(Criteria $criteria, ShopContextInterface $context)
	{
		$query = $this->originalService->createQuery($criteria, $context);
	
		return $query;
	}
	
	/**
	 * {@inheritdoc}
	 */
	public function createQueryBuilder()
	{
		return new QueryBuilder($this->connection);
	}
	
	/**
	 * @param int $categoryId
	 *
	 * @return int|null
	 */
	private function findStreamIdByCategoryId($categoryId)
	{
		$streamId = Shopware()->Container()->get('dbal_connection')->fetchColumn(
				'SELECT stream_id FROM s_categories WHERE id = :id',
				['id' => $categoryId]
		);
	
		if ($streamId) {
			return (int) $streamId;
		}
	
		return null;
	}
}

```

In einer Einkaufswelt bräuchte ich dann aber die ElementId und ProductStreamId, um den Query einschränken zu können.

Kann man ganz global ProductStreams erweitern, egal an welcher Stelle? Ansonsten müsste man jeden einzelnen Service dekorieren.

Danke im Voraus.

---

<div class="post-metadata">

### Author: ![mbdus](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/mbdus/32/12997_2.png) [@mbdus](https://forum.shopware.com/u/mbdus)
#### Post date: [17. Juli 2019 um 09:23 UTC](https://forum.shopware.com/t/productstream-erweiterung/60432/2 "2019-07-17T09:23:52Z")

</div>

Und noch ein weiteres Problem:

Damit steht an anderer Stelle nicht mehr “shopware\_searchdbal.dbal\_query\_builder\_factory” zur Verfügung. Ab dem Zeitpunkt wird nur noch “mbdus\_product\_stream.dbal\_query\_builder\_factory” an die Konstruktoren übergeben. Gibt es dafür eine Lösung? Ansonsten würde ich es über Enlight\_Bootstrap\_AfterInitResource versuchen.

Danke im Voraus.

&nbsp;

---

<div class="post-metadata">

### Author: ![mbdus](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/mbdus/32/12997_2.png) [@mbdus](https://forum.shopware.com/u/mbdus)
#### Post date: [17. Juli 2019 um 11:06 UTC](https://forum.shopware.com/t/productstream-erweiterung/60432/3 "2019-07-17T11:06:14Z")

</div>

Nachtrag:

Im zweiten Plugin bekomme ich die Fehlermeldung:

\_\_construct() must be an instance of Shopware\Bundle\SearchBundleDBAL\QueryBuilderFactory, instance of MbdusProductStream\SearchBundle\QueryBuilderFactory given

---

<div class="post-metadata">

### Author: ![mbdus](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/mbdus/32/12997_2.png) [@mbdus](https://forum.shopware.com/u/mbdus)
#### Post date: [17. Juli 2019 um 15:13 UTC](https://forum.shopware.com/t/productstream-erweiterung/60432/4 "2019-07-17T15:13:46Z")

</div>

Mit

```
use Shopware\Bundle\SearchBundleDBAL\QueryBuilderFactory as ShopwareQueryBuilderFactory;

class QueryBuilderFactory extends ShopwareQueryBuilderFactory

```

anstatt

```
class QueryBuilderFactory implements QueryBuilderFactoryInterface

```

funktioniert es.

---

<div class="post-metadata">

### Author: ![mbdus](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/mbdus/32/12997_2.png) [@mbdus](https://forum.shopware.com/u/mbdus)
#### Post date: [17. Juli 2019 um 15:18 UTC](https://forum.shopware.com/t/productstream-erweiterung/60432/5 "2019-07-17T15:18:53Z")

</div>

Was passiert, wenn das 2. Plugin createProductQuery erweitern möchte? Funktioniert es dann auch noch?

---

<div class="post-metadata">

### Author: ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)
#### Post date: [17. Juli 2019 um 15:59 UTC](https://forum.shopware.com/t/productstream-erweiterung/60432/6 "2019-07-17T15:59:54Z")

</div>

Wenn alle Plugins brav das Interface benutzen, sollte es keine Probleme geben
