Пример #1
0
 private function checkDuplicity(Product $product)
 {
     foreach ($product->getCategories() as $category) {
         foreach ($category->getProducts() as $duplicateCandidate) {
             $path = $product->getPath($category);
             if ($duplicateCandidate !== $product && $duplicateCandidate->getPath($category) === $path) {
                 throw new EntityDuplicateException(sprintf('Product with path %s already exists.', $path));
             }
         }
     }
 }
Пример #2
0
 private function addCategoriesControl()
 {
     $categoryIds = iterator_to_array($this->categoryService->getAll());
     $categoryIds = array_map(function (Category $category) {
         return $category->getId();
     }, $categoryIds);
     $control = $this->addCheckboxList('categories', 'Categories', array_flip($categoryIds));
     if ($this->editedProduct !== null) {
         $checkedIds = iterator_to_array($this->editedProduct->getCategories());
         $checkedIds = array_map(function (Category $category) {
             return $category->getId();
         }, $checkedIds);
         $control->setDefaultValue($checkedIds);
     }
 }