Category example


    public function saveDetail()
    {
        $params = $this->Request()->getParams();
        $categoryId = (int) ($params['id'] ?? 0);

        $repo = $this->em->getRepository(Category::class);

        if (empty($categoryId)) {
            $categoryModel = new Category();
            $this->em->persist($categoryModel);

            // Find parent for newly created category             $params['parentId'] = isset($params['parentId']) && is_numeric($params['parentId']) ? (int) $params['parentId'] : 1;
            /** @var Category $parentCategory */
            $parentCategory = $repo->find($params['parentId']);
            $categoryModel->setParent($parentCategory);

            // If Leaf-Category gets child category move all assignments to new child category             if ($parentCategory->getChildren()->count() === 0 && $parentCategory->getArticles()->count() > 0) {
                /** @var Article $product */
                
 {
        $this->attributeHydrator = $attributeHydrator;
        $this->mediaHydrator = $mediaHydrator;
        $this->productStreamHydrator = $productStreamHydrator;
    }

    /** * @return Category */
    public function hydrate(array $data)
    {
        $category = new Category();
        $translation = $this->getTranslation($data, '__category');
        $data = array_merge($data$translation);

        $this->assignCategoryData($category$data);

        if ($data['__media_id']) {
            $category->setMedia(
                $this->mediaHydrator->hydrate($data)
            );
        }

        
Home | Imprint | This part of the site doesn't use cookies.