<?php declare(strict_types=1);
namespace TemplaidInvoices\Controller;
use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Core\Framework\Routing\Annotation\LoginRequired;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Shopware\Storefront\Framework\Routing\Annotation\NoStore;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
use Symfony\Component\Routing\Annotation\Route;
use TemplaidInvoices\Storefront\Page\Account\TemplaidAssortmentPageLoader;
/**
* @RouteScope(scopes={"storefront"})
*/
class ListController extends StorefrontController
{
private TemplaidAssortmentPageLoader $assortmentPageLoader;
public function __construct(
TemplaidAssortmentPageLoader $assortmentPageLoader
)
{
$this->assortmentPageLoader = $assortmentPageLoader;
}
/**
* @Since("6.0.0.0")
* @LoginRequired()
* @Route("/account/assortment/{list}/{listId}", name="frontend.templaid.assortment.page", options={"seo"="false"}, methods={"GET", "POST"}, defaults={"XmlHttpRequest"=true})
* @NoStore()
*
* @throws CustomerNotLoggedInException
* @throws InconsistentCriteriaIdsException
* @throws MissingRequestParameterException
* @throws \Exception
*/
public function invoices(string $list, string $listId, Request $request, SalesChannelContext $context): Response
{
$page = $this->assortmentPageLoader->load($request, $context);
return $this->renderStorefront('@Storefront/storefront/page/account/assortment.html.twig', ['page' => $page, 'list' => $list, 'listId' => $listId]);
}
/**
* @Route("/templaid/listing/list-type", name="frontend.templaid.listing.listType", defaults={"csrf_protected"=false, "XmlHttpRequest"=true}, methods={"POST"})
*/
public function setListType(Request $request, RequestDataBag $data, SalesChannelContext $context): JsonResponse
{
$request->getSession()->set('listType', $request->get('listType'));
return new JsonResponse(['success' => true]);
}
/**
* @Route("/templaid/listing/list-limit", name="frontend.templaid.listing.listLimit", defaults={"csrf_protected"=false, "XmlHttpRequest"=true}, methods={"POST"})
*/
public function setListLimit(Request $request, RequestDataBag $data, SalesChannelContext $context): JsonResponse
{
$parameters = $request->query->all();
$parameters['limit'] = (int)$request->get('listLimit');
$refRoute = $request->get('refUrl');
return new JsonResponse(['success' => true, 'url' => $this->generateUrl($refRoute, $parameters)]);
}
}