<?php
namespace App\Controller\Shop;
use App\Component\Order\OrderFactory;
use App\Component\Product\Model\Product;
use App\Component\Product\Repository\ProductRepository;
use App\Entity\Images;
use App\Form\ClearCartType;
use App\Form\SetDiscountType;
use App\Form\SetPaymentType;
use App\Form\SetShipmentType;
use App\Repository\AnnoncesRepository;
use App\Repository\ImagesRepository;
use App\Repository\WishListRepository;
use App\Service\CurrencyService;
use App\Service\TopUpService;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class HomeController extends AbstractController
{
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @Route({
* "fr": "/",
* "en": "/en"
* }, name="home1")
* @param Request $request
* @param CurrencyService $currency
*
*/
public function index(Request $request, ProductRepository $productRepository, OrderFactory $order, CurrencyService $currency, SessionInterface $session, WishListRepository $wishrepo, AuthenticationUtils $authenticationUtils): Response
{
$products = $productRepository->findProductByCat(1);
$products_2 = $productRepository->findProductByCat(2);
$products_3 = $productRepository->findProductByCat(3);
$products_4 = $productRepository->findProductByDate();
$products_5 = $productRepository->findProductByCat(5);
$products_6 = $productRepository->findProductByCat(6);
$products_7 = $productRepository->findAllAction();
/**
* @var User $user
*/
$user = $this->getUser();
$user_wish = (!is_null($user))?$wishrepo->countUserWishList($user->getId())["cnt"]:"";
$user_bookingValue = (!is_null($user))?((float)(base64_decode($user->getBookingValue()))):"0,00";
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$test1 = json_decode(json_encode($currency->getCurrencyConverter1()), true);
$clearForm = $this->createForm(ClearCartType::class, $order->getCurrent());
$setPaymentForm = $this->createForm(SetPaymentType::class, $order->getCurrent());
$setShipmentForm = $this->createForm(SetShipmentType::class, $order->getCurrent());
$setDiscountForm = $this->createForm(SetDiscountType::class, $order->getCurrent());
return $this->render('dogmo/index.html.twig', [
'userWish' => $user_wish,
'bookingValue'=>$user_bookingValue,
'products' => $products,
'products_2' => $products_2,
'products_3' => $products_3,
'products_4' => $products_4,
'products_5' => $products_5,
'products_6' => $products_6,
'products_7' => $products_7,
'last_username' => $lastUsername,
'locale'=>$request->getLocale(),
'error' => $error,
'order' => $order,
'currencie_convert' => $currency->getRate($session->get('converter')),
"converter" => (!empty($session->get('converter'))) ? $session->get('converter') : "EUR",
'clearForm' => $clearForm->createView(),
'setPaymentForm' => $setPaymentForm->createView(),
'setShipmentForm' => $setShipmentForm->createView(),
'setDiscountForm' => $setDiscountForm->createView(),
'itemsInCart' => $order->getCurrent()->getItemsTotal(),
'order_cat' => $order->getCurrent()->getCart_cat(),
]);
}
/**
* @Route("/converter", name="convert")
* @param Request $request
* @param SessionInterface $session
* @return Response
*/
public function indexConverter(Request $request, SessionInterface $session)
{
$sortbyconvert = $request->request->get('sortbyconvert');
if ($request) {
$session->set('converter', $sortbyconvert);
$session->set('ville',1);
$session->get('ville');
$session->get('converter');
}
return $this->redirect($request->server->get('HTTP_REFERER'));
}
/**
* @Route("/search-product", name="search_product")
* @param Request $request
* @param SessionInterface $session
* @return Response
*/
public function indexSearchProduct(Request $request, SessionInterface $session)
{
$categori2 = $request->request->get('categori2');
if ($request) {
$session->set('ville', $categori2);
$session->get('ville');
}
return $this->redirectToRoute('shop_detail');
}
/**
* @Route({
* "fr": "/Product-detail/{id}/{cat}/{img}",
* "en": "/Product-detail/{id}/{cat}/{img}/en"
* }, name="produit-detail")
* @param Request $request
* @param CurrencyService $currency
*
*/
public function indexDetail(Request $request, ImagesRepository $imgRepository, WishListRepository $wishrepo, AnnoncesRepository $annoncesRepository, $id, $cat, $img, CurrencyService $currency, ProductRepository $productRepository, OrderFactory $order, SessionInterface $session, AuthenticationUtils $authenticationUtils): Response
{
$products = $productRepository->findAll();
$repository = $this->getDoctrine()->getRepository(Images::class);
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$clearForm = $this->createForm(ClearCartType::class, $order->getCurrent());
$setPaymentForm = $this->createForm(SetPaymentType::class, $order->getCurrent());
$setShipmentForm = $this->createForm(SetShipmentType::class, $order->getCurrent());
$setDiscountForm = $this->createForm(SetDiscountType::class, $order->getCurrent());
$image_prod = $imgRepository->findByAnnoncesId($id);
$img_prod_detail = $imgRepository->findByAnnonceId($img);
$locale = $request->getLocale();
/**
* @var User $user
*/
$user = $this->getUser();
$user_wish = (!is_null($user))?$wishrepo->countUserWishList($user->getId())["cnt"]:"";
$user_bookingValue = (!is_null($user))?((float)(base64_decode($user->getBookingValue()))):"0,00";
$prod_detail = $productRepository->find($id);
if ($request->isXmlHttpRequest() && $request->isMethod('POST')) {
$cat = $_POST['cat'];
$magasin = $_POST['magasin'];
$currencie = $_POST['currencie'];
$converter = $_POST['converter'];
$locale = $_POST['locale'];
if (isset($_POST['page_h_l'])) {
$page = str_replace('"', '', json_encode($_POST['page_h_l']));
$load = $productRepository->loadPageLowToHigh($locale, $cat,$magasin, $page, $converter, $currencie);
} else {
$page = 0;
$load = $productRepository->loadPageLowToHigh($locale, $cat,$magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_l_h'])) {
$page = str_replace('"', '', json_encode($_POST['page_l_h']));
$load = $productRepository->loadPageHighToLow($locale, $cat,$magasin, $page, $converter, $currencie);
} else {
$page = 0;
$load = $productRepository->loadPageHighToLow($locale, $cat,$magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_n'])) {
$page = str_replace('"', '', json_encode($_POST['page_n']));
$load = $productRepository->loadPageNewste($locale, $cat,$magasin, $page, $converter, $currencie);
} else {
$page = 0;
$load = $productRepository->loadPageNewste($locale, $cat,$magasin, $page, $converter, $currencie);
}
return new JsonResponse($load);
} else {
$currenc = (!empty($session->get('converter'))) ? $session->get('converter') : "EUR";
$highPrice = $productRepository->searchHighAmount($cat);
$lowPrice = $productRepository->searchLowAmount($cat);
return $this->render('home/product-sidebar.html.twig', [
'error' => $error,
'last_username' => $lastUsername,
'prod_id' => $prod_detail->getId(),
'prod_name' => $prod_detail->getName(),
'prod_price' => $prod_detail->getPrice(),
'prod_content' => $prod_detail->getContent(),
'prod_image' => $prod_detail->getImage(),
'cart_cat' => $prod_detail->getCart_cat(),
'annonce_id' => $prod_detail->getUser_id(),
'img_prod_details' => $img_prod_detail,
'userWish' => $user_wish,
'bookingValue'=>$user_bookingValue,
'order_cat' => $order->getCurrent()->getCart_cat(),
'products_shop' => $productRepository->loadPageDetail($locale, $cat, 10, 0,0, $currenc, $currency->getRate($session->get('converter'))),
'highPrice' => $highPrice[0]["price"],
'lowPrice' => $lowPrice[0]["price"],
'cat' => $cat,
'currencie_convert' => $currency->getRate($session->get('converter')),
"converter" => (!empty($session->get('converter'))) ? $session->get('converter') : "EUR",
'products' => $products,
'order' => $order,
'clearForm' => $clearForm->createView(),
'setPaymentForm' => $setPaymentForm->createView(),
'setShipmentForm' => $setShipmentForm->createView(),
'setDiscountForm' => $setDiscountForm->createView(),
'itemsInCart' => $order->getCurrent()->getItemsTotal(),
]);
}
}
/**
* @Route({
* "fr": "/shop-detail",
* "en": "/shop-detail/en"
* },name="shop_detail" , methods={"GET","POST"})
* @param Request $request
* @param SessionInterface $session
* @param CurrencyService $currency
*
*/
public function shopDetail(Request $request, ProductRepository $productRepository, WishListRepository $wishrepo, OrderFactory $order, CurrencyService $currency, SessionInterface $session, AuthenticationUtils $authenticationUtils): Response
{
$ville = !empty($request->request->get('categori2'))?$request->request->get('categori2'):1;
$magasin = $request->request->get('select_magasin');
if ($ville == "Choisir une ville") {
$this->addFlash('error', 'Vous devez choisir une ville et ensuite un magasin dans cette ville!');
$referer = $request->headers->get('referer');
return $this->redirect($referer);
}
$session->set('cat_c1', $ville);
$session->get('cat_c1');
$locale = $request->getLocale();
$villeName = [1 => "Douala", 2 => "Yaoundé", 3 => "Bafoussam", 4 => "Mbouda", 10 => ""];
$magasinVille = [1 => [1 => "Supermarché Santa Lucia Ange Raphael", 2 => "Supermarché Dovy Douala", 3 => "Supermarché Dovy Douala", 4 => "Supermarché KDO Douala", 10 => "",0=>""] , 2 => [1 => "Supermarché Santa Lucia Yaoundé", 2 => "Supermarché Dovy Yaoundé", 3 => "Supermarché KDO Yaoundé", 4 => "Supermarché KDO Yaoundé", 10 => "",0=>""] , 3 => [1 => "Supermarché Santa Lucia Bafoussam", 2 => "Supermarché Dovy Bafoussam", 3 => "Supermarché KDO Bafoussam", 4 => "Supermarché KDO Bafoussam", 10 => "",0=>""], 4 => [1 => "Supermarché Santa Lucia Dschang", 2 => "Supermarché Dovy Dschang", 3 => "Supermarché Dovy Dschang", 4 => "Supermarché KDO Dschang", 5 => "",0=>""], 5 => [1 => "Supermarché Santa Lucia Mbouda", 2 => "Supermarché Dovy Mbouda", 3 => "Supermarché Dovy Mbouda", 4 => "Supermarché KDO Mbouda", 10 => "",0=>""]];
/**
* @var User $user
*/
$user = $this->getUser();
$user_wish = (!is_null($user))?$wishrepo->countUserWishList($user->getId())["cnt"]:"";
$user_bookingValue = (!is_null($user))?((float)(base64_decode($user->getBookingValue()))):"0,00";
$cat= [$ville];
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$clearForm = $this->createForm(ClearCartType::class, $order->getCurrent());
$setPaymentForm = $this->createForm(SetPaymentType::class, $order->getCurrent());
$setShipmentForm = $this->createForm(SetShipmentType::class, $order->getCurrent());
$setDiscountForm = $this->createForm(SetDiscountType::class, $order->getCurrent());
if ($request->isXmlHttpRequest() && $request->isMethod('POST')) {
$cat = $_POST['cat'];
$magasin = $_POST['magasin'];
$currencie = $_POST['currencie'];
$converter = $_POST['converter'];
$locale = $_POST['locale'];
if (isset($_POST['page_no'])) {
$page = str_replace('"', '', json_encode($_POST['page_no']));
$load = $productRepository->loadPage($locale, $cat,$magasin, $page, $converter, $currencie);
} else {
$page = 0;
$load = $productRepository->loadPage($locale, $cat, $magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_h_l'])) {
$page = str_replace('"', '', json_encode($_POST['page_h_l']));
$load = $productRepository->loadPageLowToHigh($locale, $cat,$magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_l_h'])) {
$page = str_replace('"', '', json_encode($_POST['page_l_h']));
$load = $productRepository->loadPageHighToLow($locale, $cat,$magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_n'])) {
$page = str_replace('"', '', json_encode($_POST['page_n']));
$load = $productRepository->loadPageNewste($locale, $cat,$magasin, $page, $converter, $currencie);
}
return new JsonResponse($load);
} else {
$session->set('highPrice_value', $productRepository->searchHighAmount($session->get('cat_c1'))[0]["price"]);
$session->set('lowPrice_value', $productRepository->searchLowAmount($session->get('cat_c1'))[0]["price"]);
$currenc = (!empty($session->get('converter'))) ? $session->get('converter') : "EUR";
return $this->render('home/shop-detail.html.twig', [
'userWish' => $user_wish,
'bookingValue'=>$user_bookingValue,
'highPrice' => $session->get('highPrice_value'),
'lowPrice' => $session->get('lowPrice_value'),
'order' => $order,
'error' => $error,
'villeMagsin'=> ($magasinVille[$ville][$magasin])?$magasinVille[$ville][$magasin] : $magasinVille[1][0],
'last_username' => $lastUsername,
'products_shop' => '',
'currencie_convert' => $currency->getRate($session->get('converter')),
"converter" => (!empty($session->get('converter'))) ? $session->get('converter') : "EUR",
'locale' => $request->getLocale(),
'clearForm' => $clearForm->createView(),
'cat' => $cat,
'ville'=>$session->get('cat_c1') ,
'magasin' => $magasin,
'order_cat' => $order->getCurrent()->getCart_cat(),
'setPaymentForm' => $setPaymentForm->createView(),
'setShipmentForm' => $setShipmentForm->createView(),
'setDiscountForm' => $setDiscountForm->createView(),
'itemsInCart' => $order->getCurrent()->getItemsTotal(),
]);
}
}
/**
* @Route({
* "fr": "/shop-detail/{ville}/{magasin}/{categorie}/{type}",
* "en": "/shop-detail/{ville}/{magasin}/{categorie}/{type}/en"
* },name="shop_detail_ville" )
* @param Request $request
* @param SessionInterface $session
* @param CurrencyService $currency
*
*/
public function shopDetailVille(Request $request, $ville, $magasin, $type, $categorie, ProductRepository $productRepository, WishListRepository $wishrepo, OrderFactory $order, CurrencyService $currency, SessionInterface $session, AuthenticationUtils $authenticationUtils): Response
{
if ($ville == "Choisir une ville") {
$this->addFlash('error', 'Vous devez choisir une ville et ensuite un magasin dans cette ville!');
$referer = $request->headers->get('referer');
return $this->redirect($referer);
}
$session->set('cat_c1', $ville);
$session->get('cat_c1');
$locale = $request->getLocale();
$villeName = [1 => "Douala", 2 => "Yaoundé", 3 => "Bafoussam", 4 => "Mbouda", 10 => ""];
$magasinVille = [1 => [0=> $this->translator->trans('app.home.africa_shopping_ville')." douala ", 1 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Santa Lucia Ange Raphael", 2 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Douala", 3 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Douala", 4 => $this->translator->trans('app.home.africa_shopping_supermarkt')." KDO Douala", 10 => ""] , 2 => [0=>$this->translator->trans('app.home.africa_shopping_ville')." yaoundé ",1 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Santa Lucia Yaoundé", 2 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Yaoundé", 3 => $this->translator->trans('app.home.africa_shopping_supermarkt')." KDO Yaoundé", 4 => $this->translator->trans('app.home.africa_shopping_supermarkt')." KDO Yaoundé", 10 => ""] , 3 => [0=>$this->translator->trans('app.home.africa_shopping_ville')." bafoussam ",1 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Santa Lucia Bafoussam", 2 =>$this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Bafoussam", 3 => $this->translator->trans('app.home.africa_shopping_supermarkt')." KDO Bafoussam", 4 => $this->translator->trans('app.home.africa_shopping_supermarkt')." KDO Bafoussam", 10 => ""], 4 => [0=>$this->translator->trans('app.home.africa_shopping_ville')." dschang ",1 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Santa Lucia Dschang", 2 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Dschang", 3 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Dschang", 4 => $this->translator->trans('app.home.africa_shopping_supermarkt')." KDO Dschang", 5 => ""], 5 => [0=>$this->translator->trans('app.home.africa_shopping_ville')." mbouda ",1 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Santa Lucia Mbouda", 2 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Mbouda", 3 => $this->translator->trans('app.home.africa_shopping_supermarkt')." Dovy Mbouda", 4 => $this->translator->trans('app.home.africa_shopping_supermarkt')." KDO Mbouda", 10 => ""]];
/**
* @var User $user
*/
$user = $this->getUser();
$user_wish = (!is_null($user))?$wishrepo->countUserWishList($user->getId())["cnt"]:"";
$user_bookingValue = (!is_null($user))?((float)(base64_decode($user->getBookingValue()))):"0,00";
$cat= [$ville];
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$clearForm = $this->createForm(ClearCartType::class, $order->getCurrent());
$setPaymentForm = $this->createForm(SetPaymentType::class, $order->getCurrent());
$setShipmentForm = $this->createForm(SetShipmentType::class, $order->getCurrent());
$setDiscountForm = $this->createForm(SetDiscountType::class, $order->getCurrent());
if ($request->isXmlHttpRequest() && $request->isMethod('POST')) {
$cat = $_POST['cat'];
$currencie = $_POST['currencie'];
$converter = $_POST['converter'];
$locale = $_POST['locale'];
if (isset($_POST['page_no'])) {
$page = str_replace('"', '', json_encode($_POST['page_no']));
$load = $productRepository-> loadPage($locale, $cat, $magasin, $page, $converter, $currencie);
} else {
$page = 0;
$load = $productRepository->loadPage($locale, $cat, $magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_h_l'])) {
$page = str_replace('"', '', json_encode($_POST['page_h_l']));
$load = $productRepository->loadPageLowToHigh($locale, $cat,$magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_l_h'])) {
$page = str_replace('"', '', json_encode($_POST['page_l_h']));
$load = $productRepository->loadPageHighToLow($locale, $cat,$magasin, $page, $converter, $currencie);
}
if (isset($_POST['page_n'])) {
$page = str_replace('"', '', json_encode($_POST['page_n']));
$load = $productRepository->loadPageNewste($locale, $cat,$magasin, $page, $converter, $currencie);
}
return new JsonResponse($load);
} else {
$session->set('highPrice_value', $productRepository->searchHighAmount($session->get('cat_c1'))[0]["price"]);
$session->set('lowPrice_value', $productRepository->searchLowAmount($session->get('cat_c1'))[0]["price"]);
$currenc = (!empty($session->get('converter'))) ? $session->get('converter') : "EUR";
return $this->render('home/shop-detail.html.twig', [
'userWish' => $user_wish,
'bookingValue'=>$user_bookingValue,
'highPrice' => $session->get('highPrice_value'),
'lowPrice' => $session->get('lowPrice_value'),
'order' => $order,
'error' => $error,
'villeMagsin'=> $magasinVille[$ville][$magasin],
'last_username' => $lastUsername,
'products_shop' => $productRepository->loadPageDetail($locale, $ville, 40, $categorie, $type, $currenc, $currency->getRate($session->get('converter'))),
'currencie_convert' => $currency->getRate($session->get('converter')),
"converter" => (!empty($session->get('converter'))) ? $session->get('converter') : "EUR",
'locale' => $request->getLocale(),
'clearForm' => $clearForm->createView(),
'cat' => $cat,
'magasin' => $magasin,
'categorie' => $categorie,
'type' => $type,
'ville' =>$ville,
'order_cat' => $order->getCurrent()->getCart_cat(),
'setPaymentForm' => $setPaymentForm->createView(),
'setShipmentForm' => $setShipmentForm->createView(),
'setDiscountForm' => $setDiscountForm->createView(),
'itemsInCart' => $order->getCurrent()->getItemsTotal(),
]);
}
}
/**
* @Route("/setsearch", name="search_page", methods={"POST"})
*/
public function setSearchPage(Request $request, ProductRepository $productRepository)
{
$cat = $_POST['cat'];
$currencie = $_POST['currencie'];
$converter = $_POST['converter'];
$locale = $_POST['locale'];
$datasearch = str_replace('"', '', json_encode($_POST['query']));
$searchpage = $productRepository->searchPage($datasearch, $cat);
$jsonDatax = [];
$idx = 0;
$currency = [];
$currency["EUR"] = "€";
$currency["USD"] = "$";
$currency["GBP"] = "£";
$currency["CAD"] = "c$";
$currency["XAF"] = "FCFA";
for ($i = 0; $i < count($searchpage); $i++){
$temp = [
'name' => $searchpage[$i]['name'],
'cart_cat' => $searchpage[$i]['cart_cat'],
'type' => $searchpage[$i]['type'],
'type1' => $searchpage[$i]['type1'],
'id' => $searchpage[$i]['id'],
'currencie' => $currency[$converter],
'image' => $searchpage[$i]['image'],
'price' => ($currencie == 'EUR') ? $searchpage[$i]['price'] : (number_format($searchpage[$i]['price'] * $currencie, 2, ',', ' ')),
];
$jsonDatax[$idx++] = $temp;
}
return new JsonResponse($jsonDatax);
}
/**
* @Route("/setslider", name="searchslider", methods={"POST"})
*/
public function setSearchSlider(Request $request, ProductRepository $productRepository)
{
$cat = $_POST['cat'];
$currencie = $_POST['currencie'];
$converter = $_POST['converter'];
$locale = $_POST['locale'];
if (isset($_POST['minAge'])) {
$minAge = str_replace('"', '', json_encode($_POST['minAge']));
$maxAge = str_replace('"', '', json_encode($_POST['maxAge']));
$load = $productRepository->loadSlider($minAge, $maxAge, $locale, $cat, $converter, $currencie);
}else{
$minAge = 10;
$maxAge = 1234;
$load = $productRepository->loadSlider($minAge, $maxAge, $locale, $cat, $converter, $currencie);
}
return new JsonResponse($load);
}
}