src/Controller/EntrepriseController.php line 392

Open in your IDE?
  1. <?php
  2. // src/Controller/EntrepriseController.php
  3. namespace App\Controller;
  4. use App\Entity\SujetFAQ;
  5. use App\Entity\Article;
  6. use App\Entity\AppUser;
  7. use App\Entity\Product;
  8. use App\Entity\Review;
  9. use App\Entity\Category;
  10. use App\Entity\Order;
  11. use App\Entity\SlidePromo;
  12. use App\Entity\ProductOrder;
  13. use App\Entity\Entreprise;
  14. use App\Entity\ProductMisDeCote;
  15. use App\Entity\SubCategory;
  16. use App\Entity\AvisUtilisateur;
  17. use App\Form\SujetFAQType;
  18. use App\Form\AvisUtilisateurType;
  19. use App\Form\AvisUtilisateurEditType;
  20. use App\Form\ProductType;
  21. use App\Entity\ShippingMethod;
  22. use App\Entity\AbonneNewsletter;
  23. use App\Entity\SideBox;
  24. use App\Entity\ProductCollection;
  25. use App\Entity\HomeCollection;
  26. use App\Entity\Coupon;
  27. use App\Services\CinetPay;
  28. use App\Entity\WishListProduct;
  29. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  30. use Symfony\Component\HttpFoundation\Response;
  31. use Symfony\Component\HttpFoundation\JsonResponse;
  32. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  35. use Symfony\Component\Routing\Annotation\Route;
  36. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  37. /**
  38.  * @Route("/")
  39.  */
  40. class EntrepriseController extends AbstractController
  41. {    
  42.     private $session;
  43.     
  44.     public function __construct(SessionInterface $session)
  45.     {
  46.         $this->session $session;
  47.     }
  48.     
  49.     /**
  50.      * @Route("/", name="home")
  51.      */
  52.     public function homeAction()
  53.     {
  54.         $requestStack $this->get('request_stack');
  55.         $request $requestStack->getCurrentRequest();
  56.     
  57.         $em $this->getDoctrine()
  58.                     ->getManager();
  59.         
  60.         $avisUtilisateurs $em->getRePository(AvisUtilisateur::class)
  61.                          ->findBy(
  62.                                 array(),
  63.                                 array(),
  64.                                 10//nb De resultats
  65.                                 //A partir de 0
  66.                               );
  67.         
  68.         $products $em->getRePository(Product::class)
  69.                          ->findBy(
  70.                          array(
  71.                          ),
  72.                          array(
  73.                             'id' => 'DESC'
  74.                          ),
  75.                          30,
  76.                          0
  77.                          );
  78.                          
  79.         $rightBoxes $em->getRePository(SideBox::class)
  80.                          ->findBy(
  81.                          array(
  82.                          'position' => 'Right'
  83.                          )
  84.                          
  85.                          );
  86.         $leftBoxes $em->getRePository(SideBox::class)
  87.                          ->findBy(
  88.                          array(
  89.                          'position' => 'Left'
  90.                          )
  91.                          
  92.                          );
  93.         $collections = array(
  94.             
  95.         );
  96.         
  97.         $homeCollections $em->getRePository(HomeCollection::class)
  98.                          ->findAll();
  99.         foreach($homeCollections as $homeCollection){
  100.             
  101.             
  102.             $productCollections $em->getRePository(ProductCollection::class)
  103.                          ->findBy(
  104.                             array('homeCollection' => $homeCollection->getId()
  105.                                 ),
  106.                                 array(),
  107.                                 $homeCollection->getItemNumber(),
  108.                                 0
  109.                          );
  110.             $products = array();
  111.             $photos = array();
  112.             foreach($productCollections as $productCollection){
  113.                 $p $productCollection->getProduct();
  114.                 $p->setTranslatableLocale($request->getLocale());
  115.                 $em->refresh($p);
  116.                 array_push($products$p);
  117.             }
  118.             $el = array(
  119.                 'nom' =>  $homeCollection->getNom(),
  120.                 'isPromotional' =>  $homeCollection->getIsPromotional(),
  121.                 'theLink' =>  $homeCollection->getTheLink(),
  122.                 'slug' =>  $homeCollection->getSlug(),
  123.                 'photos' => $homeCollection->getPhotos(),
  124.                 'products' => $products,
  125.             );
  126.             $collections[] = $el;
  127.         }
  128.         
  129.           return $this->render('entreprise/home.html.twig', [
  130.             'avisUtilisateurs' => $avisUtilisateurs,
  131.             'products' => $products,
  132.             'rightBoxes' => $rightBoxes,
  133.             'leftBoxes' => $leftBoxes,
  134.             'collections' => $collections
  135.         ]);
  136.     }
  137.     
  138.     /**
  139.      * @Route("/collection/{slug}/{page}/{currentPage}", name="product_by_collection")
  140.      */
  141.     public function productByCollectionAction(HomeCollection $homeCollection$page='page'$currentPage 1)
  142.     {
  143.         $em $this->getDoctrine()->getManager();
  144.         $numberByPage 5;
  145.         
  146.         $em $this->getDoctrine()
  147.                     ->getManager();
  148.         $produitCollections $em->getRePository(ProductCollection::class)
  149.                         ->findProductByHomeCollection($numberByPage$currentPage$homeCollection->getId());
  150.                         
  151.         $pageAmount ceil((count($produitCollections))/$numberByPage) ;
  152.         if(($currentPage $pageAmount && $pageAmount >= 1) || $currentPage <=0){
  153.             throw $this->createNotFoundException('Nombre invalide');
  154.         }    
  155.         
  156.         $products = array();
  157.         
  158.         foreach($produitCollections as $produitCollection){
  159.             array_push($products$produitCollection->getProduct());
  160.         }
  161.         
  162.         return $this->render('entreprise/product_by_collection.html.twig', [
  163.             'products' => $products,
  164.             'currentPage' => $currentPage,
  165.             'pageAmount' => $pageAmount,
  166.             'homeCollection' => $homeCollection
  167.         ]);
  168.     }
  169.     
  170.     /**
  171.      * @Route("/profile", name="profile")
  172.      */
  173.     public function profileAction()
  174.     {
  175.         $em $this->getDoctrine()
  176.                     ->getManager();
  177.         
  178.         $requestStack $this->get('request_stack');
  179.         $request $requestStack->getCurrentRequest();
  180.     
  181.         $ok_submission '';
  182.         $user $this->getUser();
  183.         $pageTitle 'Mon profil';
  184.         if('POST' == $request->getMethod() )
  185.         {
  186.             $email $request->request->get('email');
  187.             
  188.         
  189.         }     
  190.         return $this->render('entreprise/profile.html.twig', [
  191.             'user' => $user,
  192.             'pageTitle' => $pageTitle
  193.         ]);
  194.     }
  195.     
  196.     /**
  197.      * @Route("/orders", name="user_orders")
  198.      */
  199.     public function userOrdersAction()
  200.     {
  201.         $em $this->getDoctrine()
  202.                     ->getManager();
  203.         
  204.         $requestStack $this->get('request_stack');
  205.         $request $requestStack->getCurrentRequest();
  206.     
  207.         $ok_submission '';
  208.         $user $this->getUser();
  209.         $pageTitle 'Mes orders';
  210.         $orders $em->getRePository(Order::class)
  211.                     ->findByUser($user); 
  212.         return $this->render('entreprise/orders.html.twig', [
  213.             'user' => $user,
  214.             'orders' => $orders,
  215.             'pageTitle' => $pageTitle
  216.         ]);
  217.     }
  218.     
  219.     /**
  220.     * @Route("/product-order/{id}", name="products_by_order")
  221.      */
  222.     public function productsByOrderAction(Order $order)
  223.     {
  224.         $em $this->getDoctrine()
  225.                     ->getManager();
  226.         
  227.         $productOrders $em->getRePository(ProductOrder::class)
  228.                             ->findByOrder($order->getId());
  229.         $pageTitle 'DĂ©tails order';
  230.         
  231.         $user $this->getUser();
  232.         return $this->render('entreprise/products_by_order.html.twig', [
  233.             'productOrders' => $productOrders,
  234.             'user' => $user,
  235.             'pageTitle' => $pageTitle
  236.         ]);
  237.     }
  238.     
  239.     /**
  240.      * @Route("/my-wishlist", name="user_wishlist")
  241.      */
  242.     public function wishlistAction()
  243.     {
  244.         $em $this->getDoctrine()
  245.                     ->getManager();
  246.         
  247.         $requestStack $this->get('request_stack');
  248.         $request $requestStack->getCurrentRequest();
  249.     
  250.         $ok_submission '';
  251.         $user $this->getUser();
  252.         $pageTitle 'Product mis de cĂ´tĂ©';
  253.         $produitMisDeCotes $em->getRePository(WishListProduct::class)
  254.                                 ->findByUser($user);
  255.         return $this->render('entreprise/my_wishlist.html.twig', [
  256.             'user' => $user,
  257.             'pageTitle' => $pageTitle,
  258.             'produitMisDeCotes' => $produitMisDeCotes
  259.         ]);
  260.     }
  261.     
  262.     /**
  263.      * @Route("/add-product-to-wishlist/{id}", name="add_product_to_wishlist")
  264.      */
  265.     public function addProductToWishlistAction(Product $product)
  266.     {
  267.         $em $this->getDoctrine()
  268.                     ->getManager();
  269.         $ok_submission '';
  270.         $user $this->getUser();
  271.         if(null == $user ){
  272.             $ok_submission 'Veuillez vous connecter d\'abord';
  273.         }     else{
  274.             $ok_submission 'Product mis de cĂ´tĂ©';
  275.             $productMisDeCote = new ProductMisDeCote;
  276.             $productMisDeCote->setProduct($product);
  277.             $productMisDeCote->setUser($user);
  278.             
  279.             $em->persist($productMisDeCote);
  280.             $em->flush();
  281.         }
  282.         
  283.         
  284.         $response = new Response;
  285.         $response->setStatusCode(Response::HTTP_OK);
  286.         $response->setContent($ok_submission);
  287.         return $response;
  288.         
  289.     }
  290.     
  291.     /**
  292.      * @Route("/remove-product-from-wishlist/{id}", name="remove_product_from_wishlist")
  293.      */
  294.     public function removeProductFromWishlistAction(Product $product)
  295.     {
  296.         $em $this->getDoctrine()
  297.                     ->getManager();
  298.         $ok_submission '';
  299.         $user $this->getUser();
  300.         $productMisDeCote $em->getRePository(ProductMisDeCote::class)
  301.                                 ->findOneBy(
  302.                                     array(
  303.                                     'product' => $product->getId(),
  304.                                     'user' => $user->getId()
  305.                                     )
  306.                                 );
  307.         if(null != $productMisDeCote){
  308.             $em->remove($productMisDeCote);
  309.             $em->flush();
  310.         }
  311.         
  312.         return $this->redirectToRoute('user_wishlist');
  313.         
  314.     }
  315.     
  316.     /**
  317.      * @Route("/your-password", name="user_password")
  318.      */
  319.     public function userPasswordAction()
  320.     {
  321.         $em $this->getDoctrine()
  322.                     ->getManager();
  323.         
  324.         $requestStack $this->get('request_stack');
  325.         $request $requestStack->getCurrentRequest();
  326.     
  327.         $ok_submission '';
  328.         $user $this->getUser();
  329.         $pageTitle 'Mot de passe';
  330.         if('POST' == $request->getMethod() )
  331.         {
  332.             $email $request->request->get('email');
  333.             
  334.         
  335.         }     
  336.         return $this->render('entreprise/user_password.html.twig', [
  337.             'user' => $user,
  338.             'pageTitle' => $pageTitle
  339.         ]);
  340.     }
  341.     
  342.     /**
  343.      * @Route("/s-abonner-newsletter", name="s_abonner_newsletter")
  344.      */
  345.     public function sAbonnerNewsletterAction()
  346.     {
  347.         $em $this->getDoctrine()
  348.                     ->getManager();
  349.         
  350.         $requestStack $this->get('request_stack');
  351.         $request $requestStack->getCurrentRequest();
  352.     
  353.         $ok_submission '';
  354.         $user $this->getUser();
  355.         if('POST' == $request->getMethod() )
  356.         {
  357.             $email $request->request->get('email');
  358.             
  359.             $unAbonne $em->getRePository(AbonneNewsletter::class)
  360.                          ->findOneByEmail($email);
  361.             if(null == $unAbonne){
  362.                 $unAbonne = new AbonneNewsletter;
  363.                 $unAbonne->setEmail($email);
  364.                 $em->persist($unAbonne);
  365.                 $em->flush();
  366.                 $ok_submission 'Enregistrement effectuĂ©';
  367.             } else{
  368.                 
  369.                 $ok_submission 'DejĂ  inscrit';
  370.             } 
  371.                 
  372.         }     
  373.         $response = new Response;
  374.         $response->setStatusCode(Response::HTTP_OK);
  375.         $response->setContent($ok_submission);
  376.         return $response;
  377.     }
  378.     
  379.     
  380.     /**
  381.      * @Route("/home-slides", name="home_slides")
  382.      */
  383.     public function homeSlidesAction()
  384.     {
  385.         $em $this->getDoctrine()
  386.                     ->getManager();
  387.         
  388.         $slides $em->getRePository(SlidePromo::class)
  389.                          ->findBy(
  390.                                 array(
  391.                                     'estActif' => true
  392.                                 )
  393.                                 
  394.                               );                 
  395.           return $this->render('entreprise/slide.html.twig', [
  396.             'slides' => $slides
  397.         ]);
  398.     }
  399.     
  400.     /**
  401.      * @Route("/a-propos", name="a_propos")
  402.      */
  403.     public function aProposAction()
  404.     {
  405.         
  406.           return $this->render('entreprise/a_propos.html.twig', [
  407.             
  408.         ]);
  409.     }
  410.     
  411.     /**
  412.      * @Route("/term", name="term")
  413.      */
  414.     public function termAction()
  415.     {
  416.         $em $this->getDoctrine()
  417.                     ->getManager();
  418.                     
  419.         $entreprise $em->getRePository(Entreprise::class)
  420.                         ->findAll();
  421.                         
  422.           return $this->render('entreprise/term.html.twig', [
  423.             'entreprise' => $entreprise
  424.         ]);
  425.     }
  426.     
  427.     /**
  428.      * @Route("/privacy", name="privacy")
  429.      */
  430.     public function privacyAction()
  431.     {
  432.         $em $this->getDoctrine()
  433.                     ->getManager();
  434.                     
  435.         $entreprise $em->getRePository(Entreprise::class)
  436.                         ->findAll();
  437.                         
  438.           return $this->render('entreprise/privacy.html.twig', [
  439.             'entreprise' => $entreprise
  440.         ]);
  441.     }
  442.     
  443.     /**
  444.      * @Route("/about", name="about")
  445.      */
  446.     public function aboutAction()
  447.     {
  448.         $em $this->getDoctrine()
  449.                     ->getManager();
  450.                     
  451.         $entreprise $em->getRePository(Entreprise::class)
  452.                         ->findAll();
  453.                         
  454.           return $this->render('entreprise/about.html.twig', [
  455.             'entreprise' => $entreprise
  456.         ]);
  457.     }
  458.     
  459.     
  460.     /**
  461.      * @Route("/menu-principal", name="menu_principal")
  462.      */
  463.     public function menuPrincipalAction()
  464.     {
  465.         $em $this->getDoctrine()
  466.                     ->getManager();
  467.         $categories $em->getRePository(Category::class)
  468.                         ->findAll();
  469.           return $this->render('entreprise/menu_principal.html.twig', [
  470.             'categories' => $categories
  471.         ]);
  472.     }
  473.     
  474.     /**
  475.      * @Route("/home-menu", name="home_menu")
  476.      */
  477.     public function homeMenuAction()
  478.     {
  479.         $em $this->getDoctrine()
  480.                     ->getManager();
  481.         $categories $em->getRePository(Category::class)
  482.                         ->findAll();
  483.           return $this->render('entreprise/home_menu.html.twig', [
  484.             'categories' => $categories
  485.         ]);
  486.     }
  487.     
  488.     /**
  489.      * @Route("/all-categories", name="all_categories")
  490.      */
  491.     public function allCategoriesAction()
  492.     {
  493.         $em $this->getDoctrine()
  494.                     ->getManager();
  495.         $categories $em->getRePository(Category::class)
  496.                         ->findAll();
  497.           return $this->render('entreprise/all_categories.html.twig', [
  498.             'categories' => $categories
  499.         ]);
  500.     }
  501.     
  502.     /**
  503.      * @Route("/menu", name="menu")
  504.      */
  505.     public function menuAction()
  506.     {
  507.         $em $this->getDoctrine()
  508.                     ->getManager();
  509.         $categories $em->getRePository(Category::class)
  510.                         ->findAll();
  511.           return $this->render('entreprise/menu.html.twig', [
  512.             'categories' => $categories
  513.         ]);
  514.     }
  515.     
  516.     /**
  517.      * @Route("/category/{slug/{paginer}/{pageCourante}", name="product_par_categorie")
  518.      */
  519.     public function productRecentAction($paginer='page'$pageCourante 1)
  520.     {
  521.         $em $this->getDoctrine()
  522.                     ->getManager();
  523.                     
  524.         $products $em->getRePository(Products::class)
  525.                         ->findAll();
  526.         $productNumber 10;
  527.         
  528.         $products $em->getRePository(Product::class)
  529.                         ->getProducts($productNumber$pageCourante);
  530.         
  531.                 
  532.         return $this->render('entreprise/menu_principal.html.twig', [
  533.             'categories' => $categories
  534.         ]);
  535.     }
  536.     
  537.     /**
  538.      * @Route("/category/{slug/{paginer}/{pageCourante}", name="product_par_categorie")
  539.      */
  540.     public function productParCategorieAction($paginer='page'$pageCourante 1)
  541.     {
  542.         $em $this->getDoctrine()
  543.                     ->getManager();
  544.                     
  545.         $categories $em->getRePository(Category::class)
  546.                         ->findAll();
  547.         $productNumber 10;
  548.         
  549.         $products $em->getRePository(Product::class)
  550.                         ->getProducts($productNumber$pageCourante);
  551.         
  552.                 
  553.         return $this->render('entreprise/menu_principal.html.twig', [
  554.             'categories' => $categories
  555.         ]);
  556.     }
  557.     
  558.     
  559.     /**
  560.      * @Route("/galerie", name="galerie")
  561.      */
  562.     public function galerieAction()
  563.     {
  564.         
  565.           return $this->render('entreprise/galerie.html.twig', [
  566.             
  567.         ]);
  568.     }
  569.     
  570.     
  571.     /**
  572.      * @Route("/partenaire", name="partenaire")
  573.      */
  574.     public function partenaireAction()
  575.     {
  576.         
  577.           return $this->render('entreprise/partenaire.html.twig', [
  578.             
  579.         ]);
  580.     }
  581.     
  582.     
  583.     /**
  584.      * @Route("/services", name="services")
  585.      */
  586.     public function servicesAction()
  587.     {
  588.         
  589.           return $this->render('entreprise/services.html.twig', [
  590.             
  591.         ]);
  592.     }
  593.     
  594.     
  595.     /**
  596.      * @Route("/product/{leSlug}", name="display_product")
  597.      */
  598.     public function displayProductAction(Product $product)
  599.     {
  600.         $em $this->getDoctrine()
  601.                     ->getManager();
  602.                     
  603.         $requestStack $this->get('request_stack');
  604.         $request $requestStack->getCurrentRequest();
  605.     
  606.         $product->setTranslatableLocale($request->getLocale());
  607.         $em->refresh($product);
  608.         
  609.         $reviews $em->getRePository(Review::class)
  610.                     ->findByProduct($product);
  611.         $ok_submission '';
  612.         
  613.         $user $this->getUser();
  614.         if('POST' == $request->getMethod() )
  615.         {
  616.             
  617.             $review = new Review;
  618.             $rating $request->request->get('rating');
  619.             $note $request->request->get('review');
  620.             
  621.             $review->setReview($note);
  622.             $review->setRating($rating);
  623.             $review->setProduct($product);
  624.             $review->setUser($user);
  625.             $em->persist($review);
  626.             $em->flush();
  627.             $ok_submission 'Enregistrement effectuĂ©';
  628.                 
  629.         }
  630.         $moyenneRating 0;
  631.         $recommandationNumber 0;
  632.         $i 0;
  633.         $fiveStar = array('number' => 0'pourcentage' => 0);
  634.         $fourStar = array('number' => 0'pourcentage' => 0);
  635.         $threeStar = array('number' => 0'pourcentage' => 0);
  636.         $twoStar = array('number' => 0'pourcentage' => 0);
  637.         $oneStar = array('number' => 0'pourcentage' => 0);
  638.         $rating 0;
  639.         foreach($reviews as $review){
  640.             $i++;
  641.             $rating += $review->getRating();
  642.             if($rating 2){
  643.                 $recommandationNumber++;
  644.             }
  645.             switch ($rating){
  646.                 case 1;
  647.                 $oneStar['number']++;
  648.                 break;
  649.                 case 2;
  650.                 $twoStar['number']++;
  651.                 break;
  652.                 case 3;
  653.                 $threeStar['number']++;
  654.                 break;
  655.                 case 4;
  656.                 $fourStar['number']++;
  657.                 break;
  658.                 case 5;
  659.                 $fiveStar['number']++;
  660.                 break;
  661.             }
  662.         }
  663.         if( $i ){
  664.             $moyenneRating $rating/$i;
  665.         }
  666.         $shippingMethods $em->getRePository(ShippingMethod::class)
  667.                             ->findAll();
  668.         $reviewNumber count($reviews);        
  669.           return $this->render('entreprise/display_product.html.twig', [
  670.             'product' => $product,
  671.             'ok_submission' => $ok_submission,
  672.             'reviews' => $reviews,
  673.             'reviewNumber' => $reviewNumber,
  674.             'shippingMethods' => $shippingMethods,
  675.             'moyenneRating' => $moyenneRating,
  676.             'recommandationNumber' => $recommandationNumber,
  677.             'fiveStar' => $fiveStar,
  678.             'fourStar' => $fourStar,
  679.             'threeStar' => $threeStar,
  680.             'twoStar' => $twoStar,
  681.             'oneStar' => $oneStar,
  682.         ]);
  683.     }
  684.     
  685.     /**
  686.      * @Route("/c/{slug}/{page}/{currentPage}", name="product_by_category")
  687.      */
  688.     public function productByCategoryAction(Category $category$page='page'$currentPage 1)
  689.     {
  690.         $em $this->getDoctrine()->getManager();
  691.         $numberByPage 5;
  692.         
  693.         $em $this->getDoctrine()
  694.                     ->getManager();
  695.         $products $em->getRePository(Product::class)
  696.                         ->findProductByCategory($numberByPage$currentPage$category->getSlug());
  697.         $pageAmount ceil((count($products))/$numberByPage) ;
  698.         if(($currentPage $pageAmount && $pageAmount >= 1) || $currentPage <=0){
  699.             throw $this->createNotFoundException('Nombre invalide');
  700.         }        
  701.           return $this->render('entreprise/product_by_category.html.twig', [
  702.             'products' => $products,
  703.             'currentPage' => $currentPage,
  704.             'pageAmount' => $pageAmount,
  705.             'category' => $category
  706.         ]);
  707.     }
  708.     
  709.     /**
  710.      * @Route("/sc/{slug}/{page}/{currentPage}", name="product_by_sub_category")
  711.      */
  712.     public function productBySubCategoryAction(SubCategory $subCategory$page='page'$currentPage 1)
  713.     {
  714.         $em $this->getDoctrine()->getManager();
  715.         $numberByPage 5;
  716.         
  717.         $em $this->getDoctrine()
  718.                     ->getManager();
  719.         $products $em->getRePository(Product::class)
  720.                         ->findProductBySubCategory($numberByPage$currentPage$subCategory->getSlug());
  721.         $pageAmount ceil((count($products))/$numberByPage) ;
  722.         if(($currentPage $pageAmount && $pageAmount >= 1) || $currentPage <=0){
  723.             throw $this->createNotFoundException('Nombre invalide');
  724.         }        
  725.           return $this->render('entreprise/product_by_sub_category.html.twig', [
  726.             'products' => $products,
  727.             'currentPage' => $currentPage,
  728.             'pageAmount' => $pageAmount,
  729.             'subCategory' => $subCategory
  730.         ]);
  731.     }
  732.     
  733.     /**
  734.      * @Route("/s/", name="search")
  735.      */
  736.     public function searchAction($q='',$page='page',$currentPage=1)
  737.     {
  738.         
  739.         $requestStack $this->get('request_stack');
  740.         $request $requestStack->getCurrentRequest();
  741.     
  742.         $em $this->getDoctrine()->getManager();
  743.         $numberByPage 20;
  744.         
  745.         $em $this->getDoctrine()
  746.                     ->getManager();
  747.         $q $request->get('q');
  748.         $category $request->get('category');
  749.         $minPrice $request->get('minPrice');
  750.         $maxPrice $request->get('maxPrice');
  751.         $products $em->getRePository(Product::class)
  752.                         ->search($q$category$minPrice$maxPrice$numberByPage$currentPage);
  753.                         
  754.         $categories $em->getRePository(Category::class)
  755.                         ->findAll();
  756.         
  757.         $pageAmount ceil((count($products))/$numberByPage) ;
  758.         
  759.         if(($currentPage $pageAmount && $pageAmount >= 1) || $currentPage <=0){
  760.             throw $this->createNotFoundException('Nombre invalide');
  761.         }        
  762.           return $this->render('entreprise/search.html.twig', [
  763.             'products' => $products,
  764.             'currentPage' => $currentPage,
  765.             'pageAmount' => $pageAmount,
  766.             'q' => $q,
  767.             'categories' => $categories,
  768.             'minPrice' => $minPrice,
  769.             'maxPrice' => $maxPrice,
  770.             'category' => $category
  771.         ]);
  772.     }
  773.     
  774.     /**
  775.      * @Route("/nos-products", name="nos_products")
  776.      */
  777.     public function productsAction()
  778.     {
  779.         
  780.         $em $this->getDoctrine()
  781.                     ->getManager();
  782.         $products $em->getRePository(Product::class)
  783.                         ->findAll();
  784.                         
  785.           return $this->render('entreprise/products.html.twig', [
  786.             'products' => $products
  787.         ]);
  788.     }
  789.     
  790.     
  791.     /**
  792.      * @Route("/ajouter-product", name="ajouter_product")
  793.      */
  794.     public function ajouterProductAction()
  795.     {
  796.         
  797.         $requestStack $this->get('request_stack');
  798.         $request $requestStack->getCurrentRequest();
  799.     
  800.         $em $this->getDoctrine()
  801.                     ->getManager();
  802.                     
  803.         $product = new Product;
  804.         
  805.         $form $this->createForm(ProductType::class, $product);
  806.         $ok '';
  807.         if('POST' == $request->getMethod() )
  808.         {
  809.             $form->handleRequest($request);
  810.             if( $form->isValid()){
  811.                 $em->persist($product);
  812.                 $em->flush();
  813.                 $ok 'Enregistrement effectuĂ©';
  814.                 
  815.                 $product = new Product;
  816.         
  817.                 $form $this->createForm(ProductType::class, $product);
  818.     
  819.             }
  820.         }
  821.         return $this->render('entreprise/ajouter-product.html.twig', [
  822.             'form' => $form->createView(),
  823.             'ok' =>$ok
  824.         ]);
  825.     }
  826.     
  827.     /**
  828.      * @Route("/add-to-cart", name="add_to_cart")
  829.      */
  830.     public function addToCartAction()
  831.     {
  832.         $response = new JsonResponse;
  833.        
  834.         $response->headers->set('Access-Control-Allow-Origin''*');
  835.         $response->headers->set('Content-Type''application/json');
  836.         $requestStack $this->get('request_stack');
  837.         $request $requestStack->getCurrentRequest();
  838.     
  839.         $em $this->getDoctrine()
  840.                     ->getManager();
  841.         
  842.         $nombreProduct = (int)$this->session->get('nombreProduct');
  843.         $cart = (array)$this->session->get('cart');
  844.         $product '';
  845.         $price '';
  846.         
  847.         if('POST' == $request->getMethod() ){
  848.             $product $request->get('product');
  849.             $quantity $request->get('quantity');
  850.             
  851.             $product $em->getRePository(Product::class)
  852.                         ->findOneById($product);
  853.             $leProduct = array();
  854.             if(array_key_exists($product->getId(), $cart)){
  855.                 $cart[$product->getId()]['quantity'] += 1;
  856.             } else{
  857.                 $leProduct['id'] = $product->getId();
  858.                 $leProduct['nom'] = $product->getNom();
  859.                 $leProduct['price'] = $product->getPrice();
  860.                 $leProduct['slug'] = $product->getLeSlug();
  861.                 $leProduct['quantity'] = $quantity;
  862.                 $leProduct['imagePrincipale'] = $product->getImagePrincipale()->getUrl();
  863.                 
  864.                 $cart[$product->getId()] = $leProduct;
  865.             }
  866.             $nombreProduct count($cart);
  867.             
  868.             $montantProduct 0;
  869.             foreach($cart  as $prod){
  870.                 $montantProduct += $prod['price'] *  $prod['quantity'];
  871.             }
  872.             
  873.             $montantOrder = (float)$this->session->get('montantOrder');
  874.             $couponValue = (float)$this->session->get('couponValue');
  875.             $livraison = (float)$this->session->get('livraison');
  876.             $montantOrder $montantProduct $couponValue $livraison ;
  877.             $this->session->set('cart'$cart);
  878.             $this->session->set('nombreProduct'$nombreProduct);
  879.             $this->session->set('montantProduct'$montantProduct);
  880.             $this->session->set('montantOrder'$montantOrder);
  881.             $this->session->set('livraison'$livraison);
  882.             
  883.             //return $this->redirectToRoute('display_product', array('leSlug' => $product->getLeSlug() ));
  884.             
  885.             $data = array(
  886.                 "montantProduit" => $montantProduct
  887.                 );
  888.             $response->setContent(json_encode($data));
  889.             return $response;
  890.             
  891.         }
  892.         
  893.         return $response;
  894.     }
  895.     
  896.     
  897.     /**
  898.      * @Route("/side-cart-product", name="side_cart_product")
  899.      */
  900.     public function sideCartProductsAction()
  901.     {
  902.         return $this->render('entreprise/side_cart_product.html.twig', [
  903.             'form' => $form->createView(),
  904.             'ok' =>$ok
  905.         ]);
  906.     }
  907.     
  908.     /**
  909.      * @Route("/apply-coupon", name="apply_coupon")
  910.      */
  911.     public function applayCouponAction()
  912.     {
  913.         $requestStack $this->get('request_stack');
  914.         $request $requestStack->getCurrentRequest();
  915.     
  916.         $em $this->getDoctrine()
  917.                     ->getManager();
  918.         if('POST' == $request->getMethod() ){
  919.             $coupon $request->get('coupon');
  920.             
  921.             $coupon $em->getRePository(Coupon::class)
  922.                         ->findOneByCode($coupon);
  923.             if(null != $coupon){
  924.                 $toDay = new \DateTime();
  925.                     
  926.                 if($coupon->getDateDebut() <= $toDay
  927.                     && $toDay <= $coupon->getDateFin()
  928.                     //&& $coupon->getUsageLimit() > (integer)$coupon->getActualUsage()
  929.                     ){
  930.                         
  931.                         $codePromo $this->session->get('codePromo');
  932.                         
  933.                         if($codePromo != $coupon->getCode()){
  934.                             $this->session->set('codePromo'$coupon->getCode());
  935.                             $montantOrder = (float)$this->session->get('montantOrder');
  936.                             if($coupon->getIsPercentage()){
  937.                                 
  938.                                 $couponValue = ($montantOrder *  $coupon->getCouponValue())/100;
  939.                             } else{
  940.                                 $couponValue $coupon->getCouponValue();
  941.                             }
  942.                             $this->session->set('couponValue'$couponValue);
  943.                             $montantOrder $montantOrder $couponValue;
  944.                             $this->session->set('montantOrder'$montantOrder);
  945.                         } else{
  946.                             
  947.                         }
  948.                     } else{
  949.                         
  950.                     }
  951.             }
  952.         }
  953.         
  954.         return $this->redirectToRoute('cart');
  955.         //return new Response();
  956.     }
  957.     
  958.     /**
  959.      * @Route("/delete-cart-item/{product}", name="delete_cart_item")
  960.      */
  961.     public function deleteCartItemAction($product)
  962.     {
  963.         
  964.         $requestStack $this->get('request_stack');
  965.         $request $requestStack->getCurrentRequest();
  966.     
  967.         $em $this->getDoctrine()
  968.                     ->getManager();
  969.         
  970.         $nombreProduct = (int)$this->session->get('nombreProduct');
  971.         $cart = (array)$this->session->get('cart');
  972.         
  973.         $montantProduct $this->session->get('montantProduct');
  974.         $couponValue = (float)$this->session->get('couponValue');
  975.         $livraison = (float)$this->session->get('livraison');
  976.         $montantOrder = (float)$this->session->get('montantOrder');
  977.         $montantProduct $montantProduct - ($cart[$product]['quantity'] * $cart[$product]['price']);
  978.         unset($cart[$product]);
  979.             
  980.         $nombreProduct count($cart);
  981.         $montantOrder $montantProduct $livraison $couponValue;
  982.         
  983.         $this->session->set('cart'$cart);
  984.         $this->session->set('nombreProduct'$nombreProduct);
  985.         $this->session->set('montantProduct'$montantProduct);
  986.         $this->session->set('montantOrder'$montantOrder);
  987.         
  988.         return $this->redirectToRoute('cart');
  989.           
  990.     }
  991.     
  992.     /**
  993.      * @Route("/update-cart/", name="update_cart")
  994.      */
  995.     public function updateCartAction()
  996.     {
  997.         
  998.         $requestStack $this->get('request_stack');
  999.         $request $requestStack->getCurrentRequest();
  1000.     
  1001.         $em $this->getDoctrine()
  1002.                     ->getManager();
  1003.         
  1004.         $cart = (array)$this->session->get('cart');
  1005.         $product '';
  1006.         $price '';
  1007.         
  1008.         if('POST' == $request->getMethod() ){
  1009.             $product $request->get('product');
  1010.             $quantity = (float)$request->get('quantity');
  1011.             
  1012.             $product $em->getRePository(Product::class)
  1013.                         ->findOneById($product);
  1014.             $leProduct = array();
  1015.             if(array_key_exists($product->getId(), $cart)){
  1016.                 $cart[$product->getId()]['quantity'] = $quantity;
  1017.             }
  1018.             
  1019.             $montantProduct 0;
  1020.             foreach($cart  as $prod){
  1021.                 $montantProduct += $prod['price'] *  $prod['quantity'];
  1022.             }
  1023.             
  1024.             $couponValue = (float)$this->session->get('couponValue');
  1025.             $livraison = (float)$this->session->get('livraison');
  1026.             $montantOrder $montantProduct $livraison $couponValue;
  1027.                             
  1028.             $this->session->set('cart'$cart);
  1029.             $this->session->set('montantProduct'$montantProduct);
  1030.             $this->session->set('montantOrder'$montantOrder);
  1031.         }
  1032.         
  1033.         return $this->redirectToRoute('cart');
  1034.     }
  1035.     
  1036.     
  1037.     /**
  1038.      * @Route("/top-menu-cart", name="top_menu_cart")
  1039.      */
  1040.     public function topMenuCartAction()
  1041.     {
  1042.         
  1043.         $requestStack $this->get('request_stack');
  1044.         $request $requestStack->getCurrentRequest();
  1045.     
  1046.         $em $this->getDoctrine()
  1047.                     ->getManager();
  1048.         
  1049.         $nombreProduit = (int)$this->session->get('nombreProduct');
  1050.         $montantProduit = (float)$this->session->get('montantProduit');
  1051.         $panier = (array)$this->session->get('cart');
  1052.         
  1053.         
  1054.         return $this->render('entreprise/top_menu_cart.html.twig', [
  1055.             'panier' => $panier,
  1056.             'nombreProduit' => $nombreProduit,
  1057.             'montantProduit' => $montantProduit
  1058.         ]);
  1059.     }
  1060.     
  1061.     /**
  1062.      * @Route("/cart-side-section", name="cart_side_session")
  1063.      */
  1064.     public function cartSideSessionAction()
  1065.     {
  1066.         
  1067.         $requestStack $this->get('request_stack');
  1068.         $request $requestStack->getCurrentRequest();
  1069.     
  1070.         $em $this->getDoctrine()
  1071.                     ->getManager();
  1072.         
  1073.         $nombreProduit = (int)$this->session->get('nombreProduct');
  1074.         $montantOrder = (float)$this->session->get('montantOrder');
  1075.         $couponValue = (float)$this->session->get('couponValue');
  1076.         $panier = (array)$this->session->get('cart');
  1077.         
  1078.         
  1079.         return $this->render('entreprise/cart_side_session.html.twig', [
  1080.             'panier' => $panier,
  1081.             'nombreProduit' => $nombreProduit,
  1082.             'montantOrder' => $montantOrder,
  1083.             'couponValue' => $couponValue
  1084.         ]);
  1085.     }
  1086.     
  1087.     /**
  1088.      * @Route("/cart", name="cart")
  1089.      */
  1090.     public function cartAction()
  1091.     {
  1092.         
  1093.         $requestStack $this->get('request_stack');
  1094.         $request $requestStack->getCurrentRequest();
  1095.     
  1096.         $em $this->getDoctrine()
  1097.                     ->getManager();
  1098.         
  1099.         $nombreProduct = (int)$this->session->get('nombreProduct');
  1100.         
  1101.         
  1102.         $cart = (array)$this->session->get('cart');
  1103.         
  1104.         
  1105.         return $this->render('entreprise/cart.html.twig', [
  1106.             'cart' => $cart
  1107.         ]);
  1108.     }
  1109.     
  1110.     /**
  1111.      * @Route("/empty-cart", name="empty_cart")
  1112.      */
  1113.     public function emptycartAction()
  1114.     {
  1115.         
  1116.             $this->emptyRealCart();
  1117.         
  1118.         return $this->redirectToRoute('cart');
  1119.     }
  1120.     
  1121.     /**
  1122.      * @Route("/indiquer-adresse", name="indiquer_adresse")
  1123.      */
  1124.     public function indiquerAdresseAction()
  1125.     {
  1126.         
  1127.         $requestStack $this->get('request_stack');
  1128.         $request $requestStack->getCurrentRequest();
  1129.     
  1130.         $em $this->getDoctrine()
  1131.                     ->getManager();
  1132.         $nombreProduit = (int)$this->session->get('nombreProduct');
  1133.         $montantOrder = (float)$this->session->get('montantOrder');
  1134.         $couponValue = (float)$this->session->get('couponValue');
  1135.         $livraison = (float)$this->session->get('livraison');
  1136.         $panier = (array)$this->session->get('cart');
  1137.         
  1138.         $estConnecte $this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED');
  1139.      
  1140.         if(!$estConnecte){
  1141.             
  1142.             return $this->redirectToRoute('fos_user_security_login');
  1143.         }
  1144.         
  1145.         return $this->render('entreprise/indiquer_adresse.html.twig', [
  1146.             'nombreProduit' => $nombreProduit,
  1147.             'montantOrder'  => $montantOrder,
  1148.             'couponValue'   => $couponValue,
  1149.             'livraison'     => $livraison,
  1150.             'panier'        => $panier
  1151.         ]);
  1152.     }
  1153.     
  1154.     /**
  1155.      * @Route("/shipping", name="shipping")
  1156.      */
  1157.     public function shippingAction()
  1158.     {
  1159.         $requestStack $this->get('request_stack');
  1160.         $request $requestStack->getCurrentRequest();
  1161.         
  1162.         $em $this->getDoctrine()
  1163.                     ->getManager();
  1164.         $shippingMethods $em->getRePository(ShippingMethod::class)
  1165.                                 ->findAll();
  1166.         $user $this->getUser();
  1167.         if('POST' == $request->getMethod()){
  1168.             $firstname $request->request->get('firstname');
  1169.             $lastname $request->request->get('lastname');
  1170.             $email $request->request->get('email');
  1171.             $telephone $request->request->get('telephone');
  1172.             $adresse $request->request->get('adresse');
  1173.             
  1174.             $user->setAdresse($adresse);
  1175.             $user->setTelephone($telephone);
  1176.             $user->setEmail($email);
  1177.             $user->setLastname($lastname);
  1178.             $user->setFirstname($firstname);
  1179.             $em->flush();
  1180.         }
  1181.         
  1182.         $nombreProduit = (int)$this->session->get('nombreProduct');
  1183.         $montantOrder = (float)$this->session->get('montantOrder');
  1184.         $couponValue = (float)$this->session->get('couponValue');
  1185.         $livraison = (float)$this->session->get('livraison');
  1186.         $panier = (array)$this->session->get('cart');
  1187.     
  1188.         
  1189.         return $this->render('entreprise/shipping.html.twig', [
  1190.             'shippingMethods' => $shippingMethods,
  1191.             'nombreProduit' => $nombreProduit,
  1192.             'montantOrder'  => $montantOrder,
  1193.             'couponValue'   => $couponValue,
  1194.             'livraison'     => $livraison,
  1195.             'panier'        => $panier
  1196.         ]);
  1197.     }
  1198.     
  1199.     
  1200.     /**
  1201.      * @Route("/choose-payment", name="choose_payment")
  1202.      */
  1203.     public function choosePaymentAction()
  1204.     {
  1205.         
  1206.         $requestStack $this->get('request_stack');
  1207.         $request $requestStack->getCurrentRequest();
  1208.         
  1209.         $em $this->getDoctrine()
  1210.                     ->getManager();
  1211.                     
  1212.         $user $this->getUser();
  1213.         $shippingMethod 0;
  1214.         $montantProduct 0;
  1215.         $shippingMethod = (float)$request->request->get('shippingMethod');
  1216.         $montantOrder = (float)$this->session->get('montantOrder');
  1217.         $livraison = (float)$this->session->get('livraison');
  1218.         
  1219.         if('POST' == $request->getMethod()){
  1220.             
  1221.             $montantOrder $montantOrder $livraison $shippingMethod;
  1222.             
  1223.             $this->session->set('livraison'$shippingMethod);
  1224.             $this->session->set('montantOrder'$montantOrder);
  1225.         }
  1226.         return $this->render('entreprise/choose_payment.html.twig', [
  1227.             'montantOrder' => $montantOrder
  1228.         ]);
  1229.     }
  1230.     
  1231.     /**
  1232.      * @Route("/payment", name="payment")
  1233.      */
  1234.     public function paymentAction()
  1235.     {
  1236.         
  1237.         $requestStack $this->get('request_stack');
  1238.         $request $requestStack->getCurrentRequest();
  1239.         
  1240.         $em $this->getDoctrine()
  1241.                     ->getManager();
  1242.                     
  1243.         $user $this->getUser();
  1244.         $shippingMethod 0;
  1245.         $montantProduct 0;
  1246.         $shippingMethod = (float)$request->request->get('shippingMethod');
  1247.         $montantOrder = (float)$this->session->get('montantOrder');
  1248.         $livraison = (float)$this->session->get('livraison');
  1249.         
  1250.         if('POST' == $request->getMethod()){
  1251.             
  1252.             $montantOrder $montantOrder $livraison $shippingMethod;
  1253.             
  1254.             $this->session->set('livraison'$shippingMethod);
  1255.             $this->session->set('montantOrder'$montantOrder);
  1256.         }
  1257.         return $this->render('entreprise/payment.html.twig', [
  1258.             'montantOrder' => $montantOrder
  1259.         ]);
  1260.     }
  1261.     /**
  1262.      * @Route("/review", name="review")
  1263.      */
  1264.     public function reviewAction()
  1265.     {
  1266.         
  1267.         $requestStack $this->get('request_stack');
  1268.         $request $requestStack->getCurrentRequest();
  1269.         
  1270.         $em $this->getDoctrine()
  1271.                     ->getManager();
  1272.                     
  1273.         $paymentMethod '';
  1274.         if('POST' == $request->getMethod()){
  1275.             $paymentMethod $request->request->get('paymentMethod');
  1276.             
  1277.             $this->session->set('paymentMethod'$paymentMethod);
  1278.         }
  1279.         
  1280.         $nombreProduit = (int)$this->session->get('nombreProduct');
  1281.         $montantOrder = (float)$this->session->get('montantOrder');
  1282.         $couponValue = (float)$this->session->get('couponValue');
  1283.         $livraison = (float)$this->session->get('livraison');
  1284.         $panier = (array)$this->session->get('cart');
  1285.     
  1286.         
  1287.         return $this->render('entreprise/review.html.twig', [
  1288.            'paymentMethod' => $paymentMethod,
  1289.            'nombreProduit' => $nombreProduit,
  1290.             'montantOrder'  => $montantOrder,
  1291.             'couponValue'   => $couponValue,
  1292.             'livraison'     => $livraison,
  1293.             'panier'        => $panier
  1294.         ]);
  1295.     }
  1296.     
  1297.     /**
  1298.      * @Route("/save-order", name="save_order")
  1299.      */
  1300.     public function saveOrderAction(\Swift_Mailer $mailer)
  1301.     {
  1302.         
  1303.         $requestStack $this->get('request_stack');
  1304.         $request $requestStack->getCurrentRequest();
  1305.         
  1306.         $em $this->getDoctrine()
  1307.                     ->getManager();
  1308.                     
  1309.         $nombreProduct = (int)$this->session->get('nombreProduct');
  1310.         
  1311.         $user $this->getUser();
  1312.         
  1313.         $cart = (array)$this->session->get('cart');
  1314.         $montantProduct 0;
  1315.         $order = new Order;
  1316.         
  1317.         $this->doSaveOrder($order$mailer);
  1318.         
  1319.         return $this->render('entreprise/save_order.html.twig', [
  1320.             'order' => $order
  1321.         ]);
  1322.     }
  1323.     
  1324.     
  1325.     public function doSaveOrder($order, \Swift_Mailer $mailer){
  1326.         $em $this->getDoctrine()
  1327.                     ->getManager();
  1328.         $cart = (array)$this->session->get('cart');
  1329.         $montantProduct 0;
  1330.         $user $this->getUser();
  1331.         $order->setUser($user);
  1332.         $order->setTotalHT($this->session->get('montantProduct'));
  1333.         $order->setMontantLivraison($this->session->get('livraison'));
  1334.         $order->setTotalTTC($this->session->get('montantOrder'));
  1335.         $order->setPaymentMethod($this->session->get('paymentMethod'));
  1336.         $order->setCouponValue($this->session->get('couponValue'));
  1337.         $order->setCodePromo($this->session->get('codePromo'));
  1338.         $em->persist($order);
  1339.         
  1340.         $em->flush();
  1341.         $productOrders = array();
  1342.         foreach($cart  as $prod){
  1343.             $montantProduct += $prod['price'] *  $prod['quantity'];
  1344.             $leProduct $em->getRepository(Product::class)->findOneById($prod['id']);
  1345.             $leProduct->setStockDisponible($leProduct->getStockDisponible() - $prod['quantity']);
  1346.             $productOrder = new ProductOrder;
  1347.             $productOrder->setProduct($leProduct);
  1348.             $productOrder->setOrder($order);
  1349.             $productOrder->setQuantity($prod['quantity']);
  1350.             $productOrder->setPrice($prod['price']);
  1351.             $productOrder->setTotalHT($montantProduct);
  1352.             $productOrder->setTotalTTC($montantProduct);
  1353.             $em->persist($productOrder);
  1354.             array_push($productOrders$prod);
  1355.         }
  1356.         $codePromo $this->session->get('codePromo');
  1357.         $coupon $em->getRepository(Coupon::class)
  1358.                     ->findOneByCode($codePromo);
  1359.         if(null != $coupon){
  1360.             $coupon->setActualUsage($coupon->getActualUsage()+1);
  1361.             $this->session->set('codePromo''');
  1362.         }
  1363.         $em->flush();
  1364.         
  1365.         //SendEmail and notifications
  1366.         $message = (new \Swift_Message('Votre commande'))
  1367.         ->setFrom('contact@virtuelmarket.com')
  1368.         ->setTo($user->getEmail())
  1369.         ->setBody(
  1370.             $this->renderView(
  1371.                 // templates/emails/registration.html.twig
  1372.                 'entreprise/order_email.html.twig',
  1373.                 ['productOrders' => $productOrders]
  1374.             ),
  1375.             'text/html'
  1376.         );
  1377.         $mailer->send($message);
  1378.         
  1379.         $this->emptyRealCart();
  1380.         
  1381.     }
  1382.     
  1383.     
  1384.     /**
  1385.      * @Route("/pay-order/", name="pay_order")
  1386.      * @return \Symfony\Component\HttpFoundation\Response
  1387.      */
  1388.     public function payOrderAction(Request $request)
  1389.     {
  1390.         $em $this->getDoctrine()
  1391.                     ->getManager();
  1392.                     
  1393.         $user $this->getUser();
  1394.         
  1395.         $transId rand(4560100000);
  1396.         $transDate = new \DateTime();
  1397.         $montantOrder $this->session->get('montantOrder');
  1398.         
  1399.         $amount $montantOrder;
  1400.         if('POST' == $request->getMethod()){
  1401.             var_dump($_POST);
  1402.         }
  1403.         
  1404.         
  1405.     $commande = new Order;
  1406.     //transaction id
  1407.     $id_transaction CinetPay::generateTransId();
  1408.     // Payment description
  1409.     $description_du_paiement "Devenir premium";
  1410.     // Payment Date must be on date format
  1411.     $date_transaction date("Y-m-d H:i:s");
  1412.     // Amount
  1413.     //$montant_a_payer = 100;
  1414.     $montant_a_payer $montantOrder;
  1415.     // put a value that you can use to identify the buyer in your system
  1416.     $identifiant_du_payeur $user->getId().'@@@'.$commande->getId();
  1417.     //Veuillez entrer votre apiKey
  1418.     $apiKey "1182873575626ba8e6c712e9.05305545";
  1419.     //Secret Key: 127127447062796bafS
  1420.     //Veuillez entrer votre siteId
  1421.     $site_id "792421";
  1422.     //platform ,  utiliser PROD si vous avez crĂ©Ă© votre compte sur www.cinetpay.com  ou TEST si vous avez crĂ©Ă© votre compte sur www.sandbox.cinetpay.com
  1423.     $plateform "PROD";
  1424.     //la version ,  utilisĂ© V1 si vous voulez utiliser la version 1 de l'api
  1425.     $version "V2";
  1426.     // nom du formulaire CinetPay
  1427.     $formName "goCinetPay";
  1428.     // notify url
  1429.     $notify_url $this->generateUrl('cinetpay_notify', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  1430.     // return url
  1431.     $return_url =  $this->generateUrl('cinetpay_return', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  1432.     // cancel url
  1433.     $cancel_url =  $this->generateUrl('cinetpay_cancel', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  1434.     // cinetpay button type, must be 1, 2, 3, 4 or 5
  1435.     $btnType 4;
  1436.     // button size, can be 'small' , 'large' or 'larger'
  1437.     $btnSize 'large';
  1438.     // fill command class
  1439.     $commande->setCpmTransId($id_transaction);
  1440.     $commande->setCpmAmount($montant_a_payer);
  1441.     $commande->setUser($user);
  1442.     $em->persist($commande);
  1443.     $em->flush();
  1444.     // create html form for your basket
  1445.     $CinetPay = new CinetPay($site_id$apiKey$plateform$version);
  1446.     $CinetPay->setTransId($id_transaction)
  1447.         ->setDesignation($description_du_paiement)
  1448.         ->setTransDate($date_transaction)
  1449.         ->setAmount($montant_a_payer)
  1450.         ->setDebug(true)// put it on true, if you want to activate debug
  1451.         ->setCustom($identifiant_du_payeur)// optional
  1452.         ->setNotifyUrl($notify_url)// optional
  1453.         ->setReturnUrl($return_url)// optional
  1454.         ->setCancelUrl($cancel_url);// optional
  1455.         //->displayPayButton($formName, $btnType, $btnSize);
  1456.         
  1457.         
  1458.         return $this->render('entreprise/pay_order.html.twig', [
  1459.             'user' => $user,
  1460.             'transId' => $transId,
  1461.             'transDate' => $transDate,
  1462.             'amount' => $amount,
  1463.             'CinetPay' => $CinetPay,
  1464.             'transaction' => $id_transaction,
  1465.             'formName' => $formName,
  1466.             'btnType' => $btnType,
  1467.             'btnSize' => $btnSize,
  1468.         ]);
  1469.         
  1470.         return $this->redirectToRoute('home');
  1471.             
  1472.     }
  1473.     
  1474.     /**
  1475.     * @Route("/cinetpay/notify/{transaction}", name="cinetpay_notify")
  1476.     */
  1477.     public function cinetPayNotifyAction($transaction)
  1478.     {
  1479.         $em $this->getDoctrine()
  1480.                     ->getManager();
  1481.         $user $this->getUser();
  1482.         
  1483.         $requestStack $this->get('request_stack');
  1484.         $request $requestStack->getCurrentRequest();
  1485.         $ok_submission '';
  1486.         $error '';
  1487.         
  1488.         $commande $em->getRePository(Order::class)
  1489.                             ->findOneByCpmTransId($transaction);
  1490.         $messageRequete '';        
  1491.         $errorMessage '';
  1492.         if('POST' == $request->getMethod()){
  1493.             
  1494.         $id_transaction $_POST['cpm_trans_id'];
  1495.         $apiKey "1182873575626ba8e6c712e9.05305545";
  1496.         //Secret Key: 127127447062796bafS
  1497.         //Veuillez entrer votre siteId
  1498.         $site_id "792421";
  1499.         $plateform "PROD"// ValorisĂ© Ă  PROD si vous ĂŞtes en production
  1500.         $version "V2"// ValorisĂ© Ă  V1 si vous voulez utiliser la version 1 de l'api
  1501.         $CinetPay = new CinetPay($site_id$apiKey$plateform$version);
  1502.         // Reprise exacte des bonnes donnĂ©es chez CinetPay
  1503.         $CinetPay->setTransId($id_transaction)->getPayStatus();
  1504.         $cpm_site_id $CinetPay->_cpm_site_id;
  1505.         $signature $CinetPay->_signature;
  1506.         $cpm_amount $CinetPay->_cpm_amount;
  1507.         $cpm_trans_id $CinetPay->_cpm_trans_id;
  1508.         $cpm_custom $CinetPay->_cpm_custom;
  1509.         $cpm_currency $CinetPay->_cpm_currency;
  1510.         $cpm_payid $CinetPay->_cpm_payid;
  1511.         $cpm_payment_date $CinetPay->_cpm_payment_date;
  1512.         $cpm_payment_time $CinetPay->_cpm_payment_time;
  1513.         $cpm_error_message $CinetPay->_cpm_error_message;
  1514.         $payment_method $CinetPay->_payment_method;
  1515.         $cpm_phone_prefixe $CinetPay->_cpm_phone_prefixe;
  1516.         $cel_phone_num $CinetPay->_cel_phone_num;
  1517.         $cpm_ipn_ack $CinetPay->_cpm_ipn_ack;
  1518.         $created_at $CinetPay->_created_at;
  1519.         $updated_at $CinetPay->_updated_at;
  1520.         $cpm_result $CinetPay->_cpm_result;
  1521.         $cpm_trans_status $CinetPay->_cpm_trans_status;
  1522.         $cpm_designation $CinetPay->_cpm_designation;
  1523.         $buyer_name $CinetPay->_buyer_name;
  1524.         
  1525.         $commande $em->getRePository(Order::class)
  1526.                             ->findOneByCpmTransId($cpm_trans_id);
  1527.         if($commande->getCpmTransStatus() == '00'){
  1528.             //Paiement dĂ©jĂ  validĂ©
  1529.         } else{
  1530.             $commande->setPaymentMethod($payment_method);
  1531.             $commande->setCpmPayid($cpm_payid);
  1532.             $commande->setBuyerName($buyer_name);
  1533.             $commande->setSignature($signature);
  1534.             $commande->setCelPhoneNum($cel_phone_num);
  1535.             //$commande->setCpmPaymentDate($cpm_payment_date . ' ' . $cpm_payment_time);
  1536.             if ($commande->getCpmAmount() == $cpm_amount) {
  1537.                 // C'est OK : On continue le remplissage des nouvelles donnĂ©es
  1538.                 $commande->setCpmErrorMessage($cpm_error_message);
  1539.                 $commande->setCpmTransStatus($cpm_result);
  1540.                 //$commande->setCpmTransStatus($cpm_trans_status);
  1541.                 if($cpm_result == '00'){
  1542.                     //Le paiement est bon
  1543.                     // Traitez et delivrez le service au client
  1544.                     $mailer = new \Swift_Mailer;
  1545.                     $this->doSaveOrder($commande$mailer);
  1546.                     $errorMessage 'Paiement effectuĂ© avec succès';
  1547.                     return $this->redirect($this->generateUrl('home'));
  1548.                     
  1549.                 }else{
  1550.                     //Le paiement a Ă©chouĂ©
  1551.                 }
  1552.         } else {
  1553.             //Fraude : montant payĂ© ' . $cpm_amount . ' ne correspond pas au montant de la commande
  1554.             $commande->setCpmTransStatus('-1');
  1555.             //$commande->setTransStatus('REFUSED');
  1556.         }
  1557.         // On met Ă  jour notre ligne
  1558.         //$commande->update();
  1559.         
  1560.         }
  1561.         
  1562.         }
  1563.         return $this->render('entreprise/cinetpay_notify.html.twig', [
  1564.             'pageTitle' => $pageTitle,
  1565.             'user' => $user,
  1566.             'errorMessage' => $errorMessage
  1567.         ]);
  1568.     }
  1569.     
  1570.     /**
  1571.     * @Route("/cinetpay/return/{transaction}", name="cinetpay_return")
  1572.      */
  1573.     public function cinetPayReturnAction($transaction)
  1574.     {
  1575.         $em $this->getDoctrine()
  1576.                     ->getManager();
  1577.         $user $this->getUser();
  1578.         
  1579.         $requestStack $this->get('request_stack');
  1580.         $request $requestStack->getCurrentRequest();
  1581.         $ok_submission '';
  1582.         $error '';
  1583.         
  1584.         $messageRequete '';
  1585.         $errorMessage '';
  1586.         $pageTitle 'Devenir premium';
  1587.         $commande $em->getRePository(Commande::class)
  1588.                             ->findOneByCpmTransId($transaction);
  1589.         
  1590.         if('POST' == $request->getMethod()){
  1591.             $errorMessage 'Paiement effectuĂ© avec succès'
  1592.             $id_transaction $_POST['cpm_trans_id'];
  1593.         $apiKey "1182873575626ba8e6c712e9.05305545";
  1594.         //Secret Key: 127127447062796bafS
  1595.         //Veuillez entrer votre siteId
  1596.         $site_id "792421";
  1597.         $plateform "PROD"// ValorisĂ© Ă  PROD si vous ĂŞtes en production
  1598.         $version "V2"// ValorisĂ© Ă  V1 si vous voulez utiliser la version 1 de l'api
  1599.         $CinetPay = new CinetPay($site_id$apiKey$plateform$version);
  1600.         // Reprise exacte des bonnes donnĂ©es chez CinetPay
  1601.         $CinetPay->setTransId($id_transaction)->getPayStatus();
  1602.         $cpm_site_id $CinetPay->_cpm_site_id;
  1603.         $signature $CinetPay->_signature;
  1604.         $cpm_amount $CinetPay->_cpm_amount;
  1605.         $cpm_trans_id $CinetPay->_cpm_trans_id;
  1606.         $cpm_custom $CinetPay->_cpm_custom;
  1607.         $cpm_currency $CinetPay->_cpm_currency;
  1608.         $cpm_payid $CinetPay->_cpm_payid;
  1609.         $cpm_payment_date $CinetPay->_cpm_payment_date;
  1610.         $cpm_payment_time $CinetPay->_cpm_payment_time;
  1611.         $cpm_error_message $CinetPay->_cpm_error_message;
  1612.         $payment_method $CinetPay->_payment_method;
  1613.         $cpm_phone_prefixe $CinetPay->_cpm_phone_prefixe;
  1614.         $cel_phone_num $CinetPay->_cel_phone_num;
  1615.         $cpm_ipn_ack $CinetPay->_cpm_ipn_ack;
  1616.         $created_at $CinetPay->_created_at;
  1617.         $updated_at $CinetPay->_updated_at;
  1618.         $cpm_result $CinetPay->_cpm_result;
  1619.         $cpm_trans_status $CinetPay->_cpm_trans_status;
  1620.         $cpm_designation $CinetPay->_cpm_designation;
  1621.         $buyer_name $CinetPay->_buyer_name;
  1622.         
  1623.         $customArray explode('@@@'$cpm_custom);
  1624.         $boutique $em->getRepository(Boutique::class)
  1625.                                     ->findOneById($customArray[1]);
  1626.         
  1627.         return $this->redirect($this->generateUrl('gestion.show_shop', array('slug' =>$boutique->getSlug())));
  1628.                     
  1629.         }
  1630.         return $this->render('gestion/cinetpay_return.html.twig', [
  1631.             'pageTitle' => $pageTitle,
  1632.             'user' => $user,
  1633.             'errorMessage' => $errorMessage
  1634.         ]);
  1635.     }
  1636.     
  1637.     /**
  1638.     * @Route("/cinetpay/cancel/{transaction}", name="cinetpay_cancel")
  1639.      */
  1640.     public function cinetPayCancelction($transaction)
  1641.     {
  1642.         $em $this->getDoctrine()
  1643.                     ->getManager();
  1644.         $user $this->getUser();
  1645.         
  1646.         $requestStack $this->get('request_stack');
  1647.         $request $requestStack->getCurrentRequest();
  1648.         $ok_submission '';
  1649.         $error '';
  1650.         
  1651.         $commande $em->getRePository(Commande::class)
  1652.                             ->findOneByCpmTransId($transaction);
  1653.                             
  1654.         $messageRequete '';        
  1655.         
  1656.         
  1657.         if('POST' == $request->getMethod()){
  1658.             var_dump($_POST);
  1659.         }
  1660.         return $this->render('entreprise/cinetpay_cancel.html.twig', [
  1661.             
  1662.             'user' => $user
  1663.         ]);
  1664.     }
  1665.     
  1666.     
  1667.     public function emptyRealCart()
  1668.     {
  1669.         $this->session->set('cart', array());
  1670.         $this->session->set('nombreProduct''');
  1671.         $this->session->set('montantProduct'0);
  1672.         $this->session->set('montantOrder'0);
  1673.         $this->session->set('paymentMethod''');
  1674.         $this->session->set('livraison'0);
  1675.         $this->session->set('couponValue'0);
  1676.         $this->session->set('codePromo''');
  1677.     }
  1678.     /**
  1679.      * @Route("/contact", name="contact")
  1680.      */
  1681.     public function contactAction()
  1682.     {
  1683.         
  1684.           return $this->render('entreprise/contact.html.twig', [
  1685.             
  1686.         ]);
  1687.     }
  1688.     
  1689.     /**
  1690.      * @Route("/faq", name="faq")
  1691.      */
  1692.     public function faqAction()
  1693.     {
  1694.         
  1695.         $em $this->getDoctrine()
  1696.                     ->getManager();
  1697.         $faqs $em->getRePository(SujetFAQ::class)
  1698.                     ->findAll();
  1699.                     
  1700.           return $this->render('entreprise/faq.html.twig', [
  1701.             'faqs' => $faqs
  1702.         ]);
  1703.     }
  1704.     
  1705.     /**
  1706.      * @Route("/faq/nouveau-sujet", name="faq_nouveau_sujet")
  1707.      */
  1708.     public function nouveauSujetFaqAction()
  1709.     {
  1710.         $requestStack $this->get('request_stack');
  1711.         $request $requestStack->getCurrentRequest();
  1712.     
  1713.         $em $this->getDoctrine()
  1714.                     ->getManager();
  1715.                     
  1716.         $sujetFAQ = new SujetFAQ;
  1717.         
  1718.         $form $this->createForm(SujetFAQType::class, $sujetFAQ);
  1719.         $ok '';
  1720.         if('POST' == $request->getMethod() )
  1721.         {
  1722.             $form->handleRequest($request);
  1723.             if( $form->isValid()){
  1724.                 $em->persist($sujetFAQ);
  1725.                 $em->flush();
  1726.                 $ok 'Enregistrement effectuĂ©';
  1727.                 
  1728.                 $sujetFAQ = new SujetFAQ;
  1729.         
  1730.                 $form $this->createForm(SujetFAQType::class, $sujetFAQ);
  1731.     
  1732.             }
  1733.         }
  1734.         
  1735.           return $this->render('entreprise/faq_nouveau_sujet.html.twig', [
  1736.             'form' => $form->createView(),
  1737.             'ok' => $ok
  1738.         ]);
  1739.     }
  1740.     
  1741.     /**
  1742.      * @Route("/faq/avis-utilisateur", name="avis_utilisateur")
  1743.      */
  1744.     public function avisUtilisateurAction()
  1745.     {
  1746.         $requestStack $this->get('request_stack');
  1747.         $request $requestStack->getCurrentRequest();
  1748.     
  1749.         $em $this->getDoctrine()
  1750.                     ->getManager();
  1751.                     
  1752.         $avisUtilisateurs $em->getRePository(AvisUtilisateur::class)
  1753.                             ->findAll();
  1754.         
  1755.         
  1756.           return $this->render('entreprise/avis_utilisateur.html.twig', [
  1757.             'avisUtilisateurs' => $avisUtilisateurs
  1758.         ]);
  1759.     }
  1760.     
  1761.     /**
  1762.      * @Route("/faq/nouvel-avis-utilisateur", name="nouvel_avis_utilisateur")
  1763.      */
  1764.     public function nouvelAvisUtilisateurAction()
  1765.     {
  1766.         $requestStack $this->get('request_stack');
  1767.         $request $requestStack->getCurrentRequest();
  1768.     
  1769.         $em $this->getDoctrine()
  1770.                     ->getManager();
  1771.                     
  1772.         $avisUtilisateur = new AvisUtilisateur;
  1773.         
  1774.         $form $this->createForm(AvisUtilisateurType::class, $avisUtilisateur);
  1775.         $ok '';
  1776.         if('POST' == $request->getMethod() )
  1777.         {
  1778.             $form->handleRequest($request);
  1779.             if( $form->isValid()){
  1780.                 $em->persist($avisUtilisateur);
  1781.                 $em->flush();
  1782.                 $ok 'Enregistrement effectuĂ©';
  1783.                 
  1784.                 $avisUtilisateur = new AvisUtilisateur;
  1785.         
  1786.                 $form $this->createForm(AvisUtilisateurType::class, $avisUtilisateur);
  1787.             }
  1788.         }
  1789.         
  1790.           return $this->render('entreprise/nouvel_avis_utilisateur.html.twig', [
  1791.             'form' => $form->createView(),
  1792.             'ok' => $ok
  1793.         ]);
  1794.     }
  1795.     
  1796.     /**
  1797.      * @Route("/faq/modifier-avis-utilisateur/{id}", name="modifier_avis_utilisateur")
  1798.      */
  1799.     public function modifierAvisUtilisateurAction(AvisUtilisateur $avisUtilisateur)
  1800.     {
  1801.         $requestStack $this->get('request_stack');
  1802.         $request $requestStack->getCurrentRequest();
  1803.     
  1804.         $em $this->getDoctrine()
  1805.                     ->getManager();
  1806.                     
  1807.         
  1808.         $form $this->createForm(AvisUtilisateurEditType::class, $avisUtilisateur);
  1809.         $ok '';
  1810.         if('POST' == $request->getMethod() )
  1811.         {
  1812.             $form->handleRequest($request);
  1813.             if( $form->isValid()){
  1814.                 $em->persist($avisUtilisateur);
  1815.                 $em->flush();
  1816.                 $ok 'Enregistrement effectuĂ©';
  1817.                 
  1818.             }
  1819.         }
  1820.         
  1821.           return $this->render('entreprise/modifier_avis_utilisateur.html.twig', [
  1822.             'form' => $form->createView(),
  1823.             'ok' => $ok
  1824.         ]);
  1825.     }
  1826.     
  1827.     /**
  1828.      * @Route("/faq/supprimer-avis-utilisateur/{id}", name="supprimer_avis_utilisateur")
  1829.      */
  1830.     public function supprimerAvisUtilisateurAction(AvisUtilisateur $avisUtilisateur)
  1831.     {
  1832.         $em $this->getDoctrine()
  1833.                 ->getManager();
  1834.                 
  1835.         $em->remove($avisUtilisateur);
  1836.         $em->flush();
  1837.         
  1838.         return $this->redirectToRoute('accueil');    
  1839.     }
  1840. }