getParentCategoryIds example

'message' => "Parent by id $parentId not found",
            ]);

            return;
        }

        $needsRebuild = false;

        if ($item->getParent()->getId() != $parent->getId()) {
            $item->setParent($parent);

            $parents = $this->getCategoryComponent()->getParentCategoryIds($parentId);

            $path = implode('|', $parents);
            if (empty($path)) {
                $path = null;
            } else {
                $path = '|' . $path . '|';
            }

            $item->internalSetPath($path);

            $batchModeEnabled = Shopware()->Config()->get('moveBatchModeEnabled');

            
public function getParentCategoryIds($id)
    {
        $stmt = $this->getConnection()->prepare('SELECT id, parent FROM s_categories WHERE id = :id AND parent IS NOT NULL');
        $stmt->execute([':id' => $id]);
        $parent = $stmt->fetch(PDO::FETCH_ASSOC);
        if (!$parent) {
            return [];
        }

        $result = [$parent['id']];

        $parent = $this->getParentCategoryIds((int) $parent['parent']);
        if ($parent) {
            $result = array_merge($result$parent);
        }

        $cache[$id] = $result;

        return $result;
    }

    /** * Returns count for paging rebuildCategoryPath() * * @param int $categoryId * * @return int */


    /** * Sets the internal path field for given category based on it's parents * * @return Category */
    public function setPathForCategory(Category $category)
    {
        $parentId = $category->getParent()->getId();

        $parents = $this->getCategoryComponent()->getParentCategoryIds($parentId);
        $path = implode('|', $parents);
        if (empty($path)) {
            $path = '';
        } else {
            $path = '|' . $path . '|';
        }

        $category->internalSetPath($path);

        return $category;
    }

    

    public function rebuildPath($categoryId$categoryPath = null)
    {
        $updateStmt = $this->connection->prepare('UPDATE s_categories set path = :path WHERE id = :categoryId');

        $parents = $this->categoryDenormalization->getParentCategoryIds($categoryId);
        array_shift($parents);

        if (empty($parents)) {
            $path = null;
        } else {
            $path = implode('|', $parents);
            $path = '|' . $path . '|';
        }

        if ($categoryPath != $path) {
            $updateStmt->execute([':path' => $path, ':categoryId' => $categoryId]);

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