Servus!
Ich hab ein Problem. Ich weiß nicht wie ich ein ManufacturerRepository erstelle.
Ich hab einen ManufacturerPage Controller, der die Daten für mich rendert.
Von hier aus soll der Controller die ID, die über die URL geliefert wird, im ManufacturerRepository suchen und dem Template übergeben.
<?php declare(strict_types=1);
namespace [myName]\Storefront\Controller;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Shopware\Storefront\Page\Navigation\NavigationPageLoaderInterface;
use Shopware\Storefront\Pagelet\Menu\Offcanvas\MenuOffcanvasPageletLoaderInterface;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
/**
* @RouteScope(scopes={"storefront"})
*/
class WinzerpageController extends StorefrontController
{
private NavigationPageLoaderInterface $navigationPageLoader;
private MenuOffcanvasPageletLoaderInterface $offcanvasLoader;
private string $manufacturerId;
private string $manufacturerName;
public function __construct(
NavigationPageLoaderInterface $navigationPageLoader,
MenuOffcanvasPageletLoaderInterface $offcanvasLoader
)
{
$this->navigationPageLoader = $navigationPageLoader;
$this->offcanvasLoader = $offcanvasLoader;
}
/**
* @Route("/winzer/{manufacturerName}/{manufacturerId}", name="frontend.winzer.winzer", options={"seo"="true"}, methods={"GET"})
*/
public function renderOneWinzer(Request $request,
SalesChannelContext $context,
string $manufacturerId
): ?Response
{
$this->manufacturerId = $manufacturerId;
$page = $this->navigationPageLoader->load($request, $context);
/**
* WinzerRepository erstellen
*/
return $this->renderStorefront('@VinoshopTheme/storefront/page/winzer/winzerpage.html.twig',
['page' => $page, 'manufacturerId' => $manufacturerId],
);
}
}
<service id="[myName]\Storefront\Controller\WinzerpageController" public="true">
<argument type="service" id="Shopware\Storefront\Page\Navigation\NavigationPageLoader"/>
<argument type="service" id="Shopware\Storefront\Pagelet\Menu\Offcanvas\MenuOffcanvasPageletLoader"/>
<argument type="service" id="Shopware\Core\Content\Seo\SeoUrlPlaceholderHandlerInterface"/>
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
<argument type="service" id="sales_channel.product.repository"/>
<argument type="service" id="product_manufacturer.repository"/>
</service>