src/Controller/EntrepriseController.php line 75

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