src/Controller/Front/ProductController.php line 521

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Avis;
  4. use App\Services\File;
  5. use App\Entity\Pack;
  6. use App\Entity\Ticket;
  7. use App\Entity\ImageComment;
  8. use App\Form\AvisType;
  9. use App\Services\Mail;
  10. use App\Entity\Product;
  11. use App\Entity\Category;
  12. use App\Entity\Messaging;
  13. use App\Entity\SubCategory;
  14. use App\Entity\ContactProduct;
  15. use App\Entity\PlanningCompany;
  16. use App\Entity\ProductOption;
  17. use App\Form\TicketProductType;
  18. use App\Form\ContactProductType;
  19. use App\Traits\FilterPriceTrait;
  20. use App\Repository\AvisRepository;
  21. use App\Repository\TicketRepository;
  22. use App\Repository\ProductRepository;
  23. use App\Repository\CategoryRepository;
  24. use App\Repository\LocationRepository;
  25. use App\Repository\WishListRepository;
  26. use App\Entity\TransporteurWeightPrice;
  27. use App\Entity\User;
  28. use App\Repository\DepartmentRepository;
  29. use App\Repository\ProductOptionRepository;
  30. use Doctrine\ORM\EntityManagerInterface;
  31. use App\Repository\ReservationRepository;
  32. use App\Repository\SubCategoryRepository;
  33. use Knp\Component\Pager\PaginatorInterface;
  34. use App\Repository\TypePrestationRepository;
  35. use Symfony\Component\HttpFoundation\Request;
  36. use Symfony\Component\Routing\Annotation\Route;
  37. use App\Repository\TransporteurWeightPriceRepository;
  38. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  39. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  40. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  41. use App\Services\Filter;
  42. class ProductController extends AbstractController
  43. {
  44.     use FilterPriceTrait;
  45.     /**
  46.      * @var EntityManagerInterface
  47.      */
  48.     private $em;
  49.     public function __construct(EntityManagerInterface $em)
  50.     {
  51.         $this->em $em;
  52.     }
  53.     /**
  54.      * @Route("/recherche/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_search")
  55.      */
  56.     public function searchFilter(int $pageRequest $requestDepartmentRepository $departmentRepositoryCategoryRepository $categoryRepositoryProductRepository $productRepositoryPaginatorInterface $paginatorSessionInterface $session,LocationRepository $locationRepositoryReservationRepository $reservationRepository)
  57.     {
  58.         if ($request->isMethod('POST')) {
  59.               if ($request->get('keyword') || $request->get('type') || $request->get('department_filter') || $request->get('department_filter') || $request->get('minprice_filter') ||
  60.                 $request->get('maxprice_filter') || $request->get('category') || $request->get('weddingdate') || $request->get('nb_guest')) {
  61.                 $parameters = [
  62.                     'department' => $request->get('department_filter') !== '' $request->get('department_filter') : null,
  63.                     'categoryMaster' => $request->get('category_master') !== '' $request->get('category_master') : null,
  64.                     'min_price' => $request->get('minprice_filter') !== '' $request->get('minprice_filter') : null,
  65.                     'max_price' => $request->get('maxprice_filter') !== '' $request->get('maxprice_filter') : null,
  66.                     'weddingdate' => $request->get('weddingdate') !== '' $request->get('weddingdate') : null,
  67.                     'category' => !empty($request->get('category')) ? $request->get('category') : null,
  68.                     'nbGuest' => !empty($request->get('nb_guest')) ? $request->get('nb_guest') : null,
  69.                     'type' => !empty($request->get('type')) ? $request->get('type') : null,
  70.                     'keyword' => !empty($request->get('keyword')) ? $request->get('keyword') : null,
  71.                 ];
  72.                 $session->set('department'$request->get('department_filter'));
  73.                 $session->set('min_price'$request->get('minprice_filter'));
  74.                 $session->set('max_price'$request->get('maxprice_filter'));
  75.                 $session->set('category'$request->get('category'));
  76.                 $session->set('weddingdate'$request->get('weddingdate'));
  77.                 $session->set('nbGuest'$request->get('nb_guest'));
  78.                 $session->set('type'$request->get('type'));
  79.                 $session->set('keyword'$request->get('keyword'));
  80.               
  81.                 // For displaying names
  82.                 if ($parameters['department'] && $parameters['department'] !== 'Lieu') {
  83.                     $department $departmentRepository->find($parameters['department']);
  84.                     $session->set('departmentName'$department->getName());
  85.                 }
  86.                 $categoryBackground null;
  87.                 if ($parameters['categoryMaster'] && !is_array($parameters['categoryMaster'])) {
  88.                     $category $categoryRepository->find($parameters['categoryMaster']);
  89.                     if ($category) {
  90.                         $categoryBackground $category;
  91.                         $session->set('categoryName'$category->getName());
  92.                     }
  93.                 }
  94.                 $products $productRepository->searchProduct($parameters);
  95.                 $dateSearch str_replace('/''-'$parameters['weddingdate']);
  96.                 $datetime = new \DateTime($dateSearch);
  97.                 $datetime->format('Y-m-d');
  98.                 // Calcul count services / products
  99.                 $countService 0;
  100.                 $countProducts 0;
  101.                 /** @var Product $product */
  102.                 foreach ($products as $key => $product) {
  103.                     $isService $product->getSubCategories()->filter(
  104.                         function ($entry) use ($countService$countProducts) {
  105.                             return $entry->getIsService();
  106.                         }
  107.                     );
  108.                     if ($isService) {
  109.                         $countService $countService 1;
  110.                     } else {
  111.                         $countProducts $countProducts 1;
  112.                     }
  113.                 
  114.                     /** @var PlanningCompany $planning */
  115.                     foreach ($product->getCompany()->getPlanningCompanies() as $planning) {
  116.                         if ($planning->getDateStamp() == $datetime->getTimestamp()) {
  117.                             unset($products[$key]);
  118.                         }
  119.                     }
  120.                     
  121.                     if ($product->getTypePrestation()) {
  122.                           
  123.                         if ($product->getTypePrestation()->getLabel() == 'location') {
  124.                             $prodEnLocation=$locationRepository->getLocationByProduit($product);
  125.    
  126.                             foreach($prodEnLocation as $lp){
  127.                                 if (($datetime->getTimestamp() >= $lp->getStartAt()->getTimestamp()) && ($datetime->getTimestamp() <= $lp->getEndAt()->getTimestamp())) {
  128.                                     unset($products[$key]);
  129.                                 }
  130.                             }
  131.                                     
  132.                         }
  133.                         else
  134.                         {
  135.                             $prodEnReservation=$reservationRepository->getreservationByProduit($product);
  136.                             foreach($prodEnReservation as $reserv){
  137.            
  138.                                 if ($datetime->getTimestamp() == $reserv->getReservationPlannedAt()->getTimestamp()) {
  139.                                     unset($products[$key]);
  140.                                 }
  141.                             }
  142.                         }
  143.                     }
  144.                     
  145.                 }
  146.                 $pagination $paginator->paginate(
  147.                     $products,
  148.                     $page/*page number*/
  149.                     15 /*limit per page*/
  150.                 );
  151.                 
  152.                 return $this->render('front/product/list.html.twig', [
  153.                     'products' => $pagination,
  154.                     'countProducts' => $countProducts,
  155.                     'countServices' => $countService,
  156.                     'categoryBackground' => $categoryBackground
  157.                 ]);
  158.             }
  159.         } else {
  160.             $parameters = [
  161.                 'department' => $session->get('department'),
  162.                 'min_price' => $session->get('min_price'),
  163.                 'max_price' => $session->get('max_price'),
  164.                 'weddingdate' => $session->get('weddingdate'),
  165.                 'category' => $session->get('category'),
  166.                 'nbGuest' => $session->get('nbGuest'),
  167.                 'type' => $session->get('type'),
  168.                 'keyword' => $session->get('keyword')
  169.             ];
  170.             $products $productRepository->searchProduct($parameters);
  171.             $pagination $paginator->paginate(
  172.                 $products,
  173.                 $page/*page number*/
  174.                 15 /*limit per page*/
  175.             );
  176.             $categoryBackground null;
  177.             if ( isset( $parameters['categoryMaster']) && !is_array($parameters['categoryMaster'])) {
  178.                 $category $categoryRepository->find($parameters['categoryMaster']);
  179.                 if ($category) {
  180.                     $categoryBackground $category;
  181.                     $session->set('categoryName'$category->getName());
  182.                 }
  183.             }
  184.             $countService 0;
  185.             $countProducts 0;
  186.             $dateSearch str_replace('/''-'$parameters['weddingdate']);
  187.             $datetime = new \DateTime($dateSearch);
  188.             $datetime->format('Y-m-d');
  189.             /** @var Product $product */
  190.             foreach ($products as $key => $product) {
  191.                 $isService $product->getSubCategories()->filter(
  192.                     function ($entry) use ($countService$countProducts) {
  193.                         return $entry->getIsService();
  194.                     }
  195.                 );
  196.                 if ($isService) {
  197.                     $countService $countService 1;
  198.                 } else {
  199.                     $countProducts $countProducts 1;
  200.                 }
  201.                 /** @var PlanningCompany $planning */
  202.                 foreach ($product->getCompany()->getPlanningCompanies() as $planning) {
  203.                     if ($planning->getDateStamp() == $datetime->getTimestamp()) {
  204.                         unset($products[$key]);
  205.                     }
  206.                 }
  207.             }
  208.             return $this->render('front/product/list.html.twig', [
  209.                 'products' => $pagination,
  210.                 'countProducts' => $countProducts,
  211.                 'countServices' => $countService,
  212.                 'categoryBackground' => $categoryBackground
  213.             ]);
  214.         }
  215.         $session->remove('department');
  216.         $session->remove('min_price');
  217.         $session->remove('max_price');
  218.         $session->remove('category');
  219.         //$session->remove('weddingdate');
  220.         $session->remove('nbGuest');
  221.         $session->remove('departmentName');
  222.         $session->remove('categoryName');
  223.         return $this->redirectToRoute('front_product_products');
  224.     }
  225.     /**
  226.      * @Route("/services/categorie/{slug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_category_slug")
  227.      */
  228.     public function listByCategory(int $pageCategory $categoryProductRepository $productRepositoryPaginatorInterface $paginator)
  229.     {
  230.         $products $productRepository->productsByCategory($category);
  231.         $pagination $paginator->paginate(
  232.             $products,
  233.             $page/*page number*/
  234.             15 /*limit per page*/
  235.         );
  236.         return $this->render('front/product/list.html.twig', [
  237.             'products' => $pagination,
  238.             'countProducts' => count($products)
  239.         ]);
  240.     }
  241.     /**
  242.      * @Route("/services/evenements/{subCategorySlug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_category_events")
  243.      */
  244.     public function listByCategoryEvent(SubCategory $subCategoryint $pageProductRepository $productRepositoryPaginatorInterface $paginator)
  245.     {
  246.         $products $productRepository->productsByCategoryMaster($subCategory);
  247.         $pagination $paginator->paginate(
  248.             $products,
  249.             $page/*page number*/
  250.             15 /*limit per page*/
  251.         );
  252.         return $this->render('front/product/list.html.twig', [
  253.             'products' => $pagination,
  254.             'countProducts' => count($products)
  255.         ]);
  256.     }
  257.     /**
  258.      * @Route("/services/ordre/{slug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_category")
  259.      */
  260.     public function orderByCategory(string $slugint $pageProductRepository $productRepositoryPaginatorInterface $paginator)
  261.     {
  262.         if ($slug === 'note') {
  263.             $products $productRepository->orderByNotes();
  264.         } elseif ($slug === 'reserved') {
  265.             $products $productRepository->orderByCommands();
  266.         }
  267.         $pagination $paginator->paginate(
  268.             $products,
  269.             $page/*page number*/
  270.             15 /*limit per page*/
  271.         );
  272.         return $this->render('front/product/list.html.twig', [
  273.             'products' => $pagination,
  274.             'countProducts' => count($products)
  275.         ]);
  276.     }
  277.     /**
  278.      * @Route("/services/sous-categorie/{subCategorySlug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_subcategory")
  279.      */
  280.     public function listBySubCategory(int $pageSubCategory $subCategoryProductRepository $productRepositoryPaginatorInterface $paginator)
  281.     {
  282.         $products $productRepository->productsBySubCategory($subCategory);
  283.         $pagination $paginator->paginate(
  284.             $products,
  285.             $page/*page number*/
  286.             15 /*limit per page*/
  287.         );
  288.         return $this->render('front/product/list.html.twig', [
  289.             'products' => $pagination,
  290.             'countProducts' => count($products)
  291.         ]);
  292.     }
  293.     /**
  294.      * @Route("/services/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_products")
  295.      */
  296.     public function products(int $pageProductRepository $productRepositoryPaginatorInterface $paginatorSessionInterface $session)
  297.     {
  298.         $session->remove('department');
  299.         $session->remove('min_price');
  300.         $session->remove('max_price');
  301.         $session->remove('category');
  302.         $products $productRepository->findAllServices();
  303.         // dd($products);
  304.         $pagination $paginator->paginate(
  305.             $products,
  306.             $page/*page number*/
  307.             15 /*limit per page*/
  308.         );
  309.         return $this->render('front/product/list.html.twig', [
  310.             'products' => $pagination,
  311.             'countProducts' => count($products)
  312.         ]);
  313.     }
  314.     /**
  315.      * @Route("/service/{slug}/{subCategorySlug}/{product_id}/{productSlug}", name="front_product_single")
  316.      * @ParamConverter("product", options={"id" = "product_id"})
  317.      */
  318.     public function productSingle(
  319.         TicketRepository $ticketRepository,
  320.         Category $category,
  321.         Request $request,
  322.         Product $product,
  323.         SessionInterface $session,
  324.         WishListRepository $wishListRepository,
  325.         ProductRepository $productRepository,
  326.         AvisRepository $avisRepository,
  327.         // User $user,
  328.         Mail $mail,
  329.         File $file
  330.         )
  331.     {
  332.         $ticket = new Ticket();
  333.         $formTicket $this->createForm(TicketProductType::class, $ticket, ['company' => $this->getUser()])->handleRequest($request);
  334.         if ($formTicket->isSubmitted() && $formTicket->isValid()) {
  335.             if (!$this->getUser()) {
  336.                 $session->set('chatInCurse'true);
  337.                 return $this->redirectToRoute('app_login');
  338.             }
  339.             if($this->getUser()!= null) {
  340.                 $ticket->setNumero(strtoupper(uniqid()))
  341.                     ->setSubject('contact prestataire')
  342.                     ->setProduct($product)
  343.                     ->setCreatedBy($this->getUser());
  344.             } else {
  345.                 $session->set('chatInCurse'true);
  346.                 return $this->redirectToRoute('app_login');
  347.             }
  348.             $messaging = new Messaging();
  349.             $messaging->setText($request->request->get('ticket_product')['messagings']['text']);
  350.             $messaging->setTicket($ticket);
  351.             $messaging->setMessageUser($this->getUser());
  352.             
  353.             $ticket->addMessaging($messaging);
  354.             $this->em->persist($ticket);
  355.             $this->em->persist($messaging);
  356.             $this->em->flush();
  357.             return $this->redirectToRoute('front_client_space_tickets');
  358.         } 
  359.         // else if($this->getUser() == null) {
  360.         //     echo '<message class="alert alert-danger">Vous devez vous connecter</message>';
  361.         //     return $this->redirectToRoute('app_login');
  362.         // }
  363.         if ($session->get('products')) {
  364.             $productExistInSession false;
  365.             foreach ($session->get('products') as $productSession) {
  366.                 if (array_search($product->getId(), $productSession)) {
  367.                     $productExistInSession true;
  368.                 }
  369.             }
  370.         } else {
  371.             $productExistInSession false;
  372.         }
  373.         $avis = new Avis();
  374.         $form $this->createForm(AvisType::class, $avis)->handleRequest($request);
  375.         $lastProducts $productRepository->getOtherProductsCompanyNotSingle($product->getCompany(), $product);
  376.         if ($form->isSubmitted() && $form->isValid()) {
  377.             $avis->setProduct($product);
  378.             $avis->setClient($this->getUser());
  379.             $newGlobalNote = ($avis->getCommunication()+$avis->getPrice()+$avis->getConformDescription()+$avis->getFiability()+$avis->getServiceQuality()+$avis->getSpeed()) / 6;
  380.             $avis->setGlobalNote($newGlobalNote);
  381.             $this->em->persist($avis);
  382.             $this->em->flush();
  383.             if ($request->files->get('avis') !== null) { 
  384.                 foreach($request->files->get('avis')['imageComments'] as $image){
  385.                     foreach($image as $img){
  386.                         if( $img !== null){
  387.                             $commentimage=$avisRepository->findById(['id'=>$avis->getId()]);
  388.                             $imagecomment= new ImageComment();
  389.                             $filename $file->uploadImageComment($img);
  390.                             $imagecomment->setAvis($avis);
  391.                             $imagecomment->setUrl($filename);
  392.                             $this->em->persist($imagecomment);
  393.                         
  394.                         }
  395.                     }
  396.                 }
  397.                 $this->em->flush();
  398.             }
  399.         
  400.             $this->addFlash('success''Merci pour votre avis !');
  401.             return $this->redirectToRoute('front_product_single', [
  402.                 // 'slug' => $product->getSubCategory()->getCategory()->getSlug(),
  403.                 'slug' => $product->getSubCategories()->toArray()[0]->getCategories()->toArray()[0]->getSlug(),
  404.                 'subCategorySlug' => $product->getSubCategories()->toArray()[0]->getSubCategorySlug(),
  405.                 'product_id' => $product->getId(),
  406.                 'productSlug' => $product->getProductSlug()
  407.             ]);
  408.         }
  409.         $contactProduct = new ContactProduct();
  410.         $formContactProduct $this->createForm(ContactProductType::class, $contactProduct)->handleRequest($request);
  411.         if ($formContactProduct->isSubmitted() && $formContactProduct->isValid()) {
  412.             $contactProduct->setProduct($product);
  413.             $this->em->persist($contactProduct);
  414.             $this->em->flush();
  415.             $mail->contactProvider($product->getCompany(), $contactProduct);
  416.             return $this->json([
  417.                 'status' => 'ok',
  418.                 'message' => 'Message envoyé !'
  419.             ]);
  420.         }
  421.         $productComments $avisRepository->getCommentsByArticle($product);
  422.         $productAvis $avisRepository->findBy(['product' => $product]);
  423.         $globalNote = ['totalNote' => 0'count' => 0];
  424.         $qualityService = ['totalNote' => 0'count' => 0];
  425.         $fiablity = ['totalNote' => 0'count' => 0];
  426.         $price = ['totalNote' => 0'count' => 0];
  427.         $speed = ['totalNote' => 0'count' => 0];
  428.         $conformDescription = ['totalNote' => 0'count' => 0];
  429.         $communication = ['totalNote' => 0'count' => 0];
  430.         foreach ($productAvis as $avis) {
  431.             $globalNote['totalNote'] = $globalNote['totalNote'] + $avis->getGlobalNote();
  432.             $globalNote['count'] = $globalNote['count'] + 1;
  433.             $qualityService['totalNote'] = $qualityService['totalNote'] + $avis->getServiceQuality();
  434.             $qualityService['count'] = $qualityService['count'] + 1;
  435.             $fiablity['totalNote'] = $fiablity['totalNote'] + $avis->getFiability();
  436.             $fiablity['count'] = $fiablity['count'] + 1;
  437.             $price['totalNote'] = $price['totalNote'] + $avis->getPrice();
  438.             $price['count'] = $price['count'] + 1;
  439.             $speed['totalNote'] = $speed['totalNote'] + $avis->getSpeed();
  440.             $speed['count'] = $speed['count'] + 1;
  441.             $conformDescription['totalNote'] = $conformDescription['totalNote'] + $avis->getConformDescription();
  442.             $conformDescription['count'] = $conformDescription['count'] + 1;
  443.             $communication['totalNote'] = $communication['totalNote'] + $avis->getCommunication();
  444.             $communication['count'] = $communication['count'] + 1;
  445.         }
  446.         
  447.         return $this->render('front/product/single.html.twig', [
  448.             'product' => $product,
  449.             'otherProducts' => $lastProducts,
  450.             'category' => $category,
  451.             'btnForm' => $productExistInSession,
  452.             'isWish' => $wishListRepository->findOneBy(['user' => $this->getUser(), 'product' => $product]),
  453.             'formComment' => $form->createView(),
  454.             'formTicket' => $formTicket->createView(),
  455.             'formContact' => $formContactProduct->createView(),
  456.             'productAvis' => $productComments,
  457.             'notes' => [
  458.                 'globalNote' => $globalNote,
  459.                 'qualityService' => $qualityService,
  460.                 'price' => $price,
  461.                 'speed' => $speed,
  462.                 'conformDescription' => $conformDescription,
  463.                 'communication' => $communication,
  464.             ]
  465.         ]);
  466.     }
  467.     /**
  468.      *@Route("/sendMessageAbout/{product_id}/{productSlug}", name="connection-test")
  469.      *@ParamConverter("product", options={"id" = "product_id"})
  470.      */
  471.     public function connectionTest(
  472.         SessionInterface $session
  473.     ) {
  474.         if ($this->getUser()== NULL) {
  475.             $session->set('chatInCurse'true);
  476.             return $this->redirectToRoute('app_login');
  477.         } 
  478.     }
  479.     /**
  480.      * @Route("/ajout-produit/{id}", name="front_product_add_product_basket")
  481.      */
  482.     public function addProductBasket(Product $productRequest $requestSessionInterface $session,SubCategoryRepository $subrepo,ProductOptionRepository $prodOptionrepo)
  483.     {
  484.         // dd(json_decode($request->get('groupOption')));
  485.         // dd($product->getProductOptions()->toArray());
  486.         $options $product->getProductOptions()->toArray();
  487.         // dd($options[1]);
  488.         // foreach ($request->get('qtyOption') as $key => $value) {
  489.         //     echo $value . "<br>";
  490.         // }
  491.         foreach ($options as $key => $value) {
  492.             // dd($value->getPQte());
  493.             if (isset($request->get('qtyOption')[$value->getId()]) && $request->get('qtyOption')[$value->getId()] > $value->getPQte()) {
  494.                 // return $this->json([
  495.                 //     'message' => 'error',
  496.                 //     'response' => 'Quantité option non disponible'
  497.                 // ]);
  498.             }
  499.         }
  500.         if (!$request->get('quantity')) {
  501.             return $this->json([
  502.                 'message' => 'error',
  503.                 'response' => 'Quantité incorrecte'
  504.             ]);
  505.         }
  506.         if ($request->get('quantity') > $product->getQuantity()) {
  507.             return $this->json([
  508.                 'message' => 'error',
  509.                 'response' => 'Quantité non disponible'
  510.             ]);
  511.         }
  512.         // $archivoption="";
  513.         if ($session->get('products')) {
  514.             
  515.             $allProducts $session->get('products');
  516.             $productExistInSession false;
  517.             foreach ($session->get('products') as $key => $productSession) {
  518.                 // if (!empty($productSession['options_fairepar'])) {
  519.                 //     $archivoption =$productSession['options_fairepar'];
  520.                 // }
  521.                 if (array_search($product->getId(), $productSession)) {
  522.                     $productExistInSession true;
  523.                     unset($allProducts[$key]);
  524.                     $session->set('products'$allProducts);
  525.                 }
  526.             }
  527.         } else {
  528.             $productExistInSession false;
  529.         }
  530.      
  531.         if ($productExistInSession) {
  532.             return $this->json([
  533.                 'message' => 'ok',
  534.                 'response' => 'removed'
  535.             ]);
  536.         }
  537.     
  538.         $sub=$subrepo->getSubcategoryByProduit($product);
  539.         if ($sub[0]->getSubCategorySlug() =="faire-part") {
  540.             $tabOption=[];
  541.             $tabId=[];
  542.             if (!empty($request->get('options'))) {
  543.                 foreach ($request->get('options') as $key => $value) {
  544.                     $tabId[]=$key;
  545.                 }   
  546.             }
  547.             if (!empty($request->get('idoptions'))) {
  548.                 $idoption =$request->get('idoptions');
  549.                 $tabIdexplode(',',$idoption);
  550.             
  551.              }
  552.             for ($f=0$f <sizeof($tabId) ; $f++) { 
  553.                 $existe1 false;
  554.                 if (!empty($request->get('tail'))) {
  555.                     
  556.                     for ($i=0$i json_decode($request->get('tail')); $i++) { 
  557.                         if (json_decode($request->get('OpId_'.$i))->idoption == $tabId[$f]) {
  558.                             $existe1=true;
  559.                             $tabOption["option_".$f]["idoption"]=json_decode($request->get('OpId_'.$i))->idoption json_decode($request->get('OpId_'.$i))->idoption null;
  560.                             $tabOption["option_".$f]["nomoption"]=json_decode($request->get('OpId_'.$i))->nomoption json_decode($request->get('OpId_'.$i))->nomoption null;
  561.                             $tabOption["option_".$f]["imageoption"]=json_decode($request->get('OpId_'.$i))->imageoption json_decode($request->get('OpId_'.$i))->imageoption null;
  562.                             $tabOption["option_".$f]["color"]=json_decode($request->get('OpId_'.$i))->color json_decode($request->get('OpId_'.$i))->color null;
  563.                             $tabOption["option_".$f]["form"]=json_decode($request->get('OpId_'.$i))->form json_decode($request->get('OpId_'.$i))->form null;
  564.                             $tabOption["option_".$f]["finition"]=json_decode($request->get('OpId_'.$i))->finition json_decode($request->get('OpId_'.$i))->finition null;
  565.                             $tabOption["option_".$f]["papier"]=json_decode($request->get('OpId_'.$i))->papier json_decode($request->get('OpId_'.$i))->papier null;
  566.                             $tabOption["option_".$f]["etiquette"]=json_decode($request->get('OpId_'.$i))->etiquette json_decode($request->get('OpId_'.$i))->etiquette null;
  567.                             $tabOption["option_".$f]["ruban"]=json_decode($request->get('OpId_'.$i))->ruban json_decode($request->get('OpId_'.$i))->ruban null;
  568.                             if (json_decode($request->get('OpId_'.$i))->quantite != null && json_decode($request->get('OpId_'.$i))->quantite != "Échantillon (0,00 â‚¬)" ) {
  569.                                 
  570.                                 $tabOption["option_".$f]["quantite"] =json_decode($request->get('OpId_'.$i))->quantite ? (int)explode(" "json_decode($request->get('OpId_'.$i))->quantite)[0] : null;
  571.                                 $tabOption["option_".$f]["price"]=json_decode($request->get('OpId_'.$i))->quantite ? (int)explode(" "json_decode($request->get('OpId_'.$i))->quantite)[2] : null;
  572.                             }
  573.                             else {
  574.                                 $tabOption["option_".$f]["quantite"] = 1;
  575.                                 $tabOption["option_".$f]["price"]= 0.00;
  576.                             }
  577.                         }
  578.                     }
  579.                 }
  580.                  
  581.                 if (!$existe1) {                 
  582.                             
  583.                             foreach ( $prodOptionrepo->findProduitOptionchecked($tabId[$f]) as $optionsProd) {
  584.                                 $tabOption["option_".$f]["idoption"]=$optionsProd->getId() ? $optionsProd->getId() : null;
  585.                                 $tabOption["option_".$f]["nomoption"]=$optionsProd->getName() ? $optionsProd->getName() : null;
  586.                                 $tabOption["option_".$f]["imageoption"]=$optionsProd->getImage1() ? $optionsProd->getImage1() : null;
  587.                                 $tabOption["option_".$f]["color"]=$optionsProd->getColorsOption() ? $optionsProd->getColorsOption()[0] : null;
  588.                                 $tabOption["option_".$f]["form"]=$optionsProd->getFormat() ? $optionsProd->getFormat()[0] : null;
  589.                                 $tabOption["option_".$f]["finition"]=$optionsProd->getFinition() ? $optionsProd->getFinition()[0] : null;
  590.                                 $tabOption["option_".$f]["papier"]=$optionsProd->getPapier() ? $optionsProd->getPapier()[0] : null;
  591.                                 $tabOption["option_".$f]["etiquette"]=$optionsProd->getEtiquette() ? $optionsProd->getEtiquette()[0] : null;
  592.                                 $tabOption["option_".$f]["ruban"]=$optionsProd->getRuban() ? $optionsProd->getRuban()[0] : null;
  593.                                 $tabOption["option_".$f]["quantite"] = 1;
  594.                                 $tabOption["option_".$f]["price"]= 0.00;
  595.                                 
  596.                             }
  597.                 }
  598.             }
  599.         
  600.             $product = [
  601.                 'productId' => $product->getId(),
  602.                 'quantity' => $request->get('quantity'),
  603.                 'size' => $request->get('size') ? $request->get('size') : null,
  604.                 'sizeRing' => $request->get('size_ring') ? $request->get('size_ring') : null,
  605.                 'nbGuest' => $request->get('nb_guest') ? $request->get('nb_guest') : null,
  606.                 'color' => $request->get('color') ? $request->get('color') : null,
  607.                 'options' => null,
  608.                 'options_fairepar' => $tabOption $tabOption null,
  609.                 'qtyOption' => $request->get('qtyOption') ? $request->get('qtyOption') : null
  610.             ];
  611.         }else {
  612.             $options=[];
  613.             // for ($g=0; $g < sizeof(json_decode($request->get('groupOption'))); $g++) { 
  614.             //     $options[]=json_decode($request->get('groupOption'))[g]['idoption'];
  615.             // }
  616.             foreach (json_decode($request->get('groupOption')) as $key => $gropOption) {
  617.                 foreach ($gropOption->labelo as $key => $lab) {
  618.                     $options[$gropOption->idoption][]=[
  619.                         "valeur"=> explode("#_#"$lab)[0],
  620.                         "prix"=> explode("#_#"$lab)[1],
  621.                         "qte"=>$gropOption->qte[$key]
  622.                     ];
  623.                 }
  624.                 // $options[]=$valer_prix; 
  625.                 // $options[]=$gropOption; 
  626.                 // $options[$gropOption->idoption]=$gropOption->labelo;
  627.                 // $options[$gropOption->idoption]['qte']=$gropOption->qte;
  628.             }
  629.             // dd($options);
  630.             $product = [
  631.                 'productId' => $product->getId(),
  632.                 'quantity' => $request->get('quantity'),
  633.                 'size' => $request->get('size') ? $request->get('size') : null,
  634.                 'sizeRing' => $request->get('size_ring') ? $request->get('size_ring') : null,
  635.                 'nbGuest' => $request->get('nb_guest') ? $request->get('nb_guest') : null,
  636.                 'color' => $request->get('color') ? $request->get('color') : null,
  637.                 // 'options' => $request->get('options') ? $request->get('options') : null,
  638.                 // 'qtyOption' => $request->get('qtyOption') ? $request->get('qtyOption') : null
  639.                 'options'=>$options
  640.             ];
  641.         }
  642.     //    dd($product);
  643.         if ($session->get('products')) {
  644.             $products $session->get('products');
  645.             array_push($products$product);
  646.             $session->set('products'$products);
  647.         } else {
  648.             $session->set('products', [$product]);
  649.         }
  650.         if (!empty($tabOption)) {
  651.             $session->set('archive'$tabOption);
  652.         }
  653.         return $this->json([
  654.             'message' => 'ok',
  655.             'response' => 'added'
  656.         ]);
  657.     }
  658.     /**
  659.      * @Route("/ajout-pack/{id}", name="front_product_add_pack_basket")
  660.      */
  661.     public function addPackToBasket(Pack $packSessionInterface $sessionRequest $request)
  662.     {
  663.         if (!$session->get('packs')) {
  664.             $session->set('packs'$pack->getId());
  665.         } else {
  666.             $session->remove('packs');
  667.             return $this->json([
  668.                 'message' => "ok",
  669.                 'response' => 'removed'
  670.             ]);
  671.         }
  672.         return $this->json([
  673.             'message' => 'ok',
  674.             'response' => 'added'
  675.         ]);
  676.     }
  677.     /**
  678.      * @Route("/get-subcategory", name="front_company_get_subcategory")
  679.      */
  680.     public function getSubCategory(Request $requestSubCategoryRepository $subCategoryRepository)
  681.     {
  682.         if ($request->get('data')) {
  683.             $idCategories json_decode($request->get('data'));
  684.             
  685.             $isClothing false;
  686.             $isColor false;
  687.             $isClothingRing false;
  688.             $isNbGuest false;
  689.             $isService false;
  690.             if ($idCategories->idCategory) {
  691.                 foreach ($idCategories as $idCategory) {
  692.                     foreach($idCategory as $idcat) {
  693.                         $subCategory $subCategoryRepository->find($idcat);
  694.                         $isClothing $subCategory->getIsClothing() ? true $isClothing;
  695.                         $isColor $subCategory->getIsColor() ? true $isColor;
  696.                         $isClothingRing $subCategory->getIsClothingRing() ? true $isClothingRing;
  697.                         $isNbGuest $subCategory->getIsNbGuest() ? true $isNbGuest;
  698.                         $isService $subCategory->getIsService() ? true $isService;
  699.                     }
  700.                 }
  701.             }
  702.         //    dd($isColor,$isFomat,$isFinition);
  703.             return $this->json([
  704.                 'isClothing' => $isClothing,
  705.                 'isColor' => $isColor,
  706.                 'isNbGuest' => $isNbGuest,
  707.                 'isClothingRing' => $isClothingRing,
  708.                 'isService' => $isService,
  709.                 'isClothingHTML' => $this->render('front/html/clothing.html.twig'),
  710.                 'isColorHTML' => $this->render('front/html/colors.html.twig'),
  711.                 'isNbGuestHTML' => $this->render('front/html/quantity.html.twig'),
  712.                 'isClothingRingHTML' => $this->render('front/html/clothing_ring.html.twig')
  713.             ]);
  714.         }
  715.     }
  716.     /**
  717.      * @Route("/get-subcategory-fairepart", name="front_company_get_subcategory-fairepart")
  718.      */
  719.     public function getSubCatFairepart(Request $requestSubCategoryRepository $subCategoryRepository,Filter $filtre)
  720.     {
  721.         if ($request->get('data')) {
  722.             $idCategories json_decode($request->get('data'));
  723.             
  724.             $isFairepart false;
  725.            
  726.             if ($idCategories->idCategory) {
  727.                 foreach ($idCategories as $idCategory) {
  728.                     foreach($idCategory as $idcat) {
  729.                         $subCategory $subCategoryRepository->find($idcat);
  730.                         $isFairepart $subCategory->getIsFairepart() ? true $isFairepart;
  731.                        
  732.                     }
  733.                 }
  734.             }
  735.             return $this->json([
  736.                 'isFairepart' =>  $isFairepart,
  737.                 'couleurs'=>$filtre->listecouleurs()
  738.             ]);
  739.         }
  740.     }
  741.      /**
  742.      * @Route("/get-type-prestation", name="front_company_get_typePrestation")
  743.      */
  744.     public function type_prestation(Request $requestTypePrestationRepository $typePrestationRepository)
  745.     {
  746.         if ($request->get('data')) {
  747.             $idtypePrests json_decode($request->get('data'));
  748.             // dd( $idtypePrests->idtypPrest);
  749.                 $id=1;
  750.                  $type=$typePrestationRepository->find($idtypePrests->idtypPrest); 
  751.                 $data['status']=200;
  752.                 $data['data']=$type;
  753.                 return $this->json($data200, [], [
  754.                     "groups" => "location:read"
  755.                 ]);
  756.         }else{
  757.             return $this->json([
  758.                 'status' => 400
  759.             ]);
  760.         }
  761.     }
  762.     /**
  763.      * @Route("/transporteur/calcul-cout", name="front_front_product_calcul_transporteur", methods={"POST"})
  764.      */
  765.     public function getTransporteursPrice(Request $requestTransporteurWeightPriceRepository $transporteurWeightPriceRepository)
  766.     {
  767.         $data json_decode($request->get('data'));
  768.         
  769.         if ($data->weightProduct) {
  770.             $transporteursWeight $transporteurWeightPriceRepository->getTransporteursPriceByWeight ($data->weightProduct);
  771.             return $this->json([
  772.                 'transporteurs' => $this->render('front/html/form_transporteurs.html.twig', ['transporteursWeight' => $transporteursWeight])
  773.             ]);
  774.         }
  775.     }
  776.     /**
  777.      * @Route("/transporteur/getable", name="front_front_transporteur_getable", methods={"POST"})
  778.      */
  779.     public function getCompanyTransporteursPrice(Request $requestTransporteurWeightPriceRepository $transporteurWeightPriceRepository){
  780.         $data json_decode($request->get('data'));
  781.         
  782.         if ($data->weightProduct) {
  783.             //$transporteursWeight = $transporteurWeightPriceRepository->getTransporteursPriceByWeight($data->weightProduct);
  784.             $transporteursWeight $transporteurWeightPriceRepository->getActiveTransporteursPriceByWeight($data->weightProduct);
  785.             return $this->json([
  786.                 'transporteurs' => $this->render('front/html/form_transporteurs.html.twig', ['transporteursWeight' => $transporteursWeight])
  787.             ]);
  788.         }
  789.     }
  790.     /**
  791.      * @Route("option/{id}", name="Options")
  792.      */
  793.     public function Option(ProductOption $prodOption){
  794.         $data['options']=$prodOption;
  795.         // dd($data);
  796.         return $this->json($data,200,[],['groups' => 'post:read']);
  797.     }
  798.     /**
  799.      * @Route("tousoption/{id}", name="productOption")
  800.      */
  801.     public function prodOption(ProductOptionRepository $optiorepo,Product $product,SessionInterface $session){
  802.         $optionProd=$optiorepo->findProduitOptionByProduit($product);
  803.         // dd($optionProd);
  804.         $data['options']=$optionProd;
  805.         if ($session->get('products')) {
  806.             $data['opt_pre']=$session->get('archive');
  807.         }
  808.         
  809.         return $this->json($data,200,[],['groups' => 'post:read']);
  810.     }
  811.     /**
  812.      * @Route("tous-options-product/{id}", name="option_product")
  813.      */
  814.     public function option_produit(ProductOptionRepository $optiorepo,Product $product,SessionInterface $session){
  815.         $optionProd=$optiorepo->findProduitOptionByProduit($product);
  816.         // dd($session->get('products'));
  817.         // if ($session->get('products')) {
  818.         //     $data['group_pre']=$session->get('archive');
  819.         // }
  820.         $optiongropeMVew =  $this->render('front/product/cart/optionHtml/row.html.twig', [
  821.             'optiongroups' => $optionProd
  822.         ]); 
  823.         return $this->json($optiongropeMVew->getContent());
  824.     }
  825.     /**
  826.      * @Route("tous-options-groups/{id}", name="options_groups")
  827.      */
  828.     public function ajout_options_groups(ProductOptionRepository $optiorepo,Product $product,SessionInterface $session){
  829.         $optionProd=$optiorepo->findProduitOptionByProduit($product);
  830.         // dd($product);
  831.         if ($session->get('products')) {
  832.             $pre_commande= [];
  833.             foreach ($session->get('products') as $cle => $productOption) {
  834.                 $pre_commande $productOption['options'];
  835.                 // foreach ($productOption['options'] as $idopt => $valueOptions) {
  836.                 //     //    $pre_commande[$idopt.'_'.$key]= $valueOption;
  837.                 //     foreach ($valueOptions as $key => $valueOption) {
  838.                 //         $pre_commande[$idopt][$key]=$valueOption['valeur'];
  839.                        
  840.                 //     }
  841.                 // }
  842.             }
  843.         }
  844.         // dd( $pre_commande,$optionProd);
  845.         $optiongropeMVewm =  $this->render('front/command/modifgroupbasket/modifGroup.html.twig', [
  846.             'optiongroups' => $optionProd,
  847.             'dansPanier'=>$pre_commande,
  848.             'produit'=>$product
  849.         ]); 
  850.         return $this->json($optiongropeMVewm->getContent());
  851.     }
  852. }