src/Controller/CartController.php line 59

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