/**
  * @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
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // use api parameters from a settings file
     // Make api call to get list of products
     $products = $this->getListPromotionProducts();
     $productUrls = $this->array_value_recursive('productUrl', $products);
     // Make api call to get the affiliate url for each product
     $affiliateUrls = $this->getPromotionLinks($productUrls);
     /*
      * Store product feed in db 
      */
     // $category = new Category();
     // $category->setName('Apparel');
     $category = $this->getContainer()->get('doctrine')->getRepository('AppBundle:Category')->find(1);
     foreach ($products as $key => $p) {
         $product = new Product();
         $product->setCategory($category)->setAliProductId($p['productId'])->setAliProductTitle($p['productTitle'])->setAliProductUrl($p['productUrl'])->setAliSalePrice(round(floatval(substr($p['salePrice'], 4))))->setAli30DaysCommission($p['30daysCommission'])->setAliVolume($p['volume'])->setAliCategoryId($options['categoryId'])->setAliAffiliateUrl($affiliateUrls[$key]['promotionUrl']);
         $em = $this->getEntityManager('default');
         $em->persist($product);
         $em->persist($category);
         $em->flush();
         // $output->writeln($p['productTitle']);
     }
     echo 'just sent ' . count($products) . ' products to the db' . "\n\n";
     // call get:photos command for each photo to see scrape pics from ali site
 }
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
 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;
 }
Example #5
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 #6
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 #7
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 #8
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());
 }
 /**
  * @Route("/db/create_relationship/")
  * @return Response
  */
 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 #10
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;
 }
Example #11
0
 public function createStaticAction()
 {
     // Creamos el objeto category y seleccionamos categoria entre 0-10 mediante random
     $category = new Category();
     $category->setName(sprintf("Category%d", rand(0, 10)));
     // Creamos el objeto producto con todos sus atributos.
     $product = new Product();
     $product->setName('Arroz');
     $product->setPrice('0.99');
     $product->setDescription('Paquete de 1kg de arroz');
     //relacionamos con categoría
     $product->setCategory($category);
     // recogemos el manager
     $em = $this->getDoctrine()->getManager();
     // persistimos
     $em->persist($category);
     $em->persist($product);
     // alamacenamos en la base de datos.
     $em->flush();
     return $this->Render('product/staticProduct.html.twig', array('product' => $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 #13
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 #14
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());
 }
 /**
  * Add product
  *
  * @param \AppBundle\Entity\Product $product
  *
  * @return Category
  */
 public function addProduct(Product $product)
 {
     $product->setCategory($this);
     $this->products[] = $product;
     return $this;
 }
 /**
  * @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());
 }