/**
  * @param ObjectManager $manager
  * @param string $sku
  * @return Product
  */
 protected function createProduct(ObjectManager $manager, $sku)
 {
     $businessUnit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->getFirst();
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $name = new LocalizedFallbackValue();
     $name->setString($sku);
     $product = new Product();
     $product->setSku($sku);
     $name = new LocalizedFallbackValue();
     $name->setString($sku);
     $product->addName($name);
     $product->setOwner($businessUnit);
     $product->setOrganization($organization);
     $product->addName($name);
     $manager->persist($product);
     $this->addReference($sku, $product);
     return $product;
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var EntityManager $manager */
     $user = $this->getUser($manager);
     $businessUnit = $user->getOwner();
     $organization = $user->getOrganization();
     foreach ($this->products as $item) {
         $product = new Product();
         $product->setOwner($businessUnit)->setOrganization($organization)->setSku($item['productCode']);
         $name = new LocalizedFallbackValue();
         $product->addName($name);
         $name->setString($item['productCode']);
         $manager->persist($product);
         $this->addReference($item['productCode'], $product);
     }
     $manager->flush();
 }
 /**
  * @param Product $product
  * @param Product $productCopy
  */
 protected function cloneChildObjects(Product $product, Product $productCopy)
 {
     foreach ($product->getUnitPrecisions() as $unitPrecision) {
         $productCopy->addUnitPrecision(clone $unitPrecision);
     }
     foreach ($product->getNames() as $name) {
         $productCopy->addName(clone $name);
     }
     foreach ($product->getDescriptions() as $description) {
         $productCopy->addDescription(clone $description);
     }
     if ($imageFile = $product->getImage()) {
         $imageFileCopy = $this->attachmentManager->copyAttachmentFile($imageFile);
         $productCopy->setImage($imageFileCopy);
     }
     $attachments = $this->attachmentProvider->getEntityAttachments($product);
     foreach ($attachments as $attachment) {
         $attachmentCopy = clone $attachment;
         $attachmentFileCopy = $this->attachmentManager->copyAttachmentFile($attachment->getFile());
         $attachmentCopy->setFile($attachmentFileCopy);
         $attachmentCopy->setTarget($productCopy);
         $this->doctrineHelper->getEntityManager($attachmentCopy)->persist($attachmentCopy);
     }
 }
 /**
  * @param array $names
  * @dataProvider getDefaultNameExceptionDataProvider
  *
  * @expectedException \LogicException
  * @expectedExceptionMessage There must be only one default name
  */
 public function testGetDefaultNameException(array $names)
 {
     $product = new Product();
     foreach ($names as $title) {
         $product->addName($title);
     }
     $product->getDefaultName();
 }