src/Controller/CartController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Zayavka;
  4. use App\Entity\ZayavkaMono;
  5. use App\Service\OtherFunction;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. Class CartController extends AbstractController
  12. {
  13.     private $requestStack;
  14.     private $em;
  15.     public function __construct(RequestStack $requestStackEntityManagerInterface $em)
  16.     {
  17.         $this->requestStack $requestStack;
  18.         $this->em $em;
  19.     }
  20.     public function cartBlock(){
  21.         $zayavkas = [];
  22.         if(strpos($this->requestStack->getParentRequest()->getPathInfo(), '/zayavka') === FALSE && strpos($this->requestStack->getParentRequest()->getPathInfo(), '/ajax') === FALSE) {
  23.             $clientId '';
  24.             foreach(OtherFunction::getClientId() as $item){
  25.                 if($item != 'not_identified') {
  26.                     $clientId $item;
  27.                     break;
  28.                 }
  29.             }
  30.             if(!empty($clientId)){
  31.                 $zayavkas['zayavka'] = $this->em->getRepository(Zayavka::class)->getZayavkaCart($clientId);
  32.                 $zayavkas['mono'] = $this->em->getRepository(ZayavkaMono::class)->getZayavkaCart($clientId);
  33.             }
  34.             if(!empty($zayavkas)){
  35.                 foreach ($zayavkas as $zayavka) {
  36.                     foreach ($zayavka as $item) {
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.         return $this->render('cart/block.html.twig', [
  42.             'zayavkas' => $zayavkas,
  43.             'direction' => $this->getParameter('direction'),
  44.         ]);
  45.     }
  46.     /**
  47.      * @Route(
  48.      *     "/ajax/cart/delete/{type}/{id}",
  49.      *     priority=11,
  50.      *     name="ajax_cart_delete",
  51.      *     methods={"GET","POST"},
  52.      *     requirements={
  53.      *      "type":"zayavka|mono",
  54.      *      "id":"\d+",
  55.      *     })
  56.      */
  57.     public function delete($type$id): Response
  58.     {
  59.         switch ($type){
  60.             case 'zayavka':
  61.                 $entity $this->em->getRepository(Zayavka::class)->findOneBy(['id' => $id]);
  62.                 break;
  63.             case 'mono':
  64.                 $entity $this->em->getRepository(ZayavkaMono::class)->findOneBy(['id' => $id]);
  65.                 break;
  66.         }
  67.         if(!empty($entity) && $entity->getCartDelete() == 0) {
  68.             $entity->setCartDelete(1);
  69.             $this->em->flush();
  70.         }
  71.         return $this->json('true');
  72.     }
  73. }