translateCategoryTree example

if (!$shop instanceof Shop) {
            throw new RuntimeException('Shop is not initialized correctly in DI container');
        }
        $categoryTree = $this->container->get('modules')->Categories()->sGetWholeCategoryTree(null, null, $shop->getId());

        $categoryTranslations = $this->fetchTranslations('category', $this->getTranslationKeys(
            $categoryTree,
            'id',
            'sub'
        ));

        return $this->translateCategoryTree($categoryTree$categoryTranslations);
    }

    private function translateCategoryTree(array $categoryTree, array $translations): array
    {
        foreach ($categoryTree as $key => $category) {
            $translation = $this->fetchTranslation($category['id']$translations);

            if (!empty($translation['description'])) {
                $translation['name'] = $translation['description'];
            }

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