# Mein erstes Plugin funktioniert nicht

**URL:** <https://forum.shopware.com/t/mein-erstes-plugin-funktioniert-nicht/101693>\
**Category:** Programmierung\
**Created:** [25. Oktober 2023 um 10:35 UTC](https://forum.shopware.com/t/mein-erstes-plugin-funktioniert-nicht/101693 "2023-10-25T10:35:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![birner](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@birner](https://forum.shopware.com/u/birner)\
**Post date:** [25. Oktober 2023 um 10:35 UTC](https://forum.shopware.com/t/mein-erstes-plugin-funktioniert-nicht/101693/1 "2023-10-25T10:35:13Z")

</div>

Hallo zusammen, ich versuche mich gerade an meinem ersten Plugin und mache dazu ein Youtube Videotutorial. Die ersten Schritte haben gut geklappt aber jetzt geht es nicht weiter…

Fehlermeldung: BirnerPlattform\Service\ObtainData::\_\_construct(): Argument #1 ($productRepository) must be of type BirnerPlattform\Service\EntityRepositoryInterface, Shopware\Core\Framework\DataAbstractionLayer\EntityRepository given, called in /var/www/vhosts/distracted-ishizaka.176-221-46-119.plesk.page/httpdocs/var/cache/dev\_h0aa30acdff67165bea2aef71fb1552a9/ContainerCVModvt/Shopware\_Core\_KernelDevDebugContainer.php on line 23539

Dazu habe ich 2 Dateien im Ordner „Services“ und die services.xml

1. AddDataToPage.php

```auto
<?php declare(strict_types=1);

namespace BirnerPlattform\Service;

use Shopware\Storefront\Page\Product\ProductPageLoadedEvent; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;

class AddDataToPage implements EventSubscriberInterface
{
	
	private $productRepository;
	
	public function __construct(ObtainData $obtainData)
	{
		$this->productRepository = $obtainData;
	}
	 
    public static function getSubscribedEvents(): array
    {
        return [
            ProductPageLoadedEvent::class => 'addProductAvailability'
        ];
    }

    public function addProductAvailability(ProductPageLoadedEvent $event): void
    {
		
		$meineVariable = $this->productRepository->activeStatus('SW10000', $event->getContext());
		
		$event->getPage()->assign(['meineVariable' => $meineVariable]);
    }
}

```

ObtainData.php

```auto
<?php declare(strict_types=1);

namespace BirnerPlattform\Service;

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;

class ObtainData
{
	private EntityRepositoryInterface $productRepository;
	
	public function __construct(EntityRepositoryInterface $productRepository)
	{
		$this->productRepository = $productRepository;
	}
	
	public function activeStatus($productNumber, Context $context) : bool
	{
		
		$criteria = new Criteria();
		
		$criteria->addFilter(new EqualsFilter('productNumber', $productNumber));
		
		$product = $this->productRepository->search($criteria, $context)->first();
		
		return is_null($product) ? false : $product->active;
	}
	
}

```

services.xml

\<?xml version="1.0" ?\>

```
<services>
    <service id="BirnerPlattform\Service\AddDataToPage">
        <argument type="service" id="BirnerPlattform\Service\ObtainData" />
        <tag name="kernel.event_subscriber" />
    </service>
    <service id="BirnerPlattform\Service\ObtainData">
        <argument type="service" id="product.repository" />
    </service>
</services>

```

Generell habe ich alles genau so gemacht wie beschrieben. Laut ChatGPT ist folgendes möglich, was mir aber wenig hilft: Die in deinem Code gezeigten Dateien sehen im Allgemeinen in Ordnung aus. Es sieht so aus, als ob die Konfiguration und die Abhängigkeiten korrekt festgelegt sind. Der Fehler, den du zuvor gemeldet hast, tritt auf, weil der `ObtainData`-Service nach einem Argument vom Typ `EntityRepositoryInterface` verlangt, während der Container offenbar einen Service vom Typ `EntityRepository` bereitstellt. Dies könnte auf eine Inkompatibilität zwischen den verwendeten Versionen von Shopware oder anderen Faktoren hinweisen.

Hat jemand eine Idee und Lust mir bei meinem ersten großen Hinderniss zu helfen? 🙂

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [25. Oktober 2023 um 10:45 UTC](https://forum.shopware.com/t/mein-erstes-plugin-funktioniert-nicht/101693/2 "2023-10-25T10:45:24Z")

</div>

> [@birner](#):
>
> EntityRepositoryInterface

gibt es seit Shopware 6.5 nicht mehr, wenn ich mich recht erinnere. Einfach das Interface entfernen.

Die Dokumentation ist ggf. noch 6.4/6.5 vermischt, leider.

---

<div class="post-metadata">

**Author:** ![birner](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@birner](https://forum.shopware.com/u/birner)\
**Post date:** [25. Oktober 2023 um 10:49 UTC](https://forum.shopware.com/t/mein-erstes-plugin-funktioniert-nicht/101693/3 "2023-10-25T10:49:15Z")

</div>

Ja jetzt geht es. Vielen vielen Dank!

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/2/9/29c7587ba660f00e4995d1743162782e5d6d8653.svg) [@system](https://forum.shopware.com/u/system)\
**Post date:** [24. November 2023 um 10:49 UTC](https://forum.shopware.com/t/mein-erstes-plugin-funktioniert-nicht/101693/4 "2023-11-24T10:49:42Z")

</div>

Dieses Thema wurde automatisch 30 Tage nach der letzten Antwort geschlossen. Es sind keine neuen Antworten mehr erlaubt.
