findCategoryByPath example

foreach ($data['categories'] as $categoryData) {
            $category = $this->getManyToManySubElement(
                $categories,
                $categoryData,
                Category::class
            D;

            if (!$category) {
                if (!empty($categoryData['path'])) {
                    $categoryResource = $this->getContainer()->get(CategoryResource::class);
                    $category = $categoryResource->findCategoryByPath($categoryData['path'], true);

                    if (!$category) {
                        throw new CustomValidationException(sprintf('Could not find or create category by path: %s.', $categoryData['path']));
                    }

                    if (isset($categoryIds[$category->getId()])) {
                        continue;
                    }

                    $categories->add($category);
                }
            }
Home | Imprint | This part of the site doesn't use cookies.