vendor/crehler/mojebambino-catalog/src/Controller/Storefront/CatalogController.php line 99

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @copyright 2020 Crehler Sp. z o. o.
  5.  * @link https://crehler.com/
  6.  * @support support@crehler.com
  7.  *
  8.  * @author Mateusz Flasiński
  9.  *
  10.  * For the full copyright and license information, please view the LICENSE
  11.  * file that was distributed with this source code.
  12.  */
  13. namespace Crehler\Catalog\Controller\Storefront;
  14. use Crehler\Catalog\Service\CatalogReader\BookmarksTreeService;
  15. use Crehler\Catalog\Service\CatalogReader\Loader\CatalogPageLoader as ApiCatalogPageLoader;
  16. use Crehler\Catalog\Service\CatalogReader\Page\CatalogPage\CatalogPageLoader;
  17. use Crehler\Catalog\Service\PdfFileLoaderService;
  18. use Crehler\Catalog\Service\SnippetsService;
  19. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  20. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  21. use Shopware\Storefront\Controller\StorefrontController;
  22. use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Response;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. /**
  27.  * @RouteScope(scopes={"storefront"})
  28.  */
  29. class CatalogController extends StorefrontController
  30. {
  31.     private BookmarksTreeService $bookmarksTreeService;
  32.     private CatalogPageLoader $catalogPageLoader;
  33.     private SnippetsService $snippetsService;
  34.     private ApiCatalogPageLoader $catalogPage;
  35.     private PdfFileLoaderService $fileLoaderService;
  36.     public function __construct(BookmarksTreeService $bookmarksTreeServiceCatalogPageLoader $catalogPageLoaderSnippetsService $snippetsServiceApiCatalogPageLoader $catalogPagePdfFileLoaderService $fileLoaderService)
  37.     {
  38.         $this->bookmarksTreeService $bookmarksTreeService;
  39.         $this->catalogPageLoader $catalogPageLoader;
  40.         $this->snippetsService $snippetsService;
  41.         $this->catalogPage $catalogPage;
  42.         $this->fileLoaderService $fileLoaderService;
  43.     }
  44.     /**
  45.      * @Route("/catalog/print/{catalogId}", name="frontend.catalog.print", options={"seo"="true"}, methods={"GET"})
  46.      */
  47.     public function print(string $catalogIdSalesChannelContext $context): Response
  48.     {
  49.         return $this->fileLoaderService->loadCatalog($catalogId$context);
  50.     }
  51.     /**
  52.      * @Route("/catalog/print-page/{pdfId}", name="frontend.catalog.print-page", options={"seo"="true"}, methods={"GET"})
  53.      */
  54.     public function printPage(string $pdfIdSalesChannelContext $context): Response
  55.     {
  56.         return $this->fileLoaderService->loadPage($pdfId$context);
  57.     }
  58.     /**
  59.      * @Route("/catalog/print-merge/{leftPdfId}/{rightPdfId}", name="frontend.catalog.print-merge", options={"seo"="true"}, methods={"GET"})
  60.      */
  61.     public function printMerge(string $leftPdfIdstring $rightPdfIdSalesChannelContext $context): Response
  62.     {
  63.         return $this->fileLoaderService->loadMerge($leftPdfId$rightPdfId$context);
  64.     }
  65.     /**
  66.      * @HttpCache()
  67.      * @Route("/catalog/detail/{catalogId}", name="frontend.catalog.detail", options={"seo"="true"}, methods={"GET"})
  68.      */
  69.     public function detail(Request $requestSalesChannelContext $context): ?Response
  70.     {
  71.         return $this->load($request$context'detail');
  72.     }
  73.     /**
  74.      * @HttpCache()
  75.      * @Route("/catalog/test", name="frontend.catalog.test", options={"seo"="true"}, methods={"GET"})
  76.      */
  77.     public function test(Request $requestSalesChannelContext $context): ?Response
  78.     {
  79.         $page $this->catalogPage->getPageDetail('2764d9c75ce14c7680221452071847a1'$context);
  80.     }
  81.     /**
  82.      * @HttpCache()
  83.      * @Route("/catalog/page/{pageId}", name="frontend.catalog.page", options={"seo"="true"}, methods={"GET"})
  84.      */
  85.     public function page(Request $requestSalesChannelContext $context): ?Response
  86.     {
  87.         return $this->load($request$context'page');
  88.     }
  89.     /**
  90.      * @HttpCache()
  91.      * @Route("/catalog/bookmark/{bookmarkId}", name="frontend.catalog.bookmark", options={"seo"="true"}, methods={"GET"})
  92.      */
  93.     public function bookmark(Request $requestSalesChannelContext $context): ?Response
  94.     {
  95.         return $this->load($request$context'bookmark');
  96.     }
  97.     private function load(Request $requestSalesChannelContext $contextstring $action 'detail'): ?Response
  98.     {
  99.         $currencySettings = [
  100.             'isoCode' => $context->getCurrency()->getIsoCode(),
  101.             'language' => 'pl-PL'// TODO wyjąć skądeś
  102.         ];
  103.         $page $this->catalogPageLoader->load($request$context);
  104.         $apiPageData $this->catalogPage->getPageDetail($page->getCatalogPageEntity()->getId(), $context);
  105.         if ($apiPageData->getRight() !== null && $apiPageData->getRight()->getPage()->getId() === $apiPageData->getRequestedId()) {
  106.             $apiRequestedPage $apiPageData->getRight();
  107.         } else {
  108.             $apiRequestedPage $apiPageData->getLeft();
  109.         }
  110.         $page->getMetaInformation()->setMetaTitle($apiPageData->getSeo()->getSeoTitle());
  111.         $page->getMetaInformation()->setMetaDescription($apiPageData->getSeo()->getSeoDescription());
  112.         $response $this->renderStorefront('@CrehlerCatalog/storefront/page/catalog/detail.html.twig', [
  113.             'page' => $page,
  114.             'appSnippets' => $this->snippetsService->load(),
  115.             'currencySettings' => $currencySettings,
  116.             'apiPageData' => $apiPageData,
  117.             'apiRequestedPage' => $apiRequestedPage,
  118.             'controllerName' => 'catalog',
  119.             'controllerAction' => $action,
  120.         ]);
  121.         return $response;
  122.     }
  123. }