/**
  * @return Product
  */
 public function setDataToObject()
 {
     $this->object->setSku($this->getFormattedData('sku', 'string'));
     $this->object->setName($this->getFormattedData('name', 'string'));
     $this->object->setPicture($this->getFormattedData('picture', 'string'));
     $this->object->setUrl($this->getFormattedData('url', 'string'));
     $this->object->setManufacturer($this->getFormattedData('manufacturer', 'string'));
     $this->object->setCategory($this->getFormattedData('category', 'string'));
     $this->object->setCategoryOuterId($this->getFormattedData('categoryOuterId', 'string'));
     $this->object->setIsDescription($this->getFormattedData('isDescription', 'integer'));
     $this->object->setStatus($this->getFormattedData('status', 'integer'));
     $this->object->setAvailableDate($this->getFormattedData('availableDate', 'date'));
     $this->object->setProductCreateDate($this->getFormattedData('productCreateDate', 'date'));
     parent::setDataToObject();
 }
Example #2
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 #3
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();
 }
 /**
  * {@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 #5
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)));
 }
Example #6
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();
 }
 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();
 }
Example #8
0
 protected function setObjects()
 {
     $this->object->setSku('');
     $this->object->setName('');
     $this->object->setPicture('');
     $this->object->setUrl('');
     $this->object->setManufacturer('');
     $this->object->setCategory('');
     $this->object->setProductCreateDate(new \DateTime());
     $object = new ProductInformation();
     $object->setInformationKey('i1');
     $object->setInformationValue('v4');
     $object->setProduct($this->object);
     $this->informationObjects[] = $object;
     $object = new ProductInformation();
     $object->setInformationKey('i2');
     $object->setInformationValue('v4');
     $object->setProduct($this->object);
     $this->informationObjects[] = $object;
 }
 /**
  * @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 #11
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 #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
 /**
  * @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 #14
0
 public function load(ObjectManager $manager)
 {
     $product = new Product();
     $product->setName('AGM-123 Skipper II - laser quided bomb');
     $manager->persist($product);
     $product = new Product();
     $product->setName('Vis wz. 35 - pistol');
     $manager->persist($product);
     $product = new Product();
     $product->setName('TWARDY PT-91 - tank');
     $manager->persist($product);
     $manager->flush();
 }
Example #15
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 #16
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();
 }
 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 #18
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 #19
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 #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("/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 #22
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 #23
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $categoryData = ['sport' => ['soccer_ball', 'tennis', 'billiards', 'skiing'], 'make_up' => ['perfume', 'pomade', 'powder', 'shampoo'], 'clothes' => ['dresses', 'costumes', 'coat', 'hats'], 'mobile' => ['smartphone', 'flash_drive', 'camera', 'the_tablet']];
     foreach ($categoryData as $categoryName => $productList) {
         $category = new Category();
         $category->setName($categoryName);
         $manager->persist($category);
         $manager->flush();
         foreach ($productList as $productName) {
             $product = new Product();
             $product->setName($productName);
             $manager->persist($product);
             $manager->flush();
             $category->addProduct($product);
         }
     }
 }
Example #24
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;
 }
 /**
  * @Route("/product",
  *        name = "api_product_create",
  *        requirements = {"_format" = "json"},
  *        defaults = {"_format" = "json"})
  * @Method({"POST"})
  */
 public function createAction(Request $request)
 {
     $em = $this->getEntityManager();
     $request = $request->request;
     $name = trim($request->get('name'));
     $price = $request->get('price');
     $description = $request->get('description', '');
     if (!$name) {
         throw new \InvalidArgumentException('No product name specified');
     }
     if (!$price) {
         throw new \InvalidArgumentException('No product price specified');
     }
     $product = new Product();
     $product->setName($name)->setPrice($price)->setDescription($description);
     $em->persist($product);
     $em->flush();
     $output = $product->toArray();
     return new JsonResponse($output);
 }
 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;
 }
 public function load(ObjectManager $manager)
 {
     for ($i = 0; $i < 40; $i++) {
         $product = new Product();
         $product->setName('Name Product ' . $i);
         $featureA = new Feature();
         $featureA->setName('Description');
         $featureA->setDescription("This is a feature's description");
         $featureA->setProduct($product);
         $manager->persist($featureA);
         $product->addFeature($featureA);
         $featureB = new Feature();
         $featureB->setName('Warranty');
         $featureB->setDescription("This is a warranty's description");
         $featureB->setProduct($product);
         $manager->persist($featureB);
         $product->addFeature($featureB);
         $manager->persist($product);
     }
     $manager->flush();
 }
 /**	 
  * @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 #29
0
 /**
  * Fetch the product variant record from the db. If it does not exist, create it.
  *
  * @param IncomingProduct $product
  *
  * @return ProductVariant
  */
 protected function getProductVariantRecord(IncomingProduct $product)
 {
     $productVariant = $this->entityManager->getRepository('AppBundle:ProductVariant')->find($product->getSku());
     if (!$productVariant) {
         $parentProduct = $this->entityManager->getRepository('AppBundle:Product')->findOneByName($product->getProductName());
         if (!$parentProduct) {
             $parentProduct = new Product();
             $parentProduct->setName($product->getProductName());
             $this->entityManager->persist($parentProduct);
         }
         $productVariant = new ProductVariant();
         $productVariant->setProduct($parentProduct);
         $this->updateVariant($product, $productVariant);
         $this->changes[] = 'Add product ' . $product->getName();
     } else {
         if (!$product->isEqualToProductVariant($productVariant)) {
             $this->updateVariant($product, $productVariant);
             $this->changes[] = 'Updated product ' . $product->getName();
         }
     }
     return $productVariant;
 }
Example #30
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();
 }