src/Controller/ProductController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Helpers\HomePageFetcher;
  4. use Exception;
  5. use Pimcore\Targeting\VisitorInfoStorageInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  8. use Symfony\Component\Routing\RouterInterface;
  9. class ProductController extends DefaultFrontendController
  10. {
  11.     public function __construct(
  12.         protected RouterInterface $router,
  13.         VisitorInfoStorageInterface $visitorInfoStorage
  14.     ) {
  15.         parent::__construct($visitorInfoStorage);
  16.     }
  17.     /**
  18.      * @Template
  19.      * @param Request $request
  20.      * @return array
  21.      * @throws Exception
  22.      *
  23.      */
  24.     public function singleAction(Request $request): array
  25.     {
  26.         $product $this->getDocumentEditable('relation''product')->getElement();
  27.         if ($product) {
  28.             $this->addAreaBrickData('faq-brick', [
  29.                 'faqs' => $product->getFaqs(),
  30.                 'faqs_source' => "Product",
  31.             ]);
  32.         }
  33.         /** @see SpecificationSheetController::singlePdfAction() */
  34.         //$homePageForThisLanguage = HomePageFetcher::homePages()[$request->getLocale() ?? "en"] ?? null;
  35.         //$specSheet = $product ? $homePageForThisLanguage->getUrl() . "product-download-sheet/" . $product->getId() : null;
  36.         $specSheetUrl $product
  37.             $this->router->generate('product_spec_sheet', ['_locale' => $request->getLocale() ?? 'en''product' => $product->getId()])
  38.             : null;
  39.         $data parent::data($request);
  40.         $data['product'] = $product;
  41.         $data['linkToSpecificationSheet'] = $specSheetUrl;
  42.         if ($product && $product->getDefaultFeaturedImage()) {
  43.             $data['page']['og']['image'] = $product->getDefaultFeaturedImage()->getFullPath();
  44.         }
  45.         return $data;
  46.     }
  47. }