src/Flexy/FrontBundle/Themes/CoWorking/Controller/CartController.php line 41

  1. <?php
  2. namespace App\Flexy\FrontBundle\Themes\CoWorking\Controller;
  3. use App\Flexy\FrontBundle\Themes\CoWorking\Service\ShoppingCartService;
  4. use App\Flexy\ProductBundle\Repository\ProductRepository;
  5. use App\Flexy\ShopBundle\Entity\Product\ProductShop;
  6. use App\Flexy\ShopBundle\Repository\Customer\CustomerRepository;
  7. use App\Flexy\ShopBundle\Repository\Shipping\CityRegionRepository;
  8. use App\Flexy\ShopBundle\Repository\Shipping\ShippingMethodRepository;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. #[Route('/shop/cart')]
  14. class CartController extends AbstractController
  15. {
  16.     #[Route('/'name'cart')]
  17.     public function cart(ShippingMethodRepository $shippingMethodRepository,CustomerRepository $customerRepository,CityRegionRepository $cityRegionRepository): Response
  18.     {
  19.         $shippingMethods $shippingMethodRepository->findAll();
  20.         $cityRegions $cityRegionRepository->findAll();
  21.         $customer null;
  22.         if($this->getUser()){
  23.             $customer $customerRepository->findOneBy(["user"=>$this->getUser()]);
  24.         }
  25.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/cart/cart.html.twig',
  26.     [
  27.         "shippingMethods"=>$shippingMethods,
  28.         "customer"=>$customer,
  29.         "totalCart"=>160,
  30.         "cityRegions"=>$cityRegions
  31.     ]);
  32.     }
  33.     #[Route('/ajax/cart'name'ajax_cart')]
  34.     public function ajax_cart(ShoppingCartService $shoppingCartService,Request $request): Response
  35.     {
  36.         if(
  37.             $request->query->get("idProduct")){
  38.                 if($request->query->get("actionType") == "add"){
  39.                     //
  40.                     $shoppingCartService->addItem([
  41.                         'id' => $request->query->get("idProduct"),
  42.                         'name' => $request->query->get("name"),
  43.                         'price' => $request->query->get("price"),
  44.                         'image' => $request->query->get("image"),
  45.                         'quantity' => 1,
  46.                     ],false);
  47.                 }else{
  48.                     $shoppingCartService->removeItem($request->query->get("idProduct"));
  49.                 }
  50.             }
  51.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/cart/_ajaxCart.html.twig');
  52.     }
  53.     
  54.    #[Route('/ajax/cart/update'name'ajax_cart_update')]
  55.     public function ajax_car_update(ShoppingCartService $shoppingCartService,Request $request): Response
  56.     {
  57.         
  58.     
  59.         if ($request->query->get("actionType") == "update") {
  60.             $idProduct $request->query->get("idProduct");
  61.             $name $request->query->get("name");
  62.             $subcategory $request->query->get("cat");
  63.             
  64.     
  65.             $shoppingCartService->updateName($idProduct$name ,$subcategory);
  66.         }
  67.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/cart/_ajaxCart.html.twig');
  68.     }
  69.     #[Route('/wishlist'name'wishlist')]
  70.     public function wishlist(): Response
  71.     {
  72.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/cart/wishlist.html.twig');
  73.     }
  74.     #[Route('/compare'name'compare')]
  75.     public function compare(): Response
  76.     {
  77.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/cart/compare.html.twig');
  78.     }
  79.     #[Route('/show-devis'name'show_devis')]
  80.     public function show_devis(): Response
  81.     {
  82.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/cart/showDevis.html.twig');
  83.     }
  84. }