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, []); }
/** * @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); } }