Hallo, ich lerne gerade mit dem offiziellen Kurs „Shopware 6 - Developer Training Basic (EN)“ und bin beim Punkt „Controller“ hängen geblieben.
Nach dem ich alles so wie im Kurs nachgebaut habe versuche ich die Url „…/api/v2/_action/swag-shop-finder/generate“ per POST Request aufzurufen und bekomme die folgende Fehlermeldung: "The controller for URI „/api/v2/_action/swag-shop-finder/generate“ is not callable: Controller „DemoDataController“ has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?"
Irgendwas muss ich übersehen haben. Gibt es den Quellcode aus dem Kurs irgendwo einzusehen? Kann mir jemand bei dem Fehler sagen was ich vergessen habe?
Hier meine services.xml
Hier mein Controller:
declare(strict_types=1);
use Faker\Factory as FakerFactory;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\Country\CountryEntity;
use Shopware\Core\System\Country\Exception\CountryNotFoundException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @RouteScope(scopes={"api"})
*/
class DemoDataController extends AbstractController
{
/**
* @var EntityRepositoryInterface
*/
private $countryRepository;
/**
* @var EntityRepositoryInterface
*/
private $shopFinderRepository;
public function __construct(EntityRepositoryInterface $countryRepository, EntityRepositoryInterface $shopFinderRepository)
{
$this->countryRepository = $countryRepository;
$this->shopFinderRepository = $shopFinderRepository;
}
/**
* @Route("/api/v{version}/_action/swag-shop-finder/generate", name="api.custom.swag_shop_finder.generate", methods={"POST"})
*
* @return Response
*/
public function generate(Context $context): Response
{
$faker = FakerFactory::create();
$country = $this->getActiveCountry($context);
$data = [];
for ($i = 0; $i < 50; $i++) {
$data[] = [
'id' => Uuid::randomHex(),
'acitve' => true,
'name' => $faker->name,
'street' => $faker->streetAddress,
'postCode' => $faker->postcode,
'city' => $faker->city,
'countryId' => $country->getId(),
];
}
$this->shopFinderRepository->create($data, $context);
return new Response('', Response::HTTP_NO_CONTENT);
}
/**
* getActiveCountry
*
* @param Context $context
* @return CountryEntity
*/
private function getActiveCountry(Context $context): CountryEntity
{
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('active', '1'));
$criteria->setLimit(1);
$country = $this->countryRepository->search($criteria, $context)->getEntities()->first();
if ($country === null) {
throw new CountryNotFoundException('');
}
return $country;
}
}