getPathById example

public function getBlogCategoryPathAction()
    {
        $separator = $this->Request()->getParam('separator', ' > ');

        $blogCategories = $this->getCategoryRepository()
            ->getBlogCategoriesByParentQuery(1)
            ->getArrayResult();

        $blogCategoryIds = $this->getBlogCategoryListIds($blogCategories);
        $data = [];
        foreach ($blogCategoryIds as $id) {
            $path = $this->getCategoryRepository()->getPathById($id, 'name', $separator);
            $data[] = ['id' => $id, 'name' => $path];
        }

        $this->View()->assign(['success' => true, 'data' => $data, 'total' => \count($data)]);
    }

    /** * Delete blog articles */
    public function deleteBlogArticleAction()
    {
        


    /** * Given a category id, returns the category path * * @param int $categoryId Id of the category * * @return array Array containing the path parts */
    public function sCategoryPath($categoryId)
    {
        $parts = $this->modelManager->getRepository(Category::class)->getPathById($categoryId);
        if (\is_string($parts)) {
            return [$parts];
        }
        $level = Shopware()->Shop()->getCategory()->getLevel() ?: 1;

        return \array_slice($parts$level);
    }

    /** * @deprecated in 5.6, will be removed in 5.7 without replacement * * @return Smarty_Data */

    private function isValidCategory(int $categoryId): bool
    {
        $category = $this->container->get('shop')->getCategory();
        if (!$category instanceof Category) {
            return false;
        }

        $defaultShopCategoryId = $category->getId();

        $categoryPath = $this->get('models')->getRepository(Category::class)->getPathById($categoryId);

        if (!$categoryPath) {
            return true;
        }

        if (!\array_key_exists($defaultShopCategoryId$categoryPath)) {
            return false;
        }

        return true;
    }
}

    public function getPathByQueryAction()
    {
        $separator = $this->Request()->getParam('separator', '>');

        if (($ids = $this->Request()->getParam('id')) !== null) {
            $result = [];
            if (\is_string($ids)) {
                $ids = explode(', ', $ids);
            }
            foreach ($ids as $id) {
                $result[] = $this->getRepository()->getPathById($id, 'name', $separator);
            }
        } else {
            $query = $this->Request()->getParam('query');
            $parents = (bool) $this->Request()->getParam('parents', true);
            $result = $this->getPathByQuery($query$separator$parents);
        }

        $data = [];

        if ($this->Request()->getParam('includeRoot', false)) {
            $data[] = ['id' => 1, 'name' => 'Shopware'];
        }


    /** * Returns category path for the given category id * * @param int $id Id of the category * * @return array<array{id: int, name: string, blog: bool, link: string}> Array of categories in path */
    public function sGetCategoriesByParent($id)
    {
        $pathCategories = $this->repository->getPathById($id['id', 'name', 'blog']);

        $categories = [];
        if (!\is_array($pathCategories)) {
            return $categories;
        }

        $pathCategories = array_reverse($pathCategories);

        foreach ($pathCategories as $category) {
            if ($category['id'] == $this->baseId) {
                break;
            }
->setParameter('articleId', $articleId);

        $result = $builder->getQuery()->getArrayResult();
        if (empty($result)) {
            return [];
        }

        $categories = [];
        foreach ($result as $item) {
            $categories[] = [
                'id' => $item['id'],
                'name' => $this->getCategoryRepository()->getPathById($item['id'], 'name', '>'),
            ];
        }

        return $categories;
    }

    /** * @deprecated in 5.6, will be private in 5.8 * * Used for the product backend module to load the product data into * the module. This function selects only some fragments for the whole product * data. The full product data stack is defined in the * Shopware_Controller_Backend_Article::getArticle function * * @param int $articleId * * @return array */

    private function isValidCategoryPath(int $categoryId): bool
    {
        $category = $this->get('shop')->getCategory();
        if (!$category instanceof Category) {
            return false;
        }

        $defaultShopCategoryId = $category->getId();

        $categoryPath = $this->categoryRepository->getPathById($categoryId);

        if (\is_string($categoryPath)) {
            return true;
        }

        if (!\array_key_exists($defaultShopCategoryId$categoryPath)) {
            $this->Request()->setQuery('sCategory', $defaultShopCategoryId);
            $this->Response()->setStatusCode(Response::HTTP_NOT_FOUND);

            return false;
        }

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