im trying to make a shopping cart for a school project and i have the code here. but i get no results
i dont get an error but it just doesnt show anything. the form before this does work with amount but as soon as i want to actually see my shopping cart it wont show
#[Route(‘/shoppingcart/{id}’, name: ‘shoppingcart’)]
public function detail(Request $request, EntityManagerInterface $em, int $id): Response
{
$product = $em->getRepository(Product::class)->find($id);
$form = $this->createFormBuilder()
->add(‘amount’, IntegerType::class, [
‘required’=>true,
‘data’=>1,
‘label’=>’amount’
])
->add(‘add’, SubmitType::class)
->getForm();
$session = $request->getSession();
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid() ) {
if(!$session->get('order')) {
$session->set('order',[]);
}
$amount=$form->get('amount')->getData();
$order=$session->get('order');
$order[]=[$id,$amount];
$session->set('order',$order);
$this->addFlash('success','product added!');
return $this->redirectToRoute('student_category');
}
return $this->render('student/detail.html.twig', [
'product' => $product, 'form' => $form
]);
}
Paul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.