Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addProdctAction(Request $request)
- {
- $user = $this->container->get('security.token_storage')->getToken()->getUser();
- $produit = new Produit();
- $form = $this->createFormBuilder($produit)
- ->add('nom', TextType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('description', TextareaType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('quantity', NumberType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('prix', NumberType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('imageId', FileType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('category', EntityType::class, [
- // looks for choices from this entity
- 'class' => Category::class,
- 'choice_label' => 'category',])
- ->getForm();
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- /** @var UploadedFile $file */
- $file = $produit->getImageId();
- $fileName = md5(uniqid()) . '.' . $file->guessExtension();
- // Move the file to the directory where brochures are stored
- $file->move(
- $this->getParameter('images_shop'),
- $fileName
- );
- $produit->setImageId($fileName);
- $nom = $form['nom']->getData();
- $description = $form['description']->getData();
- $stock = $form['quantity']->getData();
- $prix = $form['prix']->getData();
- $cat = $form['category']->getData();
- $now = new\DateTime('now');
- $produit->setNom($nom);
- $produit->setDescription($description);
- $produit->setQuantity($stock);
- $produit->setPrix($prix);
- $produit->setUtilisateur($user);
- $produit->setCategory($cat);
- $produit->setStars(0);
- $produit->setDate($now);
- $sn = $this->getDoctrine()->getManager();
- $sn->persist($produit);
- $sn->flush();
- $this->addFlash(
- 'notice',
- 'todo added'
- );
- }
- $panierlist = $this->getDoctrine()->getRepository('ShopBundle:Panier')->findByUser($user);
- $cat = $this->getDoctrine()->getRepository('ShopBundle:Category')->findAll();
- $count = count($panierlist);
- $total = 0;
- foreach ($panierlist as $prix) {
- $total = $total + $prix->getPrix();
- }
- return $this->render('AdminBundle:Default:addprod.html.twig', array(
- 'cat' => $cat,
- 'form' => $form->createView(),'nbrp' => $count, 'panier' => $panierlist, 'total' => $total
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement