src/Controller/CartController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\DTO\AppDTO;
  4. use App\Model\Cart as ModelCart;
  5. use App\Model\Prod as ModelProd;
  6. use App\Service\Auth\Auth as Auth;
  7. use App\Service\Checkout\Checkout;
  8. use App\Repository\DeliveryRepository;
  9. use App\Model\Wishlist as ModelWishlist;
  10. use App\Repository\PageRepository;
  11. use App\Repository\ProdRepository;
  12. use Symfony\Contracts\Cache\CacheInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Security\Core\Security;
  15. use App\Service\Paginator as ServicePaginator;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. class CartController extends AbstractASController
  20. {
  21.     public function __construct(
  22.         private DeliveryRepository $Deliveries
  23.         private PageRepository $Pages
  24.         private ProdRepository $Prods
  25.         private ModelWishlist $Wishes
  26.         private CacheInterface $Cache
  27.         private AppDTO $app
  28.         private Auth $Auth
  29.         private ModelCart $Cart
  30.         private Checkout $Checkout
  31.         private ModelProd $ModelProd
  32.         private Security $security
  33.         private EntityManagerInterface $em)
  34.     {
  35.     }
  36.     #[Route(path'/cart'name'cart_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  37.     #[Route(path'/{_locale}/cart'name'cart'requirements: ['_locale' => '%app.langs%'])]
  38.     public function index(Request $request\App\Service\Cart\Cart $Cart): Response
  39.     {
  40.         $start = (int) $request->get('start'0);
  41.         $results $this->getParameter('cart.results');
  42.         
  43.         $wishlist $this->Wishes->getOnePage($start$results);
  44.         $deliveries $this->Deliveries->getByRegion($this->Checkout->getRegion_fias_id());
  45.         $freedelivery $this->Cart->isFreeDelivery((float) $this->app->sett->get('free_delivery_amount'));
  46.         $prod_limited_msg $this->app->labels->get('cart-edit-1').':\n';
  47.         foreach ($this->Cart->getProdsLimited() as $k => $v)
  48.         {
  49.             $prod $this->Prods->get($v);
  50.             $prod_limited_msg .= $prod->getArt().': '.$prod->getNum().' '.$this->app->labels->get('cart-edit-2').'\n';
  51.         }
  52.         $cart_items $this->Cart->getCart();
  53.         foreach ($cart_items as $k => $v) {
  54.             $cart_items[$k]['prod'] = $this->Prods->get($v['id']);
  55.         }
  56.         
  57.         $cart_new_prods $this->em->createQuery("SELECT p FROM App\Entity\Prod p WHERE p.visible = 1 AND p.new = 1 AND (p.num > 0 or p.num2 > 0 or p.num3 > 0)")
  58.             ->setMaxResults(6)
  59.             ->getResult();
  60.         
  61.         foreach ($cart_new_prods as $k => $prod) {
  62.             $cart_new_prods[$k]->prices $this->ModelProd->getPrices($prod);
  63.         }
  64.         $cart_pop_prods $this->em->createQuery("SELECT p FROM App\Entity\Prod p WHERE p.visible = 1 AND p.pop = 1 AND (p.num > 0 or p.num2 > 0 or p.num3 > 0)")
  65.             ->setMaxResults(6)
  66.             ->getResult();
  67.         
  68.         foreach ($cart_pop_prods as $k => $prod) {
  69.             $cart_pop_prods[$k]->prices $this->ModelProd->getPrices($prod);
  70.         }
  71.         return $this->render('cart/edit.html.twig', [
  72.             'cart' => $this->Cart,
  73.             'cart_items' => $cart_items,
  74.             'wishlist' => $wishlist,
  75.             'deliveries' => $deliveries,
  76.             'freedelivery' => $freedelivery,
  77.             'delivery_indicator_data' => $Cart->getDeliveryIndicatorData((float) $this->app->sett->get('free_delivery_amount')),
  78.             'prod_limited_msg' => $prod_limited_msg,
  79.             'checkout' => $this->Checkout,
  80.             'page' => $this->Pages->getByName('cart'),
  81.             'paginator' => new ServicePaginator('cart'count($wishlist), $results$start),
  82.             'cart_pop_prods' => $cart_pop_prods,
  83.             'cart_new_prods' => $cart_new_prods,
  84.         ]);
  85.     }
  86.     #[Route(path'/cart/show'name'cart_show_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  87.     #[Route(path'/{_locale}/cart/show'name'cart_show'requirements: ['_locale' => '%app.langs%'])]
  88.     public function show(Request $request): Response
  89.     {
  90.         $freedelivery $this->Cart->isFreeDelivery((float) $this->app->sett->get('free_delivery_amount'));
  91.         $cart_items $this->Cart->getCart();
  92.         foreach ($cart_items as $k => $v) {
  93.             $cart_items[$k]['prod'] = $this->Prods->get($v['id']);
  94.         }
  95.         
  96.         return $this->render('cart/show.html.twig', [
  97.             'order' => null,
  98.             'cart' => $this->Cart,
  99.             'cart_items' => $cart_items,
  100.             'freedelivery' => $freedelivery,
  101.             'checkout' => $this->Checkout,
  102.         ]);
  103.     }
  104.     #[Route(path'/cart/list'name'cart_list_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  105.     #[Route(path'/{_locale}/cart/list'name'cart_list'requirements: ['_locale' => '%app.langs%'])]
  106.     public function list(Request $request): Response
  107.     {
  108.         $cart_items $this->Cart->getCart();
  109.         foreach ($cart_items as $k => $v) {
  110.             $cart_items[$k]['prod'] = $this->Prods->get($v['id']);
  111.         }
  112.         return $this->render('cart/list.html.twig', [
  113.             'cart' => $this->Cart,
  114.             'cart_items' => $cart_items,
  115.         ]);
  116.     } 
  117.     #[Route(path'/cart/clear'name'cart_clear')]
  118.     public function clear(Request $request): Response
  119.     {
  120.         $this->Cart->deleteAll();
  121.         return new Response("ok");
  122.     } 
  123. }