示例#1
0
 /**
  * Find product in cart
  *
  * @param FrontendUser $user
  * @param Product $product
  *
  * @return Cart $cartItem
  */
 public function findProduct($user, $product)
 {
     $query = $this->getDocumentManager()->createQueryBuilder('Aisel\\CartBundle\\Document\\Cart')->field('product')->equals($product->getId())->field('frontenduser')->equals($user->getId());
     $cartItem = $query->getQuery()->execute()->toArray();
     if ($cartItem) {
         return $cartItem[0];
     }
     return false;
 }
示例#2
0
 public function testDuplicateImages()
 {
     $image = new Image();
     $image->setFilename($this->faker->numberBetween(0, 10000));
     $image->setMainImage(false);
     $this->dm->persist($image);
     $this->dm->flush();
     $this->assertNotNull($image->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->addImage($image);
     $product->addImage($image);
     $this->dm->persist($product);
     $this->dm->flush();
     $this->assertNotNull($product->getId());
     $this->assertEquals(count($product->getImages()), 1);
     $this->dm->remove($image);
     $this->dm->flush();
     $this->dm->remove($product);
     $this->dm->flush();
 }
示例#3
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();
             }
         }
     }
 }
 public function testDuplicatedUrlThrowsError()
 {
     $urlText = 'product-test-meta-url';
     $this->setExpectedException('LogicException', 'Given URL already exists');
     // Create Product 1
     $product1 = new Product();
     $product1->setLocale('en');
     $product1->setDescription('...');
     $product1->setDescriptionShort('...');
     $product1->setInStock(false);
     $product1->setName('...');
     $product1->setSku('test-1');
     $product1->setStatus(true);
     $product1->setMetaUrl($urlText);
     $product1->setMetaTitle('...');
     $product1->setCommentStatus(true);
     $this->dm->persist($product1);
     $this->dm->flush();
     // Create Product 2
     $product2 = new Product();
     $product2->setLocale('en');
     $product2->setDescription('...');
     $product2->setDescriptionShort('...');
     $product2->setInStock(false);
     $product2->setName('...');
     $product2->setSku('test-2');
     $product2->setStatus(true);
     $product2->setMetaUrl($urlText);
     $product2->setMetaTitle('...');
     $product2->setCommentStatus(true);
     $this->dm->persist($product2);
     $this->dm->flush();
     // Delete Product 1
     $product1 = $this->dm->getRepository('Aisel\\ProductBundle\\Document\\Product')->findOneBy(['metaUrl' => $urlText]);
     $this->dm->remove($product1);
     $this->dm->flush();
 }