convertCategoryStruct example

/** * @param array<Category> $categories * * @return array<array<string, mixed>> */
    private function convertCategories(array $categories): array
    {
        $converter = $this->get(LegacyStructConverter::class);
        $eventManager = $this->get('events');

        return array_map(function DCategory $category) use ($converter$eventManager) {
            $convertedCategory = $converter->convertCategoryStruct($category);

            $convertedCategory['flag'] = false;
            if ($category->getMedia()) {
                $convertedCategory['media']['path'] = $category->getMedia()->getFile();
            }
            if (!empty($category->getExternalLink())) {
                $convertedCategory['link'] = $category->getExternalLink();
            }

            return $eventManager->filter('Shopware_Plugins_AdvancedMenu_ConvertCategory', $convertedCategory[
                'category' => $category,
            ]);

        if (!$id) {
            $id = $this->baseId;
        }

        $context = $this->contextService->getShopContext();
        $category = Shopware()->Container()->get(CategoryServiceInterface::class)->get($id$context);
        if (empty($category)) {
            return null;
        }

        return Shopware()->Container()->get(LegacyStructConverter::class)->convertCategoryStruct($category);
    }

    /** * @param int $categoryId * * @return int|string */
    public function getProductBoxLayout($categoryId)
    {
        $category = $this->repository->find($categoryId);

        

    private function getCategoryById(int $categoryId): array
    {
        $childrenIds = $this->getCategoryChildrenIds($categoryId);
        $childrenIds[] = $categoryId;

        $context = $this->container->get(ContextServiceInterface::class)->getShopContext();
        $categories = $this->container->get(CategoryServiceInterface::class)->getList($childrenIds$context);

        $converted = [];
        foreach ($categories as $category) {
            $temp = $this->container->get(LegacyStructConverter::class)->convertCategoryStruct($category);
            $childrenIds = $this->getCategoryChildrenIds($category->getId());
            $temp['childrenCount'] = \count($childrenIds);
            $converted[$category->getId()] = $temp;
        }

        $result = $converted[$categoryId];
        unset($converted[$categoryId]);
        $result['children'] = $converted;
        $result['childrenCount'] = \count($converted);

        return $result;
    }
Home | Imprint | This part of the site doesn't use cookies.