Service "sylius.repository.product" not found: even though it exists in the app's container, the container inside "App\Controller\Shop\SubscribeBoxController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session", "templating" and "twig" services. Try using dependency injection instead.
I got this error when I am trying to use the sylius services on my controller:
public function index(Request $request)
{
$subscribed = new Subscribed();
$subscribeForm = $this->createForm(SubscribeType::class, $subscribed);
$subscribeForm->handleRequest($request);
if ($subscribeForm->isSubmitted() && $subscribeForm->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($subscribed);
$entityManager->flush();
return $this->redirectToRoute('subscribe_details');
}
/** @var ProductRepository $productRepository */
$productRepository = $this->get('sylius.repository.product');
$product = $productRepository->findAll();
return $this->render('@SyliusShop/Subscribe/plan.html.twig', [
'form' => $subscribeForm->createView(),
'product' => $product,
]);
}
So if anyone knows about this error let me know! :)