Ich habe einen Controller für Account hinzugefügt.
Es funktioniert so wie alle anderen Account-Menus, aber nur bei diesem wird nur „Home“ aber nicht der Rest der Kategorie-Liste geladen.
Controller:
<?php declare(strict_types=1);
namespace XXXTheme\Storefront\Controller;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route(defaults: ['_routeScope' => ['storefront']])]
class AccountBacklogController extends StorefrontController
{
private EntityRepository $orderRepository;
private EntityRepository $customerRepository;
private EntityRepository $orderLineItemRepository; // OrderLineItemRepository hinzuf gen
private string $allowedSalesChannelId;
public function __construct(
EntityRepository $orderRepository,
EntityRepository $customerRepository,
EntityRepository $orderLineItemRepository, // OrderLineItemRepository injizieren
string $allowedSalesChannelId
) {
$this->orderRepository = $orderRepository;
$this->customerRepository = $customerRepository;
$this->orderLineItemRepository = $orderLineItemRepository; // Zuweisung
$this->allowedSalesChannelId = $allowedSalesChannelId;
}
#[Route(path: '/account/backlog', name: 'frontend.account.backlog', methods: ['GET'], defaults: ['_routeScope' => ['storefront']])]
public function showBacklog(SalesChannelContext $context): Response
{
// Pr fen, ob der aktuelle SalesChannel der erlaubte ist
if ($context->getSalesChannel()->getId() !== $this->allowedSalesChannelId) {
throw $this->createNotFoundException('This route is not available for this sales channel.');
}
// Kunden-ID aus dem SalesChannelContext
$customerId = $context->getCustomer()->getId();
// Lade Kundendaten
$customerCriteria = new Criteria([$customerId]);
$customer = $this->customerRepository->search($customerCriteria, $context->getContext())->first();
// Lade Bestellungen
$orderCriteria = new Criteria();
$orderCriteria->addFilter(new EqualsFilter('order.orderCustomer.customerId', $customerId));
$orderCriteria->addAssociation('order.orderCustomer');
$orderCriteria->addAssociation('lineItems.product');
$orders = $this->orderRepository->search($orderCriteria, $context->getContext());
return $this->renderStorefront('@XXXTheme/storefront/page/account/backlog.html.twig', [
'customer' => $customer,
'orders' => $orders
]);
}
}
Mit Menü
Kein Menü
Hat jemand eine Idee?
Danke und Gruss