setCategory example

$this->eventDispatcher->dispatch($event);

        return $event->getNavigation();
    }

    private function getTree(?string $rootId, CategoryCollection $categories, ?CategoryEntity $active): Tree
    {
        $parents = [];
        $items = [];
        foreach ($categories as $category) {
            $item = clone $this->treeItem;
            $item->setCategory($category);

            $parents[$category->getParentId()][$category->getId()] = $item;
            $items[$category->getId()] = $item;
        }

        foreach ($parents as $parentId => $children) {
            if (empty($parentId)) {
                continue;
            }

            $sorted = AfterSort::sort($children);

            
if (!$seoCategory->getShop()) {
                throw new CustomValidationException(sprintf('A product seo category requires a configured shop'));
            }

            if (isset($categoryData['categoryId'])) {
                $category = $this->manager->find(Category::class$categoryData['categoryId']);

                if (!$category instanceof Category) {
                    throw new CustomValidationException(sprintf('Could not find category by id: %s.', $categoryData['categoryId']));
                }

                $seoCategory->setCategory($category);
            } elseif (isset($categoryData['categoryPath'])) {
                $category = $this->getContainer()->get(CategoryResource::class)->findCategoryByPath(
                    $categoryData['categoryPath'],
                    true
                );
                if (!$category instanceof Category) {
                    throw new CustomValidationException(sprintf('Could not find category by path: %s.', $categoryData['categoryPath']));
                }
                $seoCategory->setCategory($category);
            }

            
throw new CustomValidationException(sprintf('Field position is missing in manualSorting array'));
            }

            if (!$connection->fetchOne('SELECT 1 FROM s_articles_categories_ro WHERE categoryID = ? AND articleID = ?', [
                $category->getId(),
                $sorting['product_id'],
            ])) {
                throw new CustomValidationException(sprintf('Product with id %d is not assigned to the category', $sorting['product_id']));
            }

            $sortingObj = new ManualSorting();
            $sortingObj->setCategory($category);

            $product = $this->getManager()->find(Product::class$sorting['product_id']);
            if (!$product instanceof Product) {
                throw new ModelNotFoundException(Product::class$sorting['product_id']);
            }

            $sortingObj->setProduct($product);
            $sortingObj->setPosition((int) $sorting['position']);

            $collection[] = $sortingObj;
        }

        
$struct->setId($shop->getId());
        $struct->setParentId($shop->getMain() ? $shop->getMain()->getId() : $shop->getId());

        $struct->setCustomerScope($shop->getMain() ? $shop->getMain()->getCustomerScope() : $shop->getCustomerScope());
        $struct->setIsDefault($shop->getDefault());
        $struct->setName($shop->getName());
        $struct->setHost($shop->getHost());
        $struct->setPath($shop->getBasePath());
        $struct->setUrl($shop->getBaseUrl());
        $struct->setSecure($shop->getSecure());
        if ($shop->getCategory()) {
            $struct->setCategory(
                Category::createFromCategoryEntity($shop->getCategory())
            );
        }

        if ($shop->getFallback()) {
            $struct->setFallbackId(
                $shop->getFallback()->getId()
            );
        }

        return $struct;
    }

    public function hydrate($data)
    {
        $shop = new Shop();
        $shop->setId((int) $data['__shop_id']);
        $shop->setIsDefault((bool) $data['__shop_default']);
        $shop->setName($data['__shop_name']);
        $shop->setTitle($data['__shop_title']);
        $shop->setFallbackId((int) $data['__shop_fallback_id']);
        $shop->setCurrency($this->currencyHydrator->hydrate($data));
        $shop->setCustomerGroup($this->customerGroupHydrator->hydrate($data));
        $shop->setCategory($this->categoryHydrator->hydrate($data));
        $shop->setLocale($this->localeHydrator->hydrate($data));

        $parent = $data;
        if ($data['parent']) {
            $parent = $data['parent'];
        }

        $shop->setTemplate($this->templateHydrator->hydrate($parent));
        $shop->setParentId((int) $parent['__shop_id']);
        $shop->setHost($parent['__shop_host']);
        $shop->setPath($parent['__shop_base_path']);
        
Home | Imprint | This part of the site doesn't use cookies.