src/Controller/Shop/ProductController.php line 88

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller\Shop;
  7. use App\Model\Shop\Event\EventProduct;
  8. use App\Model\Shop\Merchandise\MerchandiseProduct;
  9. use App\Service\ContentService;
  10. use App\Service\Shop\ProductService;
  11. use App\Service\TrackingService;
  12. use App\Twig\LinkGeneratorExtension;
  13. use Knp\Component\Pager\PaginatorInterface;
  14. use Pimcore\Model\DataObject;
  15. use Pimcore\Model\DataObject\ShopEvent;
  16. use Pimcore\Model\DataObject\ShopMerchandiseProduct;
  17. use Pimcore\Model\DataObject\ShopTicketCatalog;
  18. use Symfony\Component\HttpFoundation\RedirectResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\HttpKernel\Exception\GoneHttpException;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. class ProductController extends AbstractShopController
  24. {
  25.     public function ticketOverviewAction(Request $requestPaginatorInterface $paginatorProductService $serviceTrackingService $trackingService): Response
  26.     {
  27.         $catalogs = new ShopTicketCatalog\Listing();
  28.         $catalogs->addConditionParam('hideInListing IS NULL OR hideInListing = ""');
  29.         $returnData $service->prepareProductData($catalogs$request$paginator);
  30.         $trackingData $trackingService->getOverviewItemList($returnData['products']);
  31.         if ($trackingData) {
  32.             $returnData['trackingData'] = $trackingData;
  33.         }
  34.         if ($request->isXmlHttpRequest()) {
  35.             $returnData['ajax'] = 1;
  36.             $template $this->renderTemplate('shop/includes/product/product-grid-result.html.twig'$returnData);
  37.             $jsonResponse = [
  38.                 'success' => true,
  39.                 'html' => $template->getContent(),
  40.             ];
  41.             if ($trackingData) {
  42.                 $jsonResponse['responseTrackingData'] = [
  43.                     'gtm' => [
  44.                         'datalayer' => $trackingData,
  45.                     ],
  46.                 ];
  47.             }
  48.             return $this->json($jsonResponse);
  49.         }
  50.         return $this->render('shop/product/ticketOverview.html.twig'$returnData);
  51.     }
  52.     public function ticketDetailAction(Request $request): Response
  53.     {
  54.         if ($product $this->document->getProperty('shopProduct')) {
  55.             $trackingManager $this->factory->getTrackingManager();
  56.             $trackingManager->trackProductView($product);
  57.         }
  58.         $editables $this->document->getEditables();
  59.         $keys array_keys($editables);
  60.         $showFaqAnchor false;
  61.         foreach ($keys as $key) {
  62.             if (str_contains($key'accordion')) {
  63.                 $showFaqAnchor true;
  64.                 break;
  65.             }
  66.         }
  67.         return $this->render('shop/product/ticketDetail.html.twig', [
  68.             'showFaqAnchor' => $showFaqAnchor,
  69.         ]);
  70.     }
  71.     public function eventOverviewAction(Request $requestPaginatorInterface $paginatorProductService $serviceTrackingService $trackingService): Response
  72.     {
  73.         $events = new ShopEvent\Listing();
  74.         $events->addConditionParam('hideInEventList IS NULL OR hideInEventList = ""');
  75.         $returnData $service->prepareProductData($events$request$paginator);
  76.         $trackingData $trackingService->getOverviewItemList($returnData['products']);
  77.         if ($trackingData) {
  78.             $returnData['trackingData'] = $trackingData;
  79.         }
  80.         if ($request->isXmlHttpRequest()) {
  81.             $returnData['ajax'] = 1;
  82.             $template $this->renderTemplate('shop/includes/product/product-grid-result.html.twig'$returnData);
  83.             $jsonResponse = [
  84.                 'success' => true,
  85.                 'html' => $template->getContent(),
  86.             ];
  87.             if ($trackingData) {
  88.                 $jsonResponse['responseTrackingData'] = [
  89.                     'gtm' => [
  90.                         'datalayer' => $trackingData,
  91.                     ],
  92.                 ];
  93.             }
  94.             return $this->json($jsonResponse);
  95.         }
  96.         return $this->render('shop/product/eventOverview.html.twig'$returnData);
  97.     }
  98.     public function eventDetailAction(Request $request): Response
  99.     {
  100.         if ($product $this->document->getProperty('shopProduct')) {
  101.             $trackingManager $this->factory->getTrackingManager();
  102.             $trackingManager->trackProductView($product);
  103.         }
  104.         $editables $this->document->getEditables();
  105.         $keys array_keys($editables);
  106.         $showFaqAnchor false;
  107.         foreach ($keys as $key) {
  108.             if (str_contains($key'accordion')) {
  109.                 $showFaqAnchor true;
  110.                 break;
  111.             }
  112.         }
  113.         return $this->render('shop/product/eventDetail.html.twig', [
  114.             'showFaqAnchor' => $showFaqAnchor,
  115.         ]);
  116.     }
  117.     public function merchandiseOverviewAction(Request $requestPaginatorInterface $paginatorProductService $serviceTrackingService $trackingService): Response
  118.     {
  119.         $merchandise = new ShopMerchandiseProduct\Listing();
  120.         $returnData $service->prepareMerchData($merchandise$request$paginator);
  121.         $trackingData $trackingService->getOverviewItemList($returnData['products']);
  122.         if ($trackingData) {
  123.             $returnData['trackingData'] = $trackingData;
  124.         }
  125.         if ($request->isXmlHttpRequest()) {
  126.             $returnData['ajax'] = 1;
  127.             $returnData['merchandise'] = 1;
  128.             $template $this->renderTemplate('shop/includes/product/product-grid-result.html.twig'$returnData);
  129.             $jsonResponse = [
  130.                 'success' => true,
  131.                 'html' => $template->getContent(),
  132.             ];
  133.             if ($trackingData) {
  134.                 $jsonResponse['responseTrackingData'] = [
  135.                     'gtm' => [
  136.                         'datalayer' => $trackingData,
  137.                     ],
  138.                 ];
  139.             }
  140.             return $this->json($jsonResponse);
  141.         }
  142.         return $this->render('shop/product/merchandiseOverview.html.twig'$returnData);
  143.     }
  144.     /**
  145.      * @Route("{path}{name}_m_{id}", name="merchandise_detail", defaults={"path"=""}, requirements={"path"=".*?", "name"="[\w-]+", "id"="\d+"})
  146.      *
  147.      * @param Request $request
  148.      * @param ContentService $service
  149.      *
  150.      * @return Response
  151.      */
  152.     public function merchandiseDetailAction(Request $requestContentService $serviceTrackingService $trackingService): Response
  153.     {
  154.         $merchandise MerchandiseProduct::getById($request->get('id'));
  155.         if ((!($merchandise instanceof MerchandiseProduct) || !$merchandise->isPublished()) && !$request->get('pimcore_object_preview')) {
  156.             throw new GoneHttpException('Requested object not found or not published!');
  157.         }
  158.         $trackingManager $this->factory->getTrackingManager();
  159.         $trackingManager->trackProductView($merchandise);
  160.         $tracking $trackingService->createGA4ProductInfoArray($merchandise'add_to_cart');
  161.         $faqs $merchandise->getFaqCategory() ? $service->getFaqsByCategories([$merchandise->getFaqCategory()])->load() : [];
  162.         $returnArray = [ 'product' => $merchandise'faqs' => $faqs'tracking' => $tracking ];
  163.         if ($request->get('reload-variant')) {
  164.             $product MerchandiseProduct::getById(intval($request->get('reload-variant')));
  165.             $returnArray['product'] = $product;
  166.             $template $this->renderTemplate('shop/includes/product/merchandise-content.html.twig'$returnArray);
  167.             return $this->json([ 'success' => true'html' => $template->getContent() ]);
  168.         }
  169.         return $this->render('shop/product/merchandiseDetail.html.twig'$returnArray);
  170.     }
  171.     /**
  172.      * @Route("{_locale}/notification-overlay?id={id}", name="notification_overlay")
  173.      *
  174.      * @param Request $request
  175.      * @param ProductService $productService
  176.      * @param LinkGeneratorExtension $linkGenerator
  177.      *
  178.      * @return Response|RedirectResponse
  179.      */
  180.     public function notificationOverlay(Request $requestProductService $productServiceLinkGeneratorExtension $linkGenerator): Response|RedirectResponse
  181.     {
  182.         $id $request->get('id');
  183.         $product DataObject::getById($id);
  184.         $email $request->get('email');
  185.         if ((!$product instanceof MerchandiseProduct && !$product instanceof EventProduct && !$product instanceof ShopTicketCatalog) || !$product->isPublished()) {
  186.             throw new GoneHttpException('Requested object not found or not published!');
  187.         }
  188.         if ($request->getMethod() == 'POST' && $email != '') {
  189.             $success $productService->handleNotificationRequest($email$id$request->getLocale()) ?: 'false';
  190.             return new RedirectResponse($linkGenerator->getDetailLink($product) . '?success=' $success);
  191.         }
  192.         $template $this->renderTemplate('includes/overlays/notification-content.html.twig', [ 'id' => $id'product' => $product ]);
  193.         return $this->json([ 'success' => true'html' => $template->getContent() ]);
  194.     }
  195. }