/**
  * Get id from category and Magento url.
  *
  * @param CategoryInterface $category
  * @param string            $magentoUrl
  * @param MappingCollection $categoryMapping
  *
  * @return int|null
  */
 public function getIdFromCategory(CategoryInterface $category, $magentoUrl, MappingCollection $categoryMapping = null)
 {
     if ($categoryMapping && ($categoryId = $categoryMapping->getTarget($category->getCode())) != $category->getCode()) {
         return $categoryId;
     } else {
         $categoryMapping = $this->getEntityRepository()->findOneBy(['category' => $category, 'magentoUrl' => $magentoUrl]);
         return $categoryMapping ? $categoryMapping->getMagentoCategoryId() : null;
     }
 }
 /**
  * Get all sources
  * @param CategoryInterface $category
  *
  * @return array
  */
 public function getAllSources(CategoryInterface $category = null)
 {
     $sources = [];
     if ($this->isValid()) {
         $categories = $category === null ? $this->categoryManager->getTrees() : $category->getChildren();
         foreach ($categories as $category) {
             $sources[] = ['id' => $category->getCode(), 'text' => sprintf('%s (%s)', $category->getLabel(), $category->getCode())];
             $sources = array_merge($sources, $this->getAllSources($category));
         }
     }
     return $sources;
 }
 function it_provides_formatted_batch_config_for_the_job(CategoryInterface $officeCategory, CategoryInterface $bedroomCategory)
 {
     $officeCategory->getCode()->willReturn('office_room');
     $bedroomCategory->getCode()->willReturn('bedroom');
     $this->setCategories([$officeCategory, $bedroomCategory]);
     $this->setFilters([['id', 'IN', ['49', '2']]]);
     $this->getBatchConfig()->shouldReturn('{\\"filters\\":[[\\"id\\",\\"IN\\",[\\"49\\",\\"2\\"]]],\\"actions\\":[{\\"field\\":\\"categories\\",\\"value\\":[\\"office_room\\",\\"bedroom\\"]}]}');
 }
 /**
  * Update default tree of users using a tree that will be removed
  *
  * @param CategoryInterface $category
  *
  * @return null
  */
 protected function onTreeRemoved(CategoryInterface $category)
 {
     $users = $this->findUsersBy(array('defaultTree' => $category));
     $trees = $this->container->get('pim_catalog.manager.category')->getTrees();
     $defaultTree = current(array_filter($trees, function ($tree) use($category) {
         return $tree->getCode() !== $category->getCode();
     }));
     foreach ($users as $user) {
         $user->setDefaultTree($defaultTree);
         $this->computeChangeset($user);
     }
 }
Esempio n. 5
0
 function it_normalizes_a_root_category(CategoryInterface $category)
 {
     $category->getCode()->willReturn('foo');
     $category->getParent()->willReturn(null);
     $this->normalize($category, 'json')->shouldReturn(['code' => 'foo']);
 }
 /**
  * Generate url key for category name and code
  * The code is included to make sure the url_key is unique, as required in Prestashop.
  *
  * @param CategoryInterface $category
  * @param string            $localeCode
  *
  * @return string
  */
 protected function generateUrlKey(CategoryInterface $category, $localeCode)
 {
     $code = $category->getCode();
     $label = $this->getCategoryLabel($category, $localeCode);
     $url = Urlizer::urlize($label . '-' . $code);
     return $url;
 }
 /**
  * Get new normalized categories
  * @param CategoryInterface $category
  * @param array             $context
  *
  * @return array
  */
 protected function getNormalizedNewCategory(CategoryInterface $category, array $context)
 {
     $parentCategoryId = $this->categoryMappingManager->getIdFromCategory($category->getParent(), $context['magentoUrl'], $context['categoryMapping']);
     if (null === $parentCategoryId) {
         throw new CategoryNotMappedException(sprintf('An error occured during the root category creation on Magento. The Magento ' . 'connector was unable to find the mapped category "%s (%s)". Remember that you need to map your ' . 'Magento root categories to Akeneo categories. All sub categories of %s will not be exported.', $category->getLabel(), $category->getCode(), $category->getCode()));
     } else {
         return ['magentoCategory' => [(string) $parentCategoryId, ['name' => $this->getCategoryLabel($category, $context['defaultLocale']), 'is_active' => 1, 'include_in_menu' => 1, 'available_sort_by' => 1, 'default_sort_by' => 1], $context['defaultStoreView']], 'pimCategory' => $category];
     }
 }