Get category tree in TYPO3 context
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Get category tree in TYPO3 context
Hello there,
I try to get the AIMEOS category tree inside of TYPO3 but I become desperate because I don't find any post nor a helping documentation about this.
The only thing I've found was this documentation to get the AIMEOS context inside TYPO3:
https://aimeos.org/docs/latest/typo3/extend/
But then the interesting part is missing.
I try to get the category tree inside a custom MenuProcessor to add the categories to the main menu and I can't believe that I am the first person who tries to do this.
I already have this code snippet to get the base category (or any other category by code/id) but unfortunately I can't get the child categories from here.
Can anybody help me how to get the whole tree in a MenuProcessor?
I am using TYPO3 12.4.20 and aimeos/aimeos-typo3 2023.10.7 in a ddev environment with PHP 8.2
I try to get the AIMEOS category tree inside of TYPO3 but I become desperate because I don't find any post nor a helping documentation about this.
The only thing I've found was this documentation to get the AIMEOS context inside TYPO3:
https://aimeos.org/docs/latest/typo3/extend/
But then the interesting part is missing.
I try to get the category tree inside a custom MenuProcessor to add the categories to the main menu and I can't believe that I am the first person who tries to do this.
I already have this code snippet to get the base category (or any other category by code/id) but unfortunately I can't get the child categories from here.
Code: Select all
$context = \Aimeos\Aimeos\Scheduler\Base::context();
$locale = Base::locale($context);
$context->setLocale($locale);
$manager = \Aimeos\MShop::create($context, 'catalog');
$filter = $manager->filter()->add('catalog.id', '==', '1');
$category = $manager->search($filter);
I am using TYPO3 12.4.20 and aimeos/aimeos-typo3 2023.10.7 in a ddev environment with PHP 8.2
Re: Get category tree in TYPO3 context
You can try using the getTree() method after fetching the base category. Something like this should work:
It will give you the full tree of categories and let you loop through it to make the menu. Hope that helps!
Code: Select all
$context = \Aimeos\Aimeos\Scheduler\Base::context();
$locale = \Aimeos\Base::locale($context);
$context->setLocale($locale);
$manager = \Aimeos\MShop::create($context, 'catalog');
$filter = $manager->filter()->add('catalog.id', '==', '1');
$category = $manager->search($filter);
$tree = $manager->getTree($category->getId()); // Gets all child categories
// Loop through $tree to build your menu
Re: Get category tree in TYPO3 context
To get the category tree, you only need:
Code: Select all
$tree = \Aimeos\MShop::create($context, 'catalog')->getTree();
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Get category tree in TYPO3 context
Thank you so much. I've searched in the code and googled so much and then it's so easy. I have already tried something with a getTree() function but from the Frontend::create method:
But that did not work. When using your code it works and it is that simple as well. Thanks
Code: Select all
\Aimeos\Controller\Frontend::create($context, 'catalog')->getTree()
-
- Posts: 8
- Joined: 07 Mar 2018, 11:33
Re: Get category tree in TYPO3 context
To get the full tree, you can try modifying the $filter part. Instead of filtering by a specific catalog.id, set the filter to grab all categories by removing or adjusting that line. Then use $manager->getTree() to pull the full category structure.