src/Controller/PagesController.php line 77

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Bloc;
  4. use App\Entity\Categorie;
  5. use App\Entity\Contact;
  6. use App\Entity\Lait;
  7. use App\Entity\Origine;
  8. use App\Entity\Presentation;
  9. use App\Entity\Produit;
  10. use App\Data\FilterProduitData;
  11. use App\Entity\Client;
  12. use App\Entity\Commande;
  13. use App\Entity\Drive;
  14. use App\Entity\Livraison;
  15. use App\Entity\Montant;
  16. use App\Entity\Panier;
  17. use App\Entity\PanierProduits;
  18. use App\Form\FilterProduit;
  19. use App\Repository\ProduitRepository;
  20. use App\Entity\Selection;
  21. use App\Entity\Slider;
  22. use App\Entity\Statut;
  23. use App\Entity\Type;
  24. use App\Form\ClientType;
  25. use App\Form\DateCommandeType;
  26. use App\Service\RecaptchaService;
  27. use App\Form\ContactType;
  28. use App\Repository\CommandeRepository;
  29. use Doctrine\ORM\EntityManagerInterface;
  30. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  31. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Component\HttpFoundation\Response;
  34. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  35. use Symfony\Component\Mailer\MailerInterface;
  36. use Symfony\Component\Routing\Annotation\Route;
  37. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  38. use Symfony\Component\Security\Core\Security;
  39. class PagesController extends AbstractController
  40. {
  41.     /**
  42.      * @Route("/", name="accueil")
  43.      */
  44.     public function index(EntityManagerInterface $emSecurity $security): Response
  45.     {
  46.         $sliders $this->getDoctrine()->getRepository(Slider::class)->findByActif(true);
  47.         $selections $this->getDoctrine()->getRepository(Selection::class)->findByDisplay(true);
  48.         $produits $this->getDoctrine()->getRepository(Produit::class)->threeRandom($em);
  49.         $photoProduits $this->getDoctrine()->getRepository(Produit::class)->findAll();
  50.         $drive $this->getDoctrine()->getRepository(Drive::class)->findOneBy(['id' => 1]);
  51.         $connected $security->getUser();
  52.         $panier "";
  53.         if($connected){
  54.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  55.         }
  56.         return $this->render('pages/accueil.html.twig', [
  57.             'sliders' => $sliders,
  58.             'selections' => $selections,
  59.             'produits' => $produits,
  60.             'photoProduits' => $photoProduits,
  61.             'drive' => $drive,
  62.             'connected' => $connected,
  63.             'panier' => $panier,
  64.         ]);
  65.     }
  66.     /**
  67.      * @Route("/presentation", name="presentation")
  68.      */
  69.     public function presentation(Security $security): Response
  70.     {
  71.         $page = [
  72.             'id' => "presentation",
  73.             'titre' => "Votre fromager à Rennes et Cesson-Sévigné",
  74.         ];
  75.         $presentation $this->getDoctrine()->getRepository(Presentation::class)->findOneById(1);
  76.         $blocs $this->getDoctrine()->getRepository(Bloc::class)->findByDisplay(true);
  77.         $connected $security->getUser();
  78.         $panier "";
  79.         if($connected){
  80.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  81.         }
  82.         return $this->render('pages/presentation.html.twig', [
  83.             'page' => $page,
  84.             'presentation' => $presentation,
  85.             'blocs' => $blocs,
  86.             'panier' => $panier
  87.         ]);
  88.     }
  89.     /**
  90.      * @Route("/contact", name="contact")
  91.      */
  92.     public function contact(Request $requestMailerInterface $mailerRecaptchaService $recaptchaServiceSecurity $security): Response
  93.     {
  94.         $page = [
  95.             'id' => "contact",
  96.             'titre' => "Contactez-nous pour toutes questions",
  97.         ];
  98.         $etat "danger";
  99.         $message "Une erreur s'est produite. Veuillez réessayer ultérieurement.";
  100.         $connected $security->getUser();
  101.         $panier "";
  102.         if($connected){
  103.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  104.         }
  105.         $contact = new Contact();
  106.         $contactType $this->createForm(ContactType::class, $contact);
  107.         $contactType->handleRequest($request);
  108.         if($contactType->isSubmitted() && $contactType->isValid()) {
  109.             $captchaToken $request->get('g-recaptcha-response');
  110.             if(!$recaptchaService->verifyCaptcha($captchaToken)) {
  111.                 $message "Erreur de captcha";
  112.                 $etat "error";
  113.             } else {
  114.                 // Envoi du mail de contact
  115.                 $email = new TemplatedEmail();
  116.                 $email->from($contact->getEmail())
  117.                     ->to($this->getParameter('mailer_user'))
  118.                     ->subject('Demande de contact - Koaven Fromagerie')
  119.                     ->htmlTemplate('emails/mailContact.html.twig')
  120.                     ->context(array(
  121.                         'contact' => $contact
  122.                     ))
  123.                 ;
  124.                 $emailUser = new TemplatedEmail();
  125.                 $emailUser->from($this->getParameter('mailer_user'))
  126.                     ->to($contact->getEmail())
  127.                     ->subject('Confirmation réception formulaire de contact - Koaven Fromagerie')
  128.                     ->htmlTemplate('emails/mailContactUser.html.twig')
  129.                     ->context(array(
  130.                         'contact' => $contact
  131.                     ))
  132.                 ;
  133.                 $message "Votre demande de contact a bien été envoyée.";
  134.                 $etat "success";
  135.                 try{
  136.                     $mailer->send($email);
  137.                     $mailer->send($emailUser);
  138.                 } catch (TransportExceptionInterface $e)
  139.                 {
  140.                     $etat "danger";
  141.                     $message "Une erreur s'est produite. Veuillez réessayer ultérieurement.";
  142.                 }
  143.             }
  144.             $this->addFlash($etat$message);
  145.             return $this->redirectToRoute('contact');
  146.         }
  147.         return $this->render('pages/contact.html.twig', [
  148.             'page' => $page,
  149.             'formContact' => $contactType->createView(),
  150.             'panier' => $panier
  151.         ]);
  152.     }
  153.     /**
  154.      * @Route("/mentions-legales", name="mentions")
  155.      */
  156.     public function mentions(Security $security): Response
  157.     {
  158.         $page = [
  159.             'id' => "mentions",
  160.             'titre' => "Mentions légales",
  161.         ];
  162.         $connected $security->getUser();
  163.         $panier "";
  164.         if($connected){
  165.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  166.         }
  167.         return $this->render('pages/mentions.html.twig', [
  168.             'page' => $page,
  169.             'panier' => $panier
  170.         ]);
  171.     }
  172.     /**
  173.      * @Route("/cgv", name="cgv")
  174.      */
  175.     public function cgv(Security $security): Response
  176.     {
  177.         $montant $this->getDoctrine()->getRepository(Montant::class)->findOneBy(['id' => 1]);
  178.         $page = [
  179.             'id' => "cgv",
  180.             'titre' => "Conditions générales de vente",
  181.         ];
  182.         
  183.         $connected $security->getUser();
  184.         $panier "";
  185.         if($connected){
  186.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  187.         }
  188.         return $this->render('pages/cgv.html.twig', [
  189.             'page' => $page,
  190.             'security' => $security,
  191.             'panier' => $panier,
  192.             'montant' => $montant
  193.         ]);
  194.     }
  195.     /**
  196.      * @Route("/boutique", name="boutique")
  197.      */
  198.     public function boutique(ProduitRepository $repositoryRequest $requestSecurity $security): Response
  199.     {
  200.         $page = [
  201.             'id' => "fromage",
  202.             'titre' => "Votre fromager à Rennes et Cesson-Sévigné",
  203.         ];
  204.         $connected $security->getUser();
  205.         $data = new FilterProduitData();
  206.         $data->page $request->query->get('page'1) - 1;
  207.         $form $this->createForm(FilterProduit::class, $data);
  208.         $form->handleRequest($request);
  209.         $produits $repository->findSearch($data);
  210.         $drive $this->getDoctrine()->getRepository(Drive::class)->findOneBy(['id' => 1]);
  211.         $fromage $this->getDoctrine()->getRepository(Categorie::class)->findOneBy(['nom' => 'Fromages']);
  212.         $cremerie $this->getDoctrine()->getRepository(Categorie::class)->findOneBy(['nom' => 'Crémerie']);
  213.         $cidre $this->getDoctrine()->getRepository(Categorie::class)->findOneBy(['nom' => 'Cidres']);
  214.         $plateau $this->getDoctrine()->getRepository(Categorie::class)->findOneBy(['nom' => 'Plateaux']);
  215.         $nbPersonne $this->getDoctrine()->getRepository(Produit::class)->findNbPersonneDisplay();
  216.         $panier "";
  217.         if($connected){
  218.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  219.         }
  220.         $nbMax 12;
  221.         $nbProduit count($repository->findSearchForNbPage($data));
  222.         $nbPages intdiv($nbProduit$nbMax);
  223.         if($nbProduit $nbMax){
  224.             $nbPages $nbPages 1;
  225.         }
  226.         $currentPage $request->query->get('page'1) - 1;
  227.         return $this->render('pages/boutique.html.twig', [
  228.             'page' => $page,
  229.             'produits' => $produits,
  230.             'form' => $form->createView(),
  231.             'drive' => $drive,
  232.             'connected' => $connected,
  233.             'panier' => $panier,
  234.             'nbPages' => $nbPages,
  235.             'currentPage' => $currentPage,
  236.             'fromageDisplay' => !empty($fromage) && $fromage->getDisplay(),
  237.             'cremerieDisplay' => !empty($cremerie) && $cremerie->getDisplay(),
  238.             'cidreDisplay' => !empty($cidre) && $cidre->getDisplay(),
  239.             'plateauDisplay' => !empty($plateau) && $plateau->getDisplay(),
  240.             'nbPersonnesDisplay' => $nbPersonne,
  241.         ]);
  242.     }
  243.     /**
  244.      * @Route("/boutique/{slug}", name="produit")
  245.      */
  246.     public function produit(string $slugEntityManagerInterface $emSecurity $security): Response
  247.     {
  248.         $produit $this->getDoctrine()->getRepository(Produit::class)->findOneBy(['slug' => $slug]);
  249.         $produits $this->getDoctrine()->getRepository(Produit::class)->sixRandomWithCategorie($em$produit->getCategorie(), $produit->getId());
  250.         $photoProduits $this->getDoctrine()->getRepository(Produit::class)->findAll();
  251.         $drive $this->getDoctrine()->getRepository(Drive::class)->findOneBy(['id' => 1]);
  252.         $connected $security->getUser();
  253.         
  254.         $page = [
  255.             'id' => "fromage",
  256.             'titre' => $produit->getNom(),
  257.         ];
  258.         
  259.         $panier "";
  260.         if($connected){
  261.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  262.         }
  263.         if ($produit->getDisplay() == false){
  264.             return $this->redirectToRoute('boutique');
  265.         }
  266.         return $this->render('pages/produit.html.twig', [
  267.             'page' => $page,
  268.             'produit' => $produit,
  269.             'produits' => $produits,
  270.             'photoProduits' => $photoProduits,
  271.             'drive' => $drive,
  272.             'connected' => $connected,
  273.             'panier' => $panier
  274.         ]);
  275.     }
  276.     
  277.     /**
  278.      * @Route("/panier", name="panier")
  279.      */
  280.     public function panier(Request $requestSecurity $security): Response
  281.     {
  282.         $connected $security->getUser();
  283.         $drive $this->getDoctrine()->getRepository(Drive::class)->findOneBy(['id' => 1]);
  284.         $montant $this->getDoctrine()->getRepository(Montant::class)->findOneBy(['id' => 1]);
  285.         $panier "";
  286.         if($connected){
  287.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  288.             if ($panier){
  289.                 foreach($panier->getPanierProduits() as $produit){
  290.                     if ($produit->getIdProduit()->getDisplay() == false){
  291.                         $panierProduit $this->getDoctrine()->getRepository(PanierProduits::class)->findOneBy(['idPanier' => $produit->getIdPanier(), 'idProduit' => $produit->getIdProduit()]);
  292.                         
  293.                         $em $this->getDoctrine()->getManager();
  294.                         $em->remove($panierProduit);
  295.                         $em->flush();
  296.                         
  297.                         $panierProduits $this->getDoctrine()->getRepository(PanierProduits::class)->findBy(['idPanier' => $panier->getId()]);
  298.                         
  299.                         $nbProduit 0;
  300.                         $prixTotal 0;
  301.                         
  302.                         foreach ($panierProduits as $panierProduit){
  303.                             $nbProduit += $panierProduit->getNbProduit();
  304.                             $prixTotal += $panierProduit->getPrixTotal();
  305.                         }
  306.                         if($panier->getCodeId()){
  307.                             $panier->setCodeId(null);
  308.                         }
  309.                         
  310.                         $panier->setNbProduit($nbProduit);
  311.                         $panier->setPrixTotal($prixTotal);
  312.                         
  313.                         $em $this->getDoctrine()->getManager();
  314.                         $em->persist($panier);
  315.                         $em->flush();
  316.                     }
  317.                 }
  318.             }
  319.         }
  320.         
  321.         $page = [
  322.             'id' => "fromage",
  323.             'titre' => "Panier - Étape 1",
  324.         ];
  325.         return $this->render('pages/panier.html.twig', [
  326.             'page' => $page,
  327.             'drive' => $drive,
  328.             'panier' => $panier,
  329.             'connected' => $connected,
  330.             'montant' => $montant
  331.         ]);
  332.     }
  333.     /**
  334.      * @Route("/panier/suivant", name="panier_suivant")
  335.      */
  336.     public function panierSuivant(Request $requestSecurity $security): Response
  337.     {
  338.         $connected $security->getUser();
  339.         $drive $this->getDoctrine()->getRepository(Drive::class)->findOneBy(['id' => 1]);
  340.         $jours $this->getDoctrine()->getRepository(Livraison::class)->findBy(['actif' => 1]);
  341.         if(!$connected || $drive->getActive() == false){
  342.             return $this->redirectToRoute('profil');
  343.         }
  344.         
  345.         $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  346.         foreach($panier->getPanierProduits() as $produit){
  347.             if ($produit->getIdProduit()->getDisplay() == false){
  348.                 $panierProduit $this->getDoctrine()->getRepository(PanierProduits::class)->findOneBy(['idPanier' => $produit->getIdPanier(), 'idProduit' => $produit->getIdProduit()]);
  349.                 $em $this->getDoctrine()->getManager();
  350.                 $em->remove($panierProduit);
  351.                 $em->flush();
  352.                 $panierProduits $this->getDoctrine()->getRepository(PanierProduits::class)->findBy(['idPanier' => $panier->getId()]);
  353.                 $nbProduit 0;
  354.                 $prixTotal 0;
  355.                 
  356.                 foreach ($panierProduits as $panierProduit){
  357.                     $nbProduit += $panierProduit->getNbProduit();
  358.                     $prixTotal += $panierProduit->getPrixTotal();
  359.                 }
  360.                 if($panier->getCodeId()){
  361.                     $panier->setCodeId(null);
  362.                 }
  363.                 
  364.                 $panier->setNbProduit($nbProduit);
  365.                 $panier->setPrixTotal($prixTotal);
  366.                 
  367.                 $em $this->getDoctrine()->getManager();
  368.                 $em->persist($panier);
  369.                 $em->flush();
  370.             }
  371.         }
  372.         
  373.         if($panier == ""){
  374.             return $this->redirectToRoute('profil');
  375.         }
  376.         
  377.         $page = [
  378.             'id' => "fromage",
  379.             'titre' => "Panier - Étape 2",
  380.         ];
  381.         
  382.         $commande = new Commande();
  383.         $form $this->createForm(DateCommandeType::class, $commande);
  384.         $form->handleRequest($request);
  385.         
  386.         if ($form->isSubmitted()) {
  387.             $nbPanier count($this->getDoctrine()->getRepository(Panier::class)->findAll());
  388.             $panier->setDateLivraison(new \DateTime($form->get('date_livraison')->getViewData()));
  389.             $panier->setNom('KOA00' $nbPanier);
  390.             $em $this->getDoctrine()->getManager();
  391.             $em->persist($panier);
  392.             $em->flush();
  393.             $urlAxepta $this->module_bancaire_axepta($panier->getPrixTotal(), $panier->getNom());
  394.             return $this->redirect($urlAxepta);
  395.         }
  396.         return $this->render('pages/panier_suivant.html.twig', [
  397.             'page' => $page,
  398.             'drive' => $drive,
  399.             'jours' => $jours,
  400.             'panier' => $panier,
  401.             'connected' => $connected,
  402.             'form' => $form->createView(),
  403.         ]);
  404.     }
  405.     /**
  406.      * @Route("/panier/erreur", name="panier_erreur")
  407.      */
  408.     public function commandeErreur(Request $requestSecurity $security)
  409.     {
  410.         $connected $security->getUser();
  411.         $drive $this->getDoctrine()->getRepository(Drive::class)->findOneBy(['id' => 1]);
  412.         if(!$connected || $drive->getActive() == false){
  413.             return $this->redirectToRoute('profil');
  414.         }
  415.         $etat "danger";
  416.         $message "Une erreur s'est produite avec le paiement. Veuillez réessayer ultérieurement.";
  417.         $this->addFlash($etat$message);
  418.         return $this->redirectToRoute('panier_suivant');
  419.     }
  420.     /**
  421.      * @Route("/panier/valide", name="panier_valide")
  422.      */
  423.     public function commandeSuccess(Request $requestSecurity $securityMailerInterface $mailer): Response
  424.     {
  425.         $page = [
  426.             'id' => "fromage",
  427.             'titre' => "Récapitulatif de votre commande",
  428.         ];
  429.         $connected $security->getUser();
  430.         $drive $this->getDoctrine()->getRepository(Drive::class)->findOneBy(['id' => 1]);
  431.         $data $request->query->get('Data');
  432.         
  433.         if(!$connected || $drive->getActive() == false || !$data){
  434.             return $this->redirectToRoute('profil');
  435.         }
  436.         $blowfish $_ENV["BLOWFISH"];
  437.         $data hex2bin($data);
  438.         $decrypte openssl_decrypt($data'BF-ECB'$blowfishOPENSSL_RAW_DATA OPENSSL_ZERO_PADDING OPENSSL_DONT_ZERO_PAD_KEY);
  439.         $description $this->get_string_between($decrypte'Description=''&');
  440.         $refnr $this->get_string_between($decrypte'refnr=''&');
  441.         
  442.         $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['nom' => $refnr]);
  443.         
  444.         if($panier == "" || $description != 'success'){
  445.             return $this->redirectToRoute('profil');
  446.         }
  447.         
  448.         $commande = new Commande();
  449.         $statut $this->getDoctrine()->getRepository(Statut::class)->findOneBy(['id' => 1]);
  450.         $commande->setDateLivraison($panier->getDateLivraison());
  451.         $commande->setStatutId($statut);
  452.         $commande->setCodeId($panier->getCodeId());
  453.         $commande->setPrixTotal($panier->getPrixTotal());
  454.         $commande->setClientId($panier->getClientId());
  455.         $commande->setPanierId($panier);
  456.         $commande->setNom($refnr);
  457.         $em $this->getDoctrine()->getManager();
  458.         $em->persist($commande);
  459.         $panier->setCommande(1);
  460.         $em->persist($panier);
  461.         $em->flush();
  462.         $email = new TemplatedEmail();
  463.         $email->from($this->getParameter('mailer_noreply'))
  464.             ->to($this->getParameter('mailer_cmd'))
  465.             ->subject('Commande - Koaven Fromagerie')
  466.             ->htmlTemplate('emails/mailCommandeKoaven.html.twig')
  467.             ->context(array(
  468.                 'client' => $connected,
  469.                 'commande' => $commande
  470.             ))
  471.         ;
  472.         $emailUser = new TemplatedEmail();
  473.         $emailUser->from($this->getParameter('mailer_cmd'))
  474.             ->to($connected->getUserIdentifier())
  475.             ->subject('Confirmation de commande - Koaven Fromagerie')
  476.             ->htmlTemplate('emails/mailCommandeClient.html.twig')
  477.             ->context(array(
  478.                 'client' => $connected,
  479.                 'commande' => $commande
  480.             ))
  481.         ;
  482.         $message "Votre commande a bien été pris en compte, vous allez recevoir un email.";
  483.         $etat "success";
  484.         try{
  485.             $mailer->send($email);
  486.             $mailer->send($emailUser);
  487.         } catch (TransportExceptionInterface $e)
  488.         {
  489.             $etat "danger";
  490.             $message "Une erreur s'est produite. Veuillez réessayer ultérieurement.";
  491.         }
  492.         $this->addFlash($etat$message);
  493.         return $this->render('pages/panier_valide.html.twig', [
  494.             'page' => $page,
  495.             'connected' => $connected,
  496.             'commande' => $commande,
  497.             'panier' => $panier
  498.         ]);
  499.     }
  500.     /**
  501.      * @Route("/profil", name="profil")
  502.      */
  503.     public function profil(Security $security): Response
  504.     {
  505.         
  506.         $page = [
  507.             'id' => "presentation",
  508.             'titre' => "Profil",
  509.         ];
  510.         $connected $security->getUser();
  511.         $panier "";
  512.         $user null;
  513.         if($connected){
  514.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  515.             $user $this->getDoctrine()->getRepository(Client::class)->findOneBy(['id' => $connected->getId()]);
  516.         }
  517.         return $this->render('pages/profil.html.twig', [
  518.             'page' => $page,
  519.             'connected' => $connected,
  520.             'panier' => $panier,
  521.             'user' => $user
  522.         ]);
  523.     }
  524.     /**
  525.      * @Route("/commande", name="commande")
  526.      */
  527.     public function commande(CommandeRepository $repositorySecurity $security): Response
  528.     {
  529.         
  530.         $page = [
  531.             'id' => "presentation",
  532.             'titre' => "Commande",
  533.         ];
  534.         $connected $security->getUser();
  535.         if(!$connected){
  536.             return $this->redirectToRoute('profil');
  537.         }
  538.         
  539.         $commandes $repository->findBy(['clientId' => $connected->getId()]);
  540.         $panier "";
  541.         if($connected){
  542.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  543.         }
  544.         return $this->render('pages/commande.html.twig', [
  545.             'page' => $page,
  546.             'commandes' => $commandes,
  547.             'panier' => $panier
  548.         ]);
  549.     }
  550.     /**
  551.      * @Route("/commande/{id}", name="commande_detail")
  552.      */
  553.     public function commandeDetail(int $id,CommandeRepository $repositorySecurity $security): Response
  554.     {
  555.         
  556.         $connected $security->getUser();
  557.         if(!$connected){
  558.             return $this->redirectToRoute('profil');
  559.         }
  560.         
  561.         $commande $this->getDoctrine()->getRepository(Commande::class)->findOneBy(['id' => $id]);
  562.         if($commande->getClientId()->getId() != $connected->getId()){
  563.             return $this->redirectToRoute('profil');
  564.         }
  565.         
  566.         $panier "";
  567.         if($connected){
  568.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  569.         }
  570.         
  571.         $page = [
  572.             'id' => "presentation",
  573.             'titre' => $commande->getDateCreation(),
  574.         ];
  575.         return $this->render('pages/commande_detail.html.twig', [
  576.             'page' => $page,
  577.             'commande' => $commande,
  578.             'panier' => $panier
  579.         ]);
  580.     }
  581.     /**
  582.      * @Route("/commande/repasser/{id}", name="commande_repasser")
  583.      */
  584.     public function commandeRepasser(int $id,CommandeRepository $repositorySecurity $security): Response
  585.     {
  586.         
  587.         $connected $security->getUser();
  588.         if(!$connected){
  589.             return $this->redirectToRoute('profil');
  590.         }
  591.         
  592.         $commande $this->getDoctrine()->getRepository(Commande::class)->findOneBy(['id' => $id]);
  593.         if($commande->getClientId()->getId() != $connected->getId()){
  594.             return $this->redirectToRoute('profil');
  595.         }
  596.         
  597.         $panier "";
  598.         if($connected){
  599.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  600.             $panierCmd $commande->getPanierId();
  601.             if(!$panier){
  602.                 $panier = new Panier();
  603.                 $panier->setClientId($connected);
  604.                 $panier->setNbProduit(0);
  605.                 $panier->setPrixTotal(0);
  606.                 $panier->setCommande(0);
  607.             }
  608.             $em $this->getDoctrine()->getManager();
  609.             $em->persist($panier);
  610.             $em->flush();
  611.             $nbTotal 0;
  612.             $prixTotal 0;
  613.             foreach($panierCmd->getPanierProduits() as $ancienPanierProduit){
  614.                 $panierProduit $this->getDoctrine()->getRepository(PanierProduits::class)->findOneBy(['idPanier' => $panier->getId(), 'idProduit' => $ancienPanierProduit->getIdProduit()->getId()]);
  615.                 if ($ancienPanierProduit->getIdProduit()->getDisplay()){
  616.                     if(!$panierProduit){
  617.                         $panierProduit = new PanierProduits();
  618.                         $panierProduit->setIdPanier($panier);
  619.                         $panierProduit->setIdProduit($ancienPanierProduit->getIdProduit());
  620.                         $panierProduit->setNbProduit($ancienPanierProduit->getNbProduit());
  621.                         $panierProduit->setPrixTotal($ancienPanierProduit->getPrixTotal());
  622.                         $nbTotal $nbTotal $ancienPanierProduit->getNbProduit();
  623.                         $prixTotal $prixTotal $ancienPanierProduit->getPrixTotal();
  624.                     } else {
  625.                         $nb $panierProduit->getNbProduit() + $ancienPanierProduit->getNbProduit();
  626.                         $prix $panierProduit->getIdProduit()->getPrixUnitaire() * $nb;
  627.                         $panierProduit->setNbProduit($nb);
  628.                         $panierProduit->setPrixTotal($prix);
  629.                         $nbTotal $nbTotal $nb;
  630.                         $prixTotal $prixTotal $prix;
  631.                     }
  632.                     $em $this->getDoctrine()->getManager();
  633.                     $em->persist($panierProduit);
  634.                     $em->flush();
  635.                 }
  636.             }
  637.             $nb $panier->getNbProduit() + $nbTotal;
  638.             $prix $panier->getPrixTotal() + $prixTotal;
  639.             $panier->setNbProduit($nb);
  640.             $panier->setPrixTotal($prix);
  641.             $em $this->getDoctrine()->getManager();
  642.             $em->persist($panier);
  643.             $em->flush();
  644.         }
  645.         return $this->redirectToRoute('commande_detail', array('id' => $id));
  646.     }
  647.     /**
  648.      * @Route("/edit", name="edit")
  649.      */
  650.     public function edit(Security $securityRequest $requestUserPasswordEncoderInterface $passwordEncoder): Response
  651.     {
  652.         
  653.         $page = [
  654.             'id' => "presentation",
  655.             'titre' => "Modification du profil",
  656.         ];
  657.         $connected $security->getUser();
  658.         if(!$connected){
  659.             return $this->redirectToRoute('profil');
  660.         }
  661.         
  662.         $panier "";
  663.         if($connected){
  664.             $panier $this->getDoctrine()->getRepository(Panier::class)->findOneBy(['clientId' => $connected->getId(), 'commande' => 0]);
  665.         }
  666.         $user $this->getDoctrine()->getRepository(Client::class)->findOneBy(['id' => $connected->getId()]);
  667.         $form $this->createForm(ClientType::class, $user);
  668.         $form->handleRequest($request);
  669.         if ($form->isSubmitted() && $form->isValid()) {
  670.             $user->setPassword(
  671.                 $passwordEncoder->encodePassword(
  672.                     $user,
  673.                     $form->get('plainPassword')->getData()
  674.                 )
  675.             );
  676.  
  677.             $em $this->getDoctrine()->getManager();
  678.             $em->persist($user);
  679.             $em->flush();
  680.             $etat "success";
  681.             $message "Le profil a bien été modifié";
  682.             $this->addFlash($etat$message);
  683.  
  684.             return $this->redirectToRoute('profil');
  685.         }
  686.         return $this->render('pages/edit_profil.html.twig', [
  687.             'page' => $page,
  688.             'connected' => $connected,
  689.             'form' => $form->createView(),
  690.             'panier' => $panier
  691.         ]);
  692.     }
  693.     function get_string_between($string$start$end){
  694.         $string ' ' $string;
  695.         $ini strpos($string$start);
  696.         if ($ini == 0) return '';
  697.         $ini += strlen($start);
  698.         $len strpos($string$end$ini) - $ini;
  699.         return substr($string$ini$len);
  700.     }
  701.     function module_bancaire_axepta($prix$nom){
  702.         $merchantId $_ENV["MERCHANT_ID"];;
  703.         $hmac $_ENV["HMAC"];
  704.         $urlSuccess $_ENV["URL_SUCCESS"];
  705.         $urlFailure $_ENV["URL_FAILURE"];
  706.         $urlNotify $_ENV["URL_NOTIFY"];
  707.         $blowfish $_ENV["BLOWFISH"];
  708.         $prixFormat number_format($prix2','' ');
  709.         $formatAxepta str_replace(','''$prixFormat);
  710.         $formatAxepta str_replace(' '''$formatAxepta);
  711.         $stringForHmac "**"$merchantId ."*"$formatAxepta "*EUR";
  712.         $mac hash_hmac('sha256'$stringForHmac$hmac);
  713.         $info "MerchantID="$merchantId ."&RefNr="$nom."&Amount="$formatAxepta ."&Currency=EUR&URLSuccess="$urlSuccess ."&URLFailure="$urlFailure ."&URLNotify="$urlNotify ."&Response=encrypt&MAC="$mac;
  714.         $len strlen($info);
  715.         
  716.         $encrypt openssl_encrypt($info'BF-ECB'$blowfishOPENSSL_RAW_DATA);
  717.         $data bin2hex($encrypt);
  718.         $url "https://paymentpage.axepta.bnpparibas/payssl.aspx?MerchantID="$merchantId."&Data="$data ."&Len="$len ."&Template=Cards_BNP_v1&Language=fr&CCTemplate=Cards_v1&SDDTemplate=DirectDebit_v1&URLBack=https%3A%2F%2Fwww.koaven.bzh%2Fboutique&CustomField1="$prixFormat ."€&PayType=0";
  719.         
  720.         return $url;
  721.     }
  722. }