Example #1
0
 public function testDuplicateNodes()
 {
     $node = new Node();
     $node->setStatus(true);
     $node->setDescription($this->faker->sentence(10));
     $node->setMetaUrl('url_' . time());
     $node->setLocale('en');
     $this->dm->persist($node);
     $this->dm->flush();
     $this->assertNotNull($node->getId());
     $product = new Product();
     $product->setLocale('en');
     $product->setName($this->faker->sentence(1));
     $product->setDescriptionShort($this->faker->sentence(10));
     $product->setDescription($this->faker->sentence(10));
     $product->setStatus(true);
     $product->setCommentStatus(true);
     $product->setMetaUrl('url_' . time());
     $product->addNode($node);
     $product->addNode($node);
     $this->dm->persist($product);
     $this->dm->flush();
     $this->assertNotNull($product->getId());
     $this->assertEquals(count($product->getNodes()), 1);
     $this->dm->remove($node);
     $this->dm->flush();
     $this->dm->remove($product);
     $this->dm->flush();
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     // Delete all files and directories
     $this->cleanMediaDir();
     foreach ($this->fixtureFiles as $file) {
         if (file_exists($file)) {
             $contents = file_get_contents($file);
             $XML = simplexml_load_string($contents);
             foreach ($XML->database->table as $table) {
                 $product = new Product();
                 $product->setLocale($table->column[1]);
                 $product->setName($table->column[2]);
                 $product->setSku($table->column[3]);
                 $product->setPrice((int) $table->column[4]);
                 $product->setQty((int) $table->column[11]);
                 $product->setDescriptionShort($table->column[14]);
                 $product->setDescription($table->column[15]);
                 $product->setStatus((int) $table->column[16]);
                 $product->setHidden((int) $table->column[17]);
                 $product->setCommentStatus((int) $table->column[18]);
                 $product->setMetaUrl($table->column[19]);
                 $nodes = explode(",", $table->column[20]);
                 foreach ($nodes as $c) {
                     $node = $this->getReference('product_node_' . $c);
                     $product->addNode($node);
                 }
                 $manager->persist($product);
                 $manager->flush();
                 $this->addReference('product_' . $table->column[0], $product);
                 $images = $this->setProductImage($manager, $product);
                 $product->setMedias($images);
                 $manager->persist($product);
                 $manager->flush();
             }
         }
     }
 }