Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
proc
/
212
/
root
/
proc
/
self
/
root
/
proc
/
212
/
task
/
212
/
root
/
proc
/
70528
/
cwd
/
src
/
Service
/
//proc/212/root/proc/self/root/proc/212/task/212/root/proc/70528/cwd/src/Service/CartService.php
<?php namespace App\Service; use App\Entity\Cart; use App\Entity\User; use App\Repository\CartRepository; use App\Security\UserAuthenticator; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class CartService { /** * @var User */ private $user; /** * @var ManagerRegistry */ private $doctrine; /** * @var CartRepository */ private $cartRepository; /** * @var Cart */ private $cart; /** * @var Session */ private $session; /** * @var EntityManagerInterface */ private $em; public function __construct(?User $user, ManagerRegistry $doctrine, Session $session) { $this->user = $user; $this->doctrine = $doctrine; $this->em = $doctrine->getManager(); $this->cartRepository = new CartRepository($this->doctrine); $this->session = $session; } /** * @return Cart $cart */ public function getCart() { if ($this->user != null) { $this->cart = $this->cartRepository->findBy(["user" => $this->user->getId(), "payementStatus" => "to_be_started"]); if ($this->cart == []) { $this->cart = new Cart(); $this->cart->setUser($this->user); $this->em->persist($this->cart); $this->em->flush(); } else { $this->cart = $this->cart[0]; } return $this->cart; } else { $this->cart = $this->cartRepository->findBy(["sessionToken" => $this->session->getId(), "payementStatus" => "to_be_started"]); if ($this->cart == []) { $this->cart = new Cart(); $this->cart->setSessionToken($this->session->getId()); $this->em->persist($this->cart); $this->em->flush(); } else { $this->cart = $this->cart[0]; } return $this->cart; } } public function getUserCart(){ return $this->cartRepository->findOneBy(["user" => $this->user->getId(), "payementStatus" => "to_be_started", "step" => "cart"], ["id" => "DESC"]); } public function getSessionCart(){ return $this->cartRepository->findOneBy(["sessionToken" => $this->session->getId(), "payementStatus" => "to_be_started", "step" => "cart"], ["id" => "DESC"]); } /** * @return Cart $cart */ public function getExistingCart() { if ($this->user != null) { return $this->cart = $this->cartRepository->findActiveUserCart($this->user->getId())[0]; } else { return $this->cart = $this->cartRepository->findBy(["sessionToken" => $this->session->getId(), "payementStatus" => "to_be_started"])[0]; } } public function getInitiatedCart() { if ($this->user != null) { $this->cart = $this->cartRepository->findBy(["user" => $this->user->getId(), "payementStatus" => "initiated"]); if(isset($this->cart[0])) $this->cart = $this->cart[0]; else return false; return $this->cart; } else { $this->cart = $this->cartRepository->findBy(["sessionToken" => $this->session->getId(), "payementStatus" => "initiated"]); if(isset($this->cart[0])) $this->cart = $this->cart[0]; else return false; return $this->cart; } } public function getDeliveryCart(){ if($this->user){ $this->cart = $this->cartRepository->findOneBy(["user" => $this->user->getId(), "step" => "delivery"], ["id" => "DESC"]); if(!$this->cart || count($this->cart->getItems()) < 1) { $this->cart = $this->cartRepository->findOneBy(["sessionToken" => $this->session->getId(), "step" => "delivery"], ["id" => "DESC"]); } } else { $this->cart = $this->cartRepository->findOneBy(["sessionToken" => $this->session->getId(), "step" => "delivery"], ["id" => "DESC"]); } return $this->cart; } public function getIdentifyCart(){ if($this->user){ $this->cart = $this->cartRepository->findOneBy(["user" => $this->user->getId(), "step" => "identify"], ["id" => "DESC"]); if(!$this->cart || count($this->cart->getItems()) < 1) { $this->cart = $this->cartRepository->findOneBy(["sessionToken" => $this->session->getId(), "step" => "identify"], ["id" => "DESC"]); } } else { $this->cart = $this->cartRepository->findOneBy(["sessionToken" => $this->session->getId(), "step" => "identify"], ["id" => "DESC"]); } return $this->cart; } public function registerItems($items) { foreach ($items as $item) { $this->cart->addItem($item); } $this->em->persist($this->cart); $this->em->flush(); } }