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(); }
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 }
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))); }
/** * @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'); }
/** * Displays a form to create a new Product entity. * * @Route("/new", name="admin_product_new") * @Method("GET") */ public function newAction() { $entity = new Product(); $entity->SetImageLink(uniqid()); $form = $this->createCreateForm($entity); return $this->render('Admin/Product/new.html.twig', array('entity' => $entity, 'form' => $form->createView())); }
protected function saveObjects() { // Product information korábbi elemeinek törlése $oldItems = $this->object->getInformation()->toArray(); if ($oldItems) { foreach ($oldItems as $item) { $this->entityManager->remove($item); $this->object->removeInformation($item); } } // Product information-be új elemek hozzá adása if ($this->informationObjects) { foreach ($this->informationObjects as $item) { $this->object->addInformation($item); } } // Product persist $this->entityManager->persist($this->object); // Product information persistek if ($this->informationObjects) { foreach ($this->informationObjects as $object) { $this->entityManager->persist($object); } } //Flush $this->entityManager->flush(); }
public function updateAttributeSet(Product $product) { $attributes = $product->getCategory()->getAttributes(); $attributesCloned = clone $attributes; $attrValues = $product->getAttributeValues(); if ($attrValues->count() > 0) { $em = $this->doctrine->getManager(); foreach ($attrValues as $attrValue) { $attribute = $attrValue->getAttribute(); if ($attributes->contains($attribute)) { $attributesCloned->removeElement($attribute); } else { $product->removeAttributeValue($attrValue); $em->remove($attrValue); } } $em->flush(); } if ($attributesCloned->count() > 0) { foreach ($attributesCloned as $attribute) { $attrValue = new AttributeValue(); $attrValue->setProduct($product)->setAttribute($attribute); $product->addAttributeValue($attrValue); } } return $product; }
public function testProductServiceGetProductById() { $productId = 5; $repository = $this->getMockBuilder(ObjectRepository::class)->getMock(); $product = new Product(); $repository->expects(self::once())->method('findOneBy')->with(['id' => $productId])->will(self::returnValue($product->setId($productId))); $service = new ProductService($repository); self::assertEquals($product->setId($productId), $service->getProductById($productId)); }
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(); }
public function testDeleteQty() { $product = new Product(); $product->setQty(6); $item = new Item(); $item->setQty(4); $item->setProduct($product); PurchaseItemManager::deleteQty($item); $this->assertEquals(2, $item->getProduct()->getQty(), "Unexpected value for qty in product for deleteQty method "); }
/** * Deletes a Product entity. * * @Route("/delete/{id}", name="product_delete") * @Method("GET") * @param Request $request * @param Product $product * @return index page */ public function deleteAction(Request $request, Product $product) { if ($request->get('pass') !== 'angólar') { $this->addFlash('danger', 'Nie masz uprawnień do wykonania tej operacji'); } else { $em = $this->getDoctrine()->getManager()->getRepository('AppBundle:Product'); $em->createQueryBuilder('p')->delete()->where('p.id = :product')->setParameter('product', $product->getId())->getQuery()->execute(); $this->addFlash('success', 'Pomyslnie usunąłeś produkt'); } return $this->redirectToRoute('database_index'); }
private function createAndPersistProducts(Category $category) { for ($i = 1; $i <= $this->productsPerCategory; $i++) { $this->productsCount++; $product = new Product(); $product->setCode(sprintf('code_%s_%s', $category->getId(), $i))->setTitle(sprintf('title %s %s %s', $category->getId(), $i, uniqid()))->setDescription(sprintf('product description %s', $i)); $category->addProduct($product); $this->manager->persist($product); $this->setReference(sprintf('product_%s', $this->productsCount), $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()); }
/** * Usuwa produkt z koszyka * * @param Product $product * @return \AppBundle\Utils\Basket * @throws ProductNotFoundException */ public function remove(Product $product) { $basket = $this->session->get('basket', []); if (!array_key_exists($product->getId(), $basket)) { throw new ProductNotFoundException("Produkt nie znajduje się w koszyku."); } unset($basket[$product->getId()]); // aktualizujemy koszyk $this->session->set('basket', $basket); return $this; }
/** * Usuwa produkt z koszyka * * @param Product $product * @return Basket * @throws ProductNotFoundException */ public function remove(Product $product) { $basket = $this->session->get('basket', []); if (array_key_exists($product->getId(), $basket)) { unset($basket[$product->getId()]); } else { throw new ProductNotFoundException("Wybranego produktu nie miałeś w koszyku!"); } $this->session->set('basket', $basket); return $this; }
/** * @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]); }
/** * Usuwanie produktu z koszyka * @param Product $product * @return \AppBundle\Utils\Basket * @throws ProductNotFoundException */ public function remove(Product $product) { $basket = $this->session->get('basket', []); if (!array_key_exists($product->getId(), $basket)) { throw new ProductNotFoundException('Produkt nie został znaleziony w koszyku'); } unset($basket[$product->getId()]); //Aktualizujemy stan koszyka w sesji $this->session->set('basket', $basket); return $this; }
/** * @Route("/create", name="create") */ public function createAction() { $category = new Category(); $category->setName('Apparel Women'); $product = new Product(); $product->setAliProductId('32251240493')->setAliProductTitle('DL vestido de renda 2016 Navy Lace Satin Patchwork Party Maxi Dress LC6809 dress party evening elegant vestido longo festa noite')->setCategory($category)->setAliProductUrl('productUrl')->setAliSalePrice('US $16.99')->setAli30DaysCommission('30daysCommission')->setAliVolume('volume')->setAliCategoryId('3')->setAliAffiliateUrl('promotionUrl')->setNumReviews('92')->setNumReviewPages('10')->setDateOfLatestReview(strtotime('07 Jan 2016 19:19'))->setDateLastCrawled(strtotime('01 Jan 2016 00:19')); $em = $this->getDoctrine()->getManager(); $em->persist($product); $em->persist($category); $em->flush(); return new Response('Created product id ' . $product->getId() . ' and category id ' . $category->getId()); }
/** * @param Product $product * @param int $nbProduct * @param Currency $currency * * @return float */ public function convertPrice(Product $product, $nbProduct = 1, Currency $currency = null) { if (!$currency instanceof Currency) { $currency = $this->basketManager->getCurrencyWanted(); } $price = $product->getPrice() * $nbProduct; if ($currency->getCode() !== $product->getCurrency()->getCode()) { $rate = $this->ratesCaller->getRateFor($product->getCurrency(), $currency); $price = $rate * $price; } return $price; }
/** * 向购物车添加指定项目 */ public function addProduct(Product $product, $quantity = 1) { if ($product->isUnavailable()) { throw new \InvalidArgumentException('Product unavailable'); } $mapping = $this->getMapping(); // if( $this->hasProduct($product) ) { // $quantity += $mapping[$product->getId()]; // } $mapping[$product->getId()] = $quantity; $this->session->set(self::CART, $mapping); }
/** * @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()); }
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(); }
/** * {@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(); }
/** * {@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) { $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(); }
/** * @Route("/insert/product", name="insert_product") */ public function insertProductAction(Request $request) { $product = new Product(); $product->setAdded(new \DateTime('now')); $product->setState('Italy'); $form = $this->createForm(ProductType::class, $product); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($product); $em->flush(); return $this->redirectToRoute('insert_product'); } return $this->render('product/insert.html.twig', array('form' => $form->createView())); }
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())); }
public function load(ObjectManager $manager) { foreach (range(0, 99) 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->setImage('image' . $i % 10 . '.jpg'); $product->setDescription($this->getRandomDescription()); $product->setCategories($this->getRandomCategories()); $this->addReference('product-' . $i, $product); $manager->persist($product); } $manager->flush(); }
public function testInstantiateFromAdminReturnsNewProduct() { $product = new Product('test'); $productFromAdmin = new ProductFromAdmin(); $productFromAdmin->name = 'test'; $instantiatedProduct = Product::instantiateFromAdmin($productFromAdmin); self::assertEquals($instantiatedProduct, $product); }
public function createAction() { $productFromAdmin = new ProductFromAdmin(); $productData = Product::instantiateFromAdmin($productFromAdmin); // $productData = new ProductFromAdmin(); // $productData->name = 'Wat NU?'; return $this->templateEngine->renderResponse('AppBundle:admin:productStore.html.twig', array('product' => $productData)); }