src/Controller/LandingPageController.php line 86

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\LandingPage;
  4. use App\Entity\SubProduct;
  5. use App\Entity\User;
  6. use App\Form\Handler\RegisterHandler;
  7. use App\Form\Type\RegisterType;
  8. use App\Helper\VeltisControllerTrait;
  9. use App\Repository\ProductRepository;
  10. use App\Services\CartService;
  11. use App\Services\UserService;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  14. use FOS\RestBundle\Controller\Annotations as Rest;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  16. use Symfony\Component\BrowserKit\Response;
  17. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use Symfony\Component\HttpFoundation\RedirectResponse;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  22. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  23. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  24. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  25. class LandingPageController extends AbstractController
  26. {
  27.     use VeltisControllerTrait;
  28.     /**
  29.      * @Route("/lp/{id}/{slug}/{product}", name="landing-page-front", defaults={"product":null})
  30.      */
  31.     public function registerAction(Request $requestUserService $userServiceCartService $cartServiceSessionInterface $sessionTokenStorageInterface $tokenStorageEventDispatcherInterface $eventDispatcherProductRepository $productRepository)
  32.     {
  33.         /** @var $landingPage LandingPage */
  34.         $landingPage $this->em()->getRepository(\App\Entity\LandingPage::class)->find($request->attributes->get('id'));
  35.         if ($landingPage->getRedirect()) {
  36.             return new RedirectResponse($landingPage->getRedirect(), 301);
  37.         }
  38.         $products $productRepository->getForLandingPage($landingPage, ['locale'=>$landingPage->getLanguage()->getLocale()])->getQuery()->getResult();
  39.         $productsForProducer = [];
  40.         if ($landingPage->getProductProducer()) {
  41.             $productsForProducer $productRepository->getForLandingPageProductProducer($landingPage, ['locale'=>$landingPage->getLanguage()->getLocale()])->getQuery()->getResult();
  42.         }
  43.         if ($landingPage->getSpecialForBuyCheaper()) {
  44.             $products $productRepository->getForSpecialLandingPage($landingPage, ['locale'=>$landingPage->getLanguage()->getLocale()])->getQuery()->getResult();
  45.             $p = [];
  46.             foreach ($products as $product) {
  47.                 /** @var $sub SubProduct */
  48.                 foreach ($product[0]->getSubProducts() as $sub) {
  49.                     if ($sub->getActive() && $sub->getDeletedBy() === null) {
  50.                         $temp $product;
  51.                         $temp['mainPhoto'] = $product[0]->getMainPhoto();
  52.                         $temp['subName'] = $sub->getName();
  53.                         $temp['subPrice'] = $sub->getPrice();
  54.                         $temp['subRebate'] = $sub->getRebate();
  55.                         $temp['subId'] = $sub->getId();
  56.                         $temp['beforeDiscount'] = $sub->getBeforeDiscountPrice();
  57.                         $p[] = $temp;
  58.                     }
  59.                 }
  60.             }
  61.             $products $p;
  62.         }
  63.         $currency $landingPage->getLanguage()->getCurrency();
  64.         $productEntity null;
  65.         if ($request->attributes->get('product')) {
  66.             $productEntity $this->em()->getRepository(\App\Entity\Product::class)->find($request->attributes->get('product'));
  67.         }
  68.         return $this->render('frontend/landingPage/landingPage.html.twig', [
  69.             'landingPage' => $landingPage,
  70.             'productEntity'=>$productEntity,
  71.             'currency' => $currency,
  72.             'language' => $landingPage->getLanguage(),
  73.             'product' => $request->attributes->get('product'),
  74.             'products' => $products,
  75.             'productsForProducer' => $productsForProducer,
  76.         ]);
  77.     }
  78. }