function it_updates_a_not_translatable_category($categoryRepository, CategoryInterface $category, CategoryInterface $categoryMaster, CategoryTranslation $translatable)
 {
     $categoryRepository->findOneByIdentifier('master')->willReturn($categoryMaster);
     $category->setCode('mycode')->shouldBeCalled();
     $category->setParent($categoryMaster)->shouldBeCalled();
     $category->getId()->willReturn(null);
     $values = ['code' => 'mycode', 'parent' => 'master'];
     $this->update($category, $values, []);
 }
 function it_updates_a_category($categoryRepository, CategoryInterface $category, CategoryInterface $categoryMaster, CategoryTranslation $translatable)
 {
     $categoryRepository->findOneByIdentifier('master')->willReturn($categoryMaster);
     $category->getTranslation()->willReturn($translatable);
     $translatable->setLabel('Ma superbe catégorie')->shouldBeCalled();
     $category->setCode('mycode')->shouldBeCalled();
     $category->setParent($categoryMaster)->shouldBeCalled();
     $category->setLocale('fr_FR')->shouldBeCalled();
     $category->getId()->willReturn(null);
     $values = ['code' => 'mycode', 'parent' => 'master', 'labels' => ['fr_FR' => 'Ma superbe catégorie']];
     $this->update($category, $values, []);
 }
Пример #3
0
 /**
  * @param CategoryInterface $category
  * @param string            $field
  * @param mixed             $data
  */
 protected function setData(CategoryInterface $category, $field, $data)
 {
     if ('labels' === $field) {
         foreach ($data as $localeCode => $label) {
             $category->setLocale($localeCode);
         }
     } elseif ('parent' === $field) {
         $categoryParent = $this->findParent($data);
         if (null !== $categoryParent) {
             $category->setParent($categoryParent);
         } else {
             throw new \InvalidArgumentException(sprintf('The parent category "%s" does not exist', $data));
         }
     } else {
         $this->accessor->setValue($category, $field, $data);
     }
 }
 /**
  * @param CategoryInterface $category
  * @param string            $field
  * @param mixed             $data
  */
 protected function setData(CategoryInterface $category, $field, $data)
 {
     // TODO: Locales should be managed in a dedicated implementation of this updater
     if ('labels' === $field && $category instanceof TranslatableInterface) {
         foreach ($data as $localeCode => $label) {
             $category->setLocale($localeCode);
             $translation = $category->getTranslation();
             $translation->setLabel($label);
         }
     } elseif ('parent' === $field) {
         $categoryParent = $this->findParent($data);
         if (null !== $categoryParent) {
             $category->setParent($categoryParent);
         } else {
             throw new \InvalidArgumentException(sprintf('The parent category "%s" does not exist', $data));
         }
     } else {
         $this->accessor->setValue($category, $field, $data);
     }
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function addChild(CategoryInterface $child)
 {
     $child->setParent($this);
     $this->children[] = $child;
     return $this;
 }