src/Controller/CartController.php line 58

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\Delivery as ModelDelivery;
  10. use App\Model\Wishlist as ModelWishlist;
  11. use Symfony\Contracts\Cache\CacheInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Core\Security;
  14. use App\Service\Paginator as ServicePaginator;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\HttpFoundation\RequestStack;
  18. use App\RepositoryInterface\PageRepositoryInterface;
  19. use App\RepositoryInterface\ProdRepositoryInterface;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. class CartController extends AbstractASController
  22. {
  23.     protected CacheInterface $Cache;
  24.     protected AppDTO $app;
  25.     // Models
  26.     protected DeliveryRepository $Deliveries;
  27.     protected ProdRepositoryInterface $Prods;
  28.     protected PageRepositoryInterface $Pages;
  29.     protected ModelWishlist $Wishes;
  30.     protected ModelCart $Cart;
  31.     protected Auth $Auth;
  32.     protected Checkout $Checkout;
  33.     protected ModelProd $ModelProd;
  34.     public function __construct(DeliveryRepository $DeliveriesPageRepositoryInterface $PagesProdRepositoryInterface $ProdsModelWishlist $WishesCacheInterface $CacheAppDTO $appAuth $AuthModelCart $CartCheckout $CheckoutModelProd $ModelProdSecurity $securityRequestStack $requestStack)
  35.     {
  36.         $this->requestStack $requestStack;
  37.         $this->Cache $Cache;
  38.         $this->app $app;
  39.         $this->Auth $Auth;
  40.         $this->Auth->setUser($security->getUser());
  41.         $this->Cart $Cart;
  42.         $this->Checkout $Checkout;
  43.         
  44.         $this->Pages $Pages;
  45.         $this->Prods $Prods;
  46.         $this->Wishes $Wishes;
  47.         $this->Deliveries $Deliveries;
  48.         $this->ModelProd $ModelProd;
  49.     }
  50.     #[Route(path'/cart'name'cart_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  51.     #[Route(path'/{_locale}/cart'name'cart'requirements: ['_locale' => '%app.langs%'])]
  52.     public function index(Request $request): Response
  53.     {
  54.         $start = (int) $request->get('start'0);
  55.         $results $this->getParameter('cart.results');
  56.         
  57.         $wishlist $this->Wishes->getOnePage($start$results);
  58.         $deliveries $this->Deliveries->getByRegion($this->Checkout->getRegion_fias_id());
  59.         $freedelivery $this->Cart->isFreeDelivery((float) $this->app->sett->get('free_delivery_amount'));
  60.         $prod_limited_msg $this->app->labels->get('cart-edit-1').':\n';
  61.         foreach ($this->Cart->getProdsLimited() as $k => $v)
  62.         {
  63.             $prod $this->Prods->get($v);
  64.             $prod_limited_msg .= $prod->getArt().': '.$prod->getNum().' '.$this->app->labels->get('cart-edit-2').'\n';
  65.         }
  66.         $cart_items $this->Cart->getCart();
  67.         foreach ($cart_items as $k => $v) {
  68.             $cart_items[$k]['prod'] = $this->Prods->get($v['id']);
  69.         }
  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.             'prod_limited_msg' => $prod_limited_msg,
  78.             'checkout' => $this->Checkout,
  79.             'page' => $this->Pages->getByName('cart'),
  80.             'paginator' => new ServicePaginator('cart'count($wishlist), $results$start),
  81.         ]);
  82.     }
  83.     #[Route(path'/cart/show'name'cart_show_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  84.     #[Route(path'/{_locale}/cart/show'name'cart_show'requirements: ['_locale' => '%app.langs%'])]
  85.     public function show(Request $request): Response
  86.     {
  87.         $freedelivery $this->Cart->isFreeDelivery((float) $this->app->sett->get('free_delivery_amount'));
  88.         $cart_items $this->Cart->getCart();
  89.         foreach ($cart_items as $k => $v) {
  90.             $cart_items[$k]['prod'] = $this->Prods->get($v['id']);
  91.         }
  92.         
  93.         return $this->render('cart/show.html.twig', [
  94.             'order' => null,
  95.             'cart' => $this->Cart,
  96.             'cart_items' => $cart_items,
  97.             'freedelivery' => $freedelivery,
  98.             'checkout' => $this->Checkout,
  99.         ]);
  100.     }
  101.     #[Route(path'/cart/list'name'cart_list_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  102.     #[Route(path'/{_locale}/cart/list'name'cart_list'requirements: ['_locale' => '%app.langs%'])]
  103.     public function list(Request $request): Response
  104.     {
  105.         $cart_items $this->Cart->getCart();
  106.         foreach ($cart_items as $k => $v) {
  107.             $cart_items[$k]['prod'] = $this->Prods->get($v['id']);
  108.         }
  109.         return $this->render('cart/list.html.twig', [
  110.             'cart' => $this->Cart,
  111.             'cart_items' => $cart_items,
  112.         ]);
  113.     } 
  114.     #[Route(path'/cart/clear'name'cart_clear')]
  115.     public function clear(Request $request): Response
  116.     {
  117.         $this->Cart->deleteAll();
  118.         return new Response("ok");
  119.     } 
  120. }