<?php
namespace App\Controller;
use App\Entity\LandingPage;
use App\Entity\SubProduct;
use App\Entity\User;
use App\Form\Handler\RegisterHandler;
use App\Form\Type\RegisterType;
use App\Helper\VeltisControllerTrait;
use App\Repository\ProductRepository;
use App\Services\CartService;
use App\Services\UserService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
class LandingPageController extends AbstractController
{
use VeltisControllerTrait;
/**
* @Route("/lp/{id}/{slug}/{product}", name="landing-page-front", defaults={"product":null})
*/
public function registerAction(Request $request, UserService $userService, CartService $cartService, SessionInterface $session, TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher, ProductRepository $productRepository)
{
/** @var $landingPage LandingPage */
$landingPage = $this->em()->getRepository(\App\Entity\LandingPage::class)->find($request->attributes->get('id'));
if ($landingPage->getRedirect()) {
return new RedirectResponse($landingPage->getRedirect(), 301);
}
$products = $productRepository->getForLandingPage($landingPage, ['locale'=>$landingPage->getLanguage()->getLocale()])->getQuery()->getResult();
$productsForProducer = [];
if ($landingPage->getProductProducer()) {
$productsForProducer = $productRepository->getForLandingPageProductProducer($landingPage, ['locale'=>$landingPage->getLanguage()->getLocale()])->getQuery()->getResult();
}
if ($landingPage->getSpecialForBuyCheaper()) {
$products = $productRepository->getForSpecialLandingPage($landingPage, ['locale'=>$landingPage->getLanguage()->getLocale()])->getQuery()->getResult();
$p = [];
foreach ($products as $product) {
/** @var $sub SubProduct */
foreach ($product[0]->getSubProducts() as $sub) {
if ($sub->getActive() && $sub->getDeletedBy() === null) {
$temp = $product;
$temp['mainPhoto'] = $product[0]->getMainPhoto();
$temp['subName'] = $sub->getName();
$temp['subPrice'] = $sub->getPrice();
$temp['subRebate'] = $sub->getRebate();
$temp['subId'] = $sub->getId();
$temp['beforeDiscount'] = $sub->getBeforeDiscountPrice();
$p[] = $temp;
}
}
}
$products = $p;
}
$currency = $landingPage->getLanguage()->getCurrency();
$productEntity = null;
if ($request->attributes->get('product')) {
$productEntity = $this->em()->getRepository(\App\Entity\Product::class)->find($request->attributes->get('product'));
}
return $this->render('frontend/landingPage/landingPage.html.twig', [
'landingPage' => $landingPage,
'productEntity'=>$productEntity,
'currency' => $currency,
'language' => $landingPage->getLanguage(),
'product' => $request->attributes->get('product'),
'products' => $products,
'productsForProducer' => $productsForProducer,
]);
}
}