Example #1
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 #3
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
     }
 }
Example #4
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 #5
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var User $userAdmin */
     $userAdmin = $this->getReference('user-admin');
     $product1 = new Product();
     $product1->setName('Upsell message');
     $product1->setCode("{{ 'twig' }}");
     $product1->setUser($userAdmin);
     $manager->persist($product1);
     $product2 = new Product();
     $product2->setName('me');
     $product2->setCode('sadsadsa');
     $product2->setCurrency('$');
     $manager->persist($product2);
     $product3 = new Product();
     $product3->setName('Close message');
     $product3->setCode("{{ 'twig' }}");
     $product3->setUser($userAdmin);
     $manager->persist($product3);
     $product4 = new Product();
     $product4->setName('продукт');
     $product4->setPrice(1000);
     $product4->setCurrency('$');
     $product4->setUser($userAdmin);
     $manager->persist($product4);
     $this->setReference('product-4', $product4);
     $product5 = new Product();
     $product5->setName('продукт');
     $product5->setPrice(1000);
     $product5->setCurrency('$');
     $product5->setUser($userAdmin);
     $manager->persist($product5);
     $this->setReference('product-5', $product5);
     $manager->flush();
 }
Example #6
0
 public function index2Action()
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $product = new Product();
     $product->setName('xxxx');
     $product->setPrice(5.97);
     $em->persist($product);
     $em->flush();
     $product = new Product();
     $product->setName('xxxx');
     $product->setPrice(30);
     $em->persist($product);
     $em->flush();
     $query = $em->createQuery('SELECT p
       FROM AppBundle:Product p
       WHERE p.price > :price
       ORDER BY p.name ASC')->setParameter('price', '19.99');
     $products = $query->getResult();
     $query = $em->createQuery('DELETE
        FROM AppBundle:Product p
        WHERE p.name = :name')->setParameter('name', 'xxxx');
     $products = $query->execute();
     return $this->render('AppBundle:test:index.html.twig', array('data' => print_r(null, true)));
 }
 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("/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());
 }
 /**
  * @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]);
 }
Example #10
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();
 }
Example #11
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 #12
0
 private function generateContent(ObjectManager $manager)
 {
     $products = array(array('name' => 'Phone A8181', 'code' => 'A8181', 'price' => '180.0', 'content' => 'Nihil morati post haec militares avidi saepe turbarum adorti sunt Montium primum, qui divertebat in proximo, levi corpore senem atque morbosum, et hirsutis resticulis cruribus eius innexis divaricaturn sine spiramento ullo ad usque praetorium traxere praefecti.', 'enabled' => true), array('name' => 'Phone B8', 'code' => 'PB8', 'price' => '365.0', 'content' => 'Et olim licet otiosae sint tribus pacataeque centuriae et nulla suffragiorum certamina set Pompiliani redierit securitas temporis, per omnes tamen quotquot sunt partes terrarum, ut domina suscipitur et regina et ubique patrum reverenda cum auctoritate canities populique Romani nomen circumspectum et verecundum.', 'enabled' => true), array('name' => 'Tab Smart 18', 'code' => 'TAB-S18', 'price' => '320.0', 'content' => 'Cuius acerbitati uxor grave accesserat incentivum, germanitate Augusti turgida supra modum, quam Hannibaliano regi fratris filio antehac Constantinus iunxerat pater, Megaera quaedam mortalis.', 'enabled' => true));
     foreach ($products as $key => $product) {
         $entry = new Product();
         $entry->setName($product['name']);
         $entry->setCode($product['code']);
         $entry->setPrice($product['price']);
         $entry->setContent($product['content']);
         $entry->setEnabled($product['enabled']);
         $manager->persist($entry);
     }
 }
Example #13
0
 public function load(ObjectManager $manager)
 {
     $product = new Product();
     $product->setName('ProductOne');
     $product->setPrice(8.550000000000001);
     $product->setQuanity(50);
     $product2 = new Product();
     $product2->setName('ProductTwo');
     $product2->setPrice(9.25);
     $product2->setQuanity(8);
     $manager->persist($product);
     $manager->persist($product2);
     $manager->flush();
 }
Example #14
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();
 }
 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 #16
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 #17
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 #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
 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 #20
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 #21
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());
     }
 }
 /**
  * @Route(
  *     "/product/create",
  *     name="create_product"
  * )
  * @Method("POST")
  */
 public function createProductAction()
 {
     if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
         $request = Request::createFromGlobals();
         $order_id = intval($request->request->get('order_id', 0));
         $title = strval($request->request->get('title'));
         $price = floatval($request->request->get('price'));
         $link = strval($request->request->get('link'));
         $quantity = intval($request->request->get('quantity'));
         if ($order_id > 0 && $price > 0 && $quantity > 0 && $title != '') {
             // Check whether order with such ID exist
             $order = $this->getDoctrine()->getRepository('AppBundle:Orders')->find($order_id);
             if ($order) {
                 // Check whether order is still open to join / change quantities
                 $closing_after = Utilities::countTimeRemaining(date_timestamp_get($order->getJoiningDeadline()));
                 if ($closing_after != Utilities::$STATUS_JOINING_TIME_IS_OVER) {
                     $user = $this->getUser();
                     $product = new Product();
                     $product->setTitle($title);
                     $product->setPrice($price);
                     $product->setLink($link);
                     $product->setOrders($order);
                     $userProduct = new UserProduct();
                     $userProduct->setProduct($product);
                     $userProduct->setQuantity($quantity);
                     $userProduct->setUser($user);
                     $product->addUserProduct($userProduct);
                     $em = $this->getDoctrine()->getManager();
                     $em->persist($userProduct);
                     $em->persist($product);
                     $em->flush();
                     return $this->render('default/product.html.twig', array('order' => $order, 'product' => $product, 'quantity' => $quantity));
                 } else {
                     return new Response(AjaxResponses::$ORDER_JOINING_TIME_IS_OVER, Response::HTTP_NOT_FOUND);
                 }
             } else {
                 return new Response(AjaxResponses::$ORDER_NOT_FOUND, Response::HTTP_NOT_FOUND);
             }
         } else {
             return new Response(AjaxResponses::$WRONG_REQUEST_PARAMETERS, Response::HTTP_BAD_REQUEST);
         }
     } else {
         return new Response(AjaxResponses::$UNAUTHORIZED, Response::HTTP_UNAUTHORIZED);
     }
 }
Example #23
0
 public function addProduct($name, $categoryName = null)
 {
     $category = null;
     if ($categoryName != null) {
         $category = $this->addCategory($categoryName);
     }
     $product = $this->getProduct($name);
     if ($product == null) {
         $product = new Product();
         $product->setName($name);
         $product->setPrice(0);
         $product->setCategory($category);
         $this->em->persist($product);
     } else {
         $product->setCategory($category);
     }
     return $product;
 }
 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 #26
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 #27
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 #28
0
 public function newAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $task = new Task();
     $task->setName('Task name');
     // dummy code - this is here just so that the Task has some tags
     // otherwise, this isn't an interesting example
     $product1 = new Product();
     $product1->setName('prodct1');
     $product1->setPrice('11.11');
     $task->getProducts()->add($product1);
     $product2 = new Product();
     $product2->setName('product2');
     $product2->setPrice('22.22');
     $task->getProducts()->add($product2);
     $form = $this->createForm(TaskType::class, $task);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->persist($task);
         $em->flush();
         return $form->get('saveAndAdd')->isClicked() ? $this->redirectToRoute('task_new', [], 301) : $this->redirectToRoute('task_list', [], 301);
     }
     return $this->render('AppBundle:Task:new.html.twig', array('form' => $form->createView()));
 }
Example #29
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.');
 }
 /**
  * {@inheritDoc}
  */
 public function setPrice($price)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setPrice', array($price));
     return parent::setPrice($price);
 }