/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var EntityManager $manager */
     $user = $this->getUser($manager);
     $businessUnit = $user->getOwner();
     $organization = $user->getOrganization();
     $locator = $this->container->get('file_locator');
     $filePath = $locator->locate('@OroB2BProductBundle/Migrations/Data/Demo/ORM/data/products.csv');
     if (is_array($filePath)) {
         $filePath = current($filePath);
     }
     $handler = fopen($filePath, 'r');
     $headers = fgetcsv($handler, 1000, ',');
     $inventoryStatuses = $this->getAllEnumValuesByCode($manager, 'prod_inventory_status');
     $visibilities = $this->getAllEnumValuesByCode($manager, 'prod_visibility');
     $statuses = $this->getAllEnumValuesByCode($manager, 'prod_status');
     while (($data = fgetcsv($handler, 1000, ',')) !== false) {
         $row = array_combine($headers, array_values($data));
         $name = new LocalizedFallbackValue();
         $name->setString($row['name']);
         $description = new LocalizedFallbackValue();
         $description->setText(nl2br($row['description']));
         $product = new Product();
         $product->setOwner($businessUnit)->setOrganization($organization)->setSku($row['sku'])->setInventoryStatus($inventoryStatuses[1])->setVisibility($visibilities[0])->setStatus($statuses[1])->addName($name)->addDescription($description);
         $manager->persist($product);
     }
     fclose($handler);
     $manager->flush();
 }
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $title = new LocalizedFallbackValue();
     $title->setString('Master catalog');
     $category = new Category();
     $category->addTitle($title);
     $manager->persist($category);
     $manager->flush($category);
 }
 public function testToString()
 {
     $stringValue = new LocalizedFallbackValue();
     $stringValue->setString('string');
     $this->assertEquals('string', (string) $stringValue);
     $textValue = new LocalizedFallbackValue();
     $textValue->setText('text');
     $this->assertEquals('text', (string) $textValue);
     $emptyValue = new LocalizedFallbackValue();
     $this->assertEquals('', (string) $emptyValue);
 }
 /**
  * @param Category $root
  * @param array $categories
  */
 protected function addCategories(Category $root, array $categories)
 {
     if (!$categories) {
         return;
     }
     foreach ($categories as $title => $nestedCategories) {
         $categoryTitle = new LocalizedFallbackValue();
         $categoryTitle->setString($title);
         $category = new Category();
         $category->addTitle($categoryTitle);
         $root->addChildCategory($category);
         $this->addCategories($category, $nestedCategories);
     }
 }
 /**
  * @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;
 }
 /**
  * @param int|null $entityId
  * @param int|null $localeId
  * @param string|FallbackType $fieldValue
  * @return LocalizedFallbackValue
  */
 protected function generateLocalizedFallbackValue($entityId, $localeId, $fieldValue)
 {
     $localizedFallbackValue = null;
     if ($entityId) {
         $localizedFallbackValue = $this->findLocalizedFallbackValue($entityId);
     }
     if (!$localizedFallbackValue) {
         $localizedFallbackValue = new LocalizedFallbackValue();
     }
     $localizedFallbackValue->setLocale($localeId ? $this->findLocale($localeId) : null);
     if ($fieldValue instanceof FallbackType) {
         $localizedFallbackValue->setFallback($fieldValue->getType());
         $this->propertyAccessor->setValue($localizedFallbackValue, $this->field, null);
     } else {
         $localizedFallbackValue->setFallback(null);
         $this->propertyAccessor->setValue($localizedFallbackValue, $this->field, $fieldValue);
     }
     return $localizedFallbackValue;
 }
Example #7
0
 public function testToString()
 {
     $value = 'test';
     $title = new LocalizedFallbackValue();
     $title->setString($value);
     $category = new Category();
     $category->addTitle($title);
     $this->assertEquals($value, (string) $category);
 }
 /**
  * @param string|null $string
  * @param string|null $text
  * @return LocalizedFallbackValue
  */
 protected function createLocalizedValue($string = null, $text = null)
 {
     $value = new LocalizedFallbackValue();
     $value->setString($string)->setText($text);
     return $value;
 }
 public function testGetDefaultDescription()
 {
     $defaultDescription = new LocalizedFallbackValue();
     $defaultDescription->setString('default');
     $localizedDescription = new LocalizedFallbackValue();
     $localizedDescription->setString('localized')->setLocale(new Locale());
     $category = new Product();
     $category->addDescription($defaultDescription)->addDescription($localizedDescription);
     $this->assertEquals($defaultDescription, $category->getDefaultDescription());
 }
 /**
  * @param array $categories
  * @return array
  */
 protected function prepareCategories(array $categories)
 {
     foreach ($categories as $item) {
         $categoryTitle = new LocalizedFallbackValue();
         $categoryTitle->setString($item['title']);
         $category = $this->createCategory($item['id']);
         $category->addTitle($categoryTitle);
         $category->setParentCategory($this->getParent($item['parent']));
         $this->categoriesCollection[$category->getId()] = $category;
     }
     foreach ($this->categoriesCollection as $parentCategory) {
         foreach ($this->categoriesCollection as $category) {
             if ($category->getParentCategory() == $parentCategory) {
                 $parentCategory->addChildCategory($category);
             }
         }
     }
 }