public function add(Produit $produit, $qty = 1) { //Soit j'ai un tableau vide soit un tableau plein d'id produit if ($this->session->get('panier')) { $allProducts = $this->session->get('panier'); } else { $allProducts = []; } //TRaitement sur la quantité if (array_key_exists($produit->getId(), $allProducts)) { // $allProducts[$product->getId()]; représente la quantité du produit $allProducts[$produit->getId()] = $allProducts[$produit->getId()] + $qty; //$qty = $allProducts[$product->getId()] + $qty } else { $allProducts[$produit->getId()] = $qty; } $this->session->set('panier', $allProducts); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $faker = \Faker\Factory::create('fr_FR'); for ($i = 0; $i < 10; $i++) { //VOir la doc en tapant faker.php lien github (https://github.com/fzaninotto/Faker) $produit = new Produit(); $produit->setTitle($faker->text(10)); $produit->setPrice($faker->randomFloat(2, 0, 500)); $produit->setQuantity($faker->numberBetween(0, 1)); $produit->setDescription($faker->text(10)); $produit->setDateCreated($faker->dateTimeThisYear); $categorie = $this->getReference("categ_" . $i); $produit->setCategorie($categorie); $produit->setMarque($manager->getRepository('WaBackBundle:Marque')->find(1)); $manager->persist($produit); $manager->flush(); } }