Example #1
0
 public function load(ObjectManager $manager)
 {
     $yaml = new Parser();
     $symbonfy_base_dir = $this->container->getParameter('kernel.root_dir');
     $data_dir = $symbonfy_base_dir . '/Resources/data/';
     try {
         $value = Yaml::parse(file_get_contents($data_dir . 'tasks.yml'));
     } catch (ParseException $e) {
         printf("Unable to parse the YAML string: %s", $e->getMessage());
     }
     /*
     tasks:
         0: { id: 1, name: ''}
         1: { id: 1, name: ''}
     taskauthor:
         0: { id: 1, name: "Brad Taylor", isActive: true }
         1: { id: 2, name: "William O'Neil", isActive: false }
     */
     $products = array(0 => array('name' => 'Product0', 'price' => 0, 'description' => 'Description Product 0'), 1 => array('name' => 'Product1', 'price' => 1, 'description' => 'Description Product 1'), 2 => array('name' => 'Product2', 'price' => 2, 'description' => 'Description Product 2'), 3 => array('name' => 'Product3', 'price' => 3, 'description' => 'Description Product 3'), 4 => array('name' => 'Product4', 'price' => 4, 'description' => 'Description Product 4'));
     foreach ($products as $product_id => $data) {
         $product = new Product();
         $product->setName($data['name']);
         $product->setDescription($data['description']);
         $product->setPrice($data['price']);
         $manager->persist($product);
         $this->addReference($product_id, $product);
     }
     $manager->flush();
 }
Example #2
0
 /**
  * @Route("/import", name="massimport")
  */
 public function massImportAction(Request $request)
 {
     $form = $this->createFormBuilder(null, array('action' => $this->generateUrl('massimport')))->add('file', 'file')->getForm();
     if ($request->getMethod() === 'POST') {
         $request = $this->getRequest();
         $form->bind($request);
         // It always gets overwritten
         $form['file']->getData()->move('/tmp', 'example.tmp');
         $lines = explode(PHP_EOL, file_get_contents('/tmp/example.tmp'));
         // since we don't care about first line or last line
         array_shift($lines);
         array_pop($lines);
         foreach ($lines as $line) {
             $data = explode("\t", $line);
             $product = new Product();
             $product->setTitle($data[0]);
             $product->setDescription($this->sanitize($data[1]));
             $product->setPrice($data[2]);
             // I'm not dealing with timezones as I'd need another field for it to work with doctrine and I didn't notice until the end of the exam
             $product->setInitDate(new \DateTime($data[3]));
             $product->setExpiryDate(new \DateTime($data[4]));
             $product->setMerchantAddress($data[5]);
             $product->setMerchantName($this->sanitize($data[6]));
             // I'm currently just enabling all of them
             $product->setStatus(1);
             $this->saveProduct($product);
         }
     }
     return $this->render('default/success.html.twig');
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $product1 = new Product();
     $product1->setName('Calça Jeans');
     $product1->setDescription('Calça Jeans masculina confeccionada em algodão, poliéster e
     elastano, que proporcionam toque macio sobre o corpo. Fechamento por botão e zíper.');
     $product1->setImage('calca_jeans.jpg');
     $product1->setPrice(150.49);
     $categories1 = new ArrayCollection();
     $categories1->add($this->getReference('category1'));
     $categories1->add($this->getReference('category2'));
     $product1->setCategories($categories1);
     $product2 = new Product();
     $product2->setName('Shampoo');
     $product2->setDescription('Shampoo anti-caspa para cabelos secos.');
     $product2->setImage('shampoo.jpg');
     $product2->setPrice(9.99);
     $categories2 = new ArrayCollection();
     $categories2->add($this->getReference('category3'));
     $product2->setCategories($categories2);
     $manager->persist($product1);
     $manager->persist($product2);
     $manager->flush();
     $this->addReference('product1', $product1);
     $this->addReference('product2', $product2);
 }
Example #4
0
 /**
  * {@inheritDoc}
  * @see \Doctrine\Common\DataFixtures\FixtureInterface::load()
  */
 public function load(ObjectManager $manager)
 {
     // Recogemos la ubicación del proyecto symfony
     $symfony_app_base_dir = $this->container->getParameter('kernel.root_dir');
     // Añadimos mediante fichero .csv nuevos registros a la base de datos.
     // abrimos el fichero y lo recorremos en modo lectura
     $row = 0;
     $fd = fopen($symfony_app_base_dir . '/Resources/data/products.csv', "r");
     if ($fd) {
         while (($data = fgetcsv($fd, 1000, ",")) !== false) {
             $row++;
             if ($row == 1) {
                 continue;
             }
             // Creamos el objeto
             $product = new Product();
             // Recogemos el objeto del fichero
             $product->setName($data[0]);
             $product->setDescription($data[1]);
             $product->setCategory($this->getReference($data[2]));
             $product->setPrice($data[3]);
             $manager->persist($product);
             // alamacenamos en la base de datos.
             $manager->flush();
             $this->addReference($product->getName(), $product);
         }
         fclose($fd);
         // se cierra el fichero
     }
 }
 public function load(ObjectManager $manager)
 {
     $product = new Product();
     $product->setName('Samsung Galaxy S6');
     $product->setPrice('600');
     $product->setDescription('The description of the product goes here');
     $manager->persist($product);
     $manager->flush();
 }
 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $product = new Product();
     $product->setName('iphone');
     $product->setPrice('300.00');
     $product->setDescription('Used, like new');
     $em = $this->getDoctrine()->getManager();
     $em->persist($product);
     $em->flush();
     return $this->render('default/index.html.twig', ['base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'), 'product' => $product]);
 }
 /**
  * @Route("/product")
  */
 public function createAction()
 {
     $product = new Product();
     $product->setName('A Foo Bar');
     $product->setPrice('19.99');
     $product->setDescription('Lorem ipsum dolor');
     $em = $this->getDoctrine()->getManager();
     $em->persist($product);
     $em->flush();
     return new Response('Created product id ' . $product->getId());
 }
Example #8
0
 /**
  * @Route("/product/create")
  * @Template()
  */
 public function createAction()
 {
     $product = new Product();
     $product->setName("Product 1");
     $product->setDescription("Description product 1");
     $product->setPrice(100000);
     $product->setComparePrice(200000);
     $em = $this->getDoctrine()->getManager();
     $em->persist($product);
     $em->flush();
     return array();
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     for ($x = 0; $x < 50; $x++) {
         $feature1 = new Feature();
         $feature1->setName("Name 1");
         $feature2 = new Feature();
         $feature2->setName("Name 2");
         $product = new Product();
         $product->setDescription("Description " . $x)->setName("Name " . $x)->setPrice($x)->setFeatures(array($feature1, $feature2));
         $manager->persist($product);
     }
     $manager->flush();
 }
Example #10
0
 /**
  * @Route("/lucky/product")
  */
 public function productAction()
 {
     for ($i = 0; $i < 5; $i++) {
         $product = new Product();
         $product->setName('A Foo Bar');
         $product->setPrice(mt_rand(1, 53));
         $product->setDescription('Lorem ipsum dolor');
         $em = $this->getDoctrine()->getManager();
         $em->persist($product);
     }
     $em->flush();
     return new Response('Created product id ' . $product->getId());
 }
Example #11
0
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 0; $i < 1000; $i++) {
         $product = new Product();
         $product->setName(ucfirst($faker->word));
         $product->setDescription(ucfirst($faker->text));
         $product->setPrice(ucfirst($faker->randomFloat(2, 10, 9999)));
         $product->setAmount(ucfirst($faker->numberBetween(0, 20)));
         $product->setCategory($this->getReference('category-' . $faker->numberBetween(1, 100)));
         $manager->persist($product);
     }
     $manager->flush();
 }
Example #12
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $supplier = new Supplier('Kafo');
     $manager->persist($supplier);
     $products = [['name' => 'Barazylia Santos (250g)', 'price' => 19.0], ['name' => 'Ethiopia (250g)', 'price' => 28.0, 'description' => 'Kawa Jednorodna'], ['name' => 'Rwanda (250g)', 'price' => 28.0, 'description' => 'Kawa Jednorodna']];
     foreach ($products as $product) {
         $entity = new Product($product['name'], $product['price'], $supplier);
         if (isset($product['description'])) {
             $entity->setDescription($product['description']);
         }
         $manager->persist($entity);
     }
     $manager->flush();
 }
 public function load(ObjectManager $manager)
 {
     foreach (range(1, 100) as $i) {
         $product = new Product();
         $product->setEnabled(rand(1, 1000) % 10 < 7);
         $product->setName($this->getRandomName());
         $product->setPrice($this->getRandomPrice());
         $product->setTags($this->getRandomTags());
         $product->setEan($this->getRandomEan());
         $product->setDescription($this->getRandomDescription());
         $this->addReference('product-' . $i, $product);
         $manager->persist($product);
     }
     $manager->flush();
 }
Example #14
0
 public function createAction()
 {
     $category = new Category();
     $category->setName('Good stuff');
     $product = new Product();
     $product->setName('Brown stuff');
     $product->setPrice('9.99');
     $product->setDescription('Coffee from Kenya');
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id ' . $product->getId() . ' and category id ' . $category->getId());
 }
Example #15
0
 public function indexAction()
 {
     $categories = new Categories();
     $categories->setName('Computer Peripherals');
     $product = new Product();
     $product->setName('Keyboard');
     $product->setPrice(19.99);
     $product->setDescription('Ergonomic and stylish!');
     $product->setCategory($categories);
     $em = $this->getDoctrine()->getManager();
     $em->persist($categories);
     $em->persist($product);
     $em->flush();
     return new Response('<html><head></head><body>Test</body></html>');
 }
Example #16
0
 /**
  * Relation controller.
  *
  * @Route("/relation")
  */
 public function relationAction()
 {
     $category = new Category();
     $category->setName('Prodotti principali');
     $product = new Product();
     $product->setName('Test');
     $product->setPrice(19.99);
     $product->setDescription('prodotto di test');
     // correlare questo prodotto alla categoria
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Creati prodotto con id: ' . $product->getId() . ' e categoria con id: ' . $category->getId());
 }
Example #17
0
 public function newAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $product = new Product();
     $product->setName('product1');
     $product->setPrice(33.3);
     $product->setDescription('Product description');
     $form = $this->createForm(ProductType::class, $product);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->persist($product);
         $em->flush();
         return $form->get('saveAndAdd')->isClicked() ? $this->redirectToRoute('product_new', [], 301) : $this->redirectToRoute('product_list', [], 301);
     }
     return $this->render('AppBundle:Product:new.html.twig', array('form' => $form->createView()));
 }
Example #18
0
 /**
  * @Route("/productcategory", name="Produkt mit Kategorie einpflegen")
  */
 public function createProductAction()
 {
     $category = new Category();
     $category->setName('Main Products');
     $product = new Product();
     $product->setName('Foo');
     $product->setPrice(19.99);
     $product->setDescription('Lorem ipsum dolor');
     // relate this product to the category
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId());
 }
Example #19
0
 /**
  * @Route("/product/create", name="productCreate")
  */
 public function createAction()
 {
     $product = new Product();
     //$product->setName('Televison');
     $product->setPrice('160');
     $product->setDescription('Samsung 50');
     $validator = $this->get('validator');
     $errors = $validator->validate($product);
     if (count($errors) > 0) {
         return $this->render('product/validation.html.twig', array('errors' => $errors));
     } else {
         $em = $this->getDoctrine()->getManager();
         $em->persist($product);
         $em->flush();
         return new Response('Created product id ' . $product->getId());
     }
 }
 private function generateProduct()
 {
     $product = new Product();
     $name = array();
     for ($i = 0; $i < rand(3, 6); $i++) {
         array_push($name, $this->genstr(rand(3, 8)));
     }
     $product->setName(implode(' ', $name));
     $product->setPrice(rand(32, 999) / 10);
     $product->setPriceDiscounted($product->getPrice() * 0.9);
     $product->setSoldNo(rand(0, 500));
     $product->setUpdateAt($this->rand_date('2013-01-01', '2015-10-06'));
     $product->setBrand($this->genstr(rand(3, 8)));
     $product->setInventory(rand(0, 200));
     $product->setDescription($this->genstr(rand(3, 8)) . ' ' . $this->genstr(rand(3, 8)) . ' ' . $this->genstr(rand(3, 8)));
     $product->setProductKey(substr(uniqid(), 0, 10));
     $product->setWeight(rand(0, 1200));
     $product->setClick(rand(0, 1000));
     $product->setImageLink(uniqid());
     return $product;
 }
 /**	 
  * @Route("{_locale}/product/create/{name}/{price}", name="product_create",
  * requirements={
  * "name": "[A-Za-z0-9\s-]+",
  * "price" : "\d{2}(\.\d{2})?"
  * })
  */
 public function createParamAction($name, $price)
 {
     $em = $this->getDoctrine()->getManager();
     $categories = $this->getDoctrine()->getRepository('AppBundle:Category')->findAll();
     if (!$categories) {
         $category = new Category();
         $category->setName('Default Category');
         $em->persist($category);
     } else {
         $category = $categories[rand(0, count($categories) - 1)];
     }
     $product = new Product();
     $product->setName($name);
     $product->setPrice($price);
     $product->setDescription(sprintf('Description de %s', $name));
     // relacionamos con categoría
     $product->setCategory($category);
     $em->persist($product);
     $em->flush();
     return $this->render('dws/message.html.twig', array('message' => sprintf("Producto %s(%d) creado!!", $product->getName(), $product->getId())));
 }
Example #22
0
 public function load(ObjectManager $manager)
 {
     $symbonfy_base_dir = $this->container->getParameter('kernel.root_dir');
     $data_dir = $symbonfy_base_dir . '/Resources/data/';
     $row = 0;
     if (($fd = fopen($data_dir . 'products.csv', "r")) !== FALSE) {
         while (($data = fgetcsv($fd, 1000, ",")) !== FALSE) {
             $row++;
             if ($row == 1) {
                 continue;
             }
             //skip header
             $product = new Product();
             $product->setName($data[0]);
             $product->setDescription($data[1]);
             $product->setCategory($this->getReference($data[2]));
             $product->setPrice($data[3]);
             $manager->persist($product);
         }
         fclose($fd);
     }
     $manager->flush();
 }
Example #23
0
 /**
  * @Route("/product/new", name="new_product")
  */
 public function createAction()
 {
     $validator = $this->get('validator');
     $category = new Category();
     $category->setName('Main Products');
     $errors = $validator->validate($category);
     if (count($errors) > 0) {
         return $this->render('product/validation.html.twig', array('errors' => $errors));
     }
     $product = new Product();
     $product->setName('');
     $product->setPrice('19.99');
     $product->setDescription('Lorem ipsum dolor');
     $product->setCategory($category);
     $errors = $validator->validate($product);
     if (count($errors) > 0) {
         return $this->render('product/validation.html.twig', array('errors' => $errors));
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId());
 }
Example #24
0
 /**
  * @Given existen los siguientes productos:
  */
 public function createProducts(TableNode $tableNode)
 {
     $em = $this->getEntityManager();
     foreach ($tableNode->getHash() as $productHash) {
         $product = new Product();
         $product->setCode($productHash['codigo']);
         $product->setName($productHash['descripcion']);
         $product->setDescription($productHash['descripcion completa']);
         $product->setNumberConsumerUnit($productHash['numero UC']);
         $product->setChangeHistory($productHash['historial']);
         //We obtain the corresponding identifier to the trademark name
         $em = $this->getEntityManager();
         $trademark = $em->getRepository('AppBundle:Trademark')->findOneBy(array('name' => $productHash['marca']));
         $product->setTrademark($trademark);
         //We obtain the corresponding identifier to the barcode, both the CU and SU
         $em = $this->getEntityManager();
         $barcodeCU = $em->getRepository('AppBundle:Barcode')->findOneBy(array('code' => $productHash['codigo UC']));
         $product->setBarcodeCU($barcodeCU);
         $barcodeSU = $em->getRepository('AppBundle:Barcode')->findOneBy(array('code' => $productHash['codigo UV']));
         $product->setBarcodeSU($barcodeSU);
         $em->persist($product);
     }
     $em->flush();
 }
Example #25
0
 public function createParamAction($name, $price)
 {
     // Se crea el objeto con los parámetros que le pasamos.
     $product = new Product();
     $product->setName($name);
     $product->setPrice($price);
     $product->setDescription($name);
     // Se almacena en la base de datos.
     $em = $this->getDoctrine()->getManager();
     $em->persist($product);
     $em->flush();
     return new Response('Objeto ' . $product->getName() . ' con id ' . $product->getId() . ' ' . ' creado correctamente.');
 }
 /**
  * @Route("/product/createProduct", name="createProduct")
  */
 public function createProductAction()
 {
     $category = new Category();
     $category->setName('Main Products');
     $product = new Product();
     $product->setName('Segon');
     $product->setPrice(20);
     $product->setDescription('descripció');
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId());
 }
 /**
  * {@inheritDoc}
  */
 public function setDescription($description)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setDescription', array($description));
     return parent::setDescription($description);
 }
Example #28
0
 /**
  * @Route("/commerce/import", name="import_products" )
  */
 public function importAction(Request $request)
 {
     $prds = array();
     for ($i = 1; $i < 21; $i++) {
         $product = new Product();
         $product->setName("product " . $i);
         $product->setPrice(1 * rand(2, 99));
         $product->setDescription("rezareareerzarezraear");
         $em = $this->getDoctrine()->getManager();
         $em->persist($product);
         $prds[] = $product;
         $em->flush();
     }
     for ($i = 1; $i <= 5; $i++) {
         $categ = new Category();
         $categ->setName("categ " . $i);
         $c1 = rand(1, 20);
         $c2 = rand(1, 20);
         $categ->addProduct($prds[$c1]);
         if ($c1 != $c2) {
             $categ->addProduct($prds[$c2]);
         }
         $em = $this->getDoctrine()->getManager();
         $em->persist($categ);
         $em->flush();
     }
     return "import success";
 }
Example #29
0
 /**
  * @Given /^supplier "([^"]*)" exists with product:$/
  */
 public function supplierExistsWithProduct($name, TableNode $table)
 {
     $data = $table->getRowsHash();
     $supplier = $this->supplierExists($name);
     $product = new Product($data['Name'], (double) $data['Price'], $supplier);
     if (isset($data['Description'])) {
         $product->setDescription($data['Description']);
     }
     var_dump($product->getPrice());
     $this->getEntityManager()->persist($product);
     $this->getEntityManager()->flush();
     $this->getParameterBag()->set('product', $product);
 }