<?php
namespace App\Controller\Front;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use App\Manager\LanguageManager;
class FrontController extends \App\Controller\BaseController
{
/**
* @Route("/", name="default_index")
*/
public function defaultIndex(Request $request, LanguageManager $lgMgr)
{
return $this->redirect('/fr', 302);
}
/**
* @Route("/{_locale}", name="index", requirements={"_locale":"fr|en"})
*/
public function index(Request $request, \App\Manager\ModuleManager $moduleMgr, LanguageManager $lgMgr)
{
$moduleHooked = $moduleMgr->getHook('homepage');
return $this->render('front/index.html.twig',[
'moduleHooked' => $moduleHooked
]);
}
/**
* @Route("/{_locale}/maintenance", name="maintenance", requirements={"_locale":"fr|en"})
*/
public function maintenance(Request $request)
{
return $this->render('front/maintenance.html.twig',[]);
}
/**
* @Route("/{_locale}/email/test", name="email_test", requirements={"_locale":"fr|en"})
*/
public function testEmail(\Doctrine\ORM\EntityManagerInterface $em, \App\Service\Mailer $mailer)
{
$rootCategories = $em->getRepository('App:Category')->getRoots();
$mailer->sendOrderConfirmation($order);
// return $this->render('mails/layout.html.twig',[
// 'rootCategories' => $rootCategories
// ]);
}
/**
* @Route("/{_locale}/email/order", name="email_order", requirements={"_locale":"fr|en"})
*/
public function orderEmail(\Doctrine\ORM\EntityManagerInterface $em, \App\Service\Mailer $mailer)
{
$order = $em->getRepository('App:Order')->find(90288);
$mailer->sendOrderConfirmation($order);
}
/**
* @Route("/send-email", name="sendemail")
*/
public function sendEmail(\Swift_Mailer $mailer)
{
$message = (new \Swift_Message('Hello Email'))
->setFrom('website@dogcat.com')
->setTo('qkaulek@gmail.com')
->setBody('You should see me from the profiler!');
$mailer->send($message);
return $this->redirectToRoute('index');
}
/**
* @Route("/change-locale/{_locale}", name="change_locale", requirements={"_locale=":"en|fr"})
*/
public function changeLocale(Request $request, LanguageManager $lgMgr)
{
$request->getSession()->set('_locale', $request->getLocale());
$lgMgr->switchTo($request->getLocale());
$redirect = $request->get('redirect',null);
if($redirect){
return $this->redirect($redirect);
}
return $this->redirectToRoute('index');
}
protected function getDiscountList($products)
{
$priceGroup = $this->cartMgr->getPriceContext();
$em = $this->getDoctrine()->getManager();
$data = [];
$prices = [];
foreach($products as $product) {
$parent = $product;
if($product->hasChildren() && $product->getFromProduct($priceGroup)) {
$product = $product->getFromProduct($priceGroup);
}
$discounts = $em->getRepository(\App\Entity\MarketingRule::class)->getByProduct($product, true);
if($discounts) {
foreach($discounts as $discount){
$price = $this->priceMgr->getPrice($product, 1, false);
if(empty($data[$parent->getId()]) || ($prices[$parent->getId()] > $price)) {
$prices[$parent->getId()] = $price;
$data[$parent->getId()] = $discount->getTitle();
}
}
}
}
return $data;
}
}