Estoy trabajando en crear un carrito de compras para un proyecto que estoy realizando y estoy utilizando Symfony6, al momento de entrar al url del carrito para probar su funcionamiento me da este error, he buscado en internet y probado algunas de las soluciones pero no me han servido.
Cannot autowire argument $cartManager of "App\Controller\Frontend\CartController::index()": it references class "App\Manager\CartManager" but no such service exists.
Este es el código del controlador del Carrito:
namespace App\Controller\Frontend;
use App\Form\CartType;
use App\Manager\CartManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class CartController
* @package App\Controller
*/
class CartController extends AbstractController
{
/**
* @Route("/cart", name="cart")
*/
public function index(CartManager $cartManager, Request $request): Response
{
$cart = $cartManager->getCurrentCart();
$form = $this->createForm(CartType::class, $cart);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$cart->setUpdateAt(new \DateTime());
$cartManager->save($cart);
return $this->redirectToRoute('cart');
}
return $this->render('cart/index.html.twig', [
'cart' => $cart,
'form' => $form->createView()
]);
}
}
Este es el código del Manager del Carrito
namespace App\Manager;
use App\Entity\Order;
use App\Factory\OrderFactory;
use App\Storage\CartSessionStorage;
use Doctrine\ORM\EntityManagerInterface;
class CartManager
{
/**
* @var CartSessionStorage
*/
private $cartSessionStorage;
/**
* @var OrderFactory
*/
private $cartFactory;
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* CartManager constructor.
*/
public function __construct(
CartSessionStorage $cartStorage,
OrderFactory $orderFactory,
EntityManagerInterface $entityManager
) {
$this->cartSessionStorage = $cartStorage;
$this->cartFactory = $orderFactory;
$this->entityManager = $entityManager;
}
/**
* Gets the current cart.
*/
public function getCurrentCart(): Order
{
$cart = $this->cartSessionStorage->getCart();
if (!$cart) {
$cart = $this->cartFactory->create();
}
return $cart;
}
/**
* Persists the cart in database and session.
*/
public function save(Order $cart): void
{
// Persist in database
$this->entityManager->persist($cart);
$this->entityManager->flush();
// Persist in session
$this->cartSessionStorage->setCart($cart);
}
}
No se que me esta faltando la verdad, he revisado pero no logro entender el porque del error. agradecería su ayuda.