public function testOnDuplicateAfterSourceProductLinkedWithCategory()
 {
     $this->category->getProducts()->clear();
     $this->category->addProduct($this->sourceProduct);
     $event = new ProductDuplicateAfterEvent($this->product, $this->sourceProduct);
     $this->listener->onDuplicateAfter($event);
     $this->assertCount(2, $this->category->getProducts());
     $this->assertTrue($this->category->getProducts()->contains($this->product));
 }
Пример #2
0
 public function testProductAccessors()
 {
     $firstProduct = new Product();
     $secondProduct = new Product();
     $category = new Category();
     $category->addProduct($firstProduct)->addProduct($secondProduct);
     $this->assertEquals([0 => $firstProduct, 1 => $secondProduct], $category->getProducts()->toArray());
     $category->removeProduct($firstProduct);
     $this->assertEquals([1 => $secondProduct], $category->getProducts()->toArray());
 }
Пример #3
0
 /**
  * @param Category  $category
  * @param Product[] $products
  */
 protected function appendProducts(Category $category, array $products)
 {
     $categoryRepository = $this->manager->getRepository('OroB2BCatalogBundle:Category');
     /** @var $product Product */
     foreach ($products as $product) {
         $productCategory = $categoryRepository->findOneByProduct($product);
         if ($productCategory instanceof Category) {
             $productCategory->removeProduct($product);
             $this->manager->flush($productCategory);
         }
         $category->addProduct($product);
     }
 }