How to get all categories (for a nav menu)?
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
How to get all categories (for a nav menu)?
Me again!
Using the JsonAPI, how can I actually retrieve the COMPLETE catalog tree? Categories are needed to build a navigational menu.
Is my approach wrong when I think of categories as menu entries? How would you suggest to go about this problem?
(BTW: I use TYPO3 11 with Aimeos 22.10 on a php 8.1 system.)
Using the JsonAPI, how can I actually retrieve the COMPLETE catalog tree? Categories are needed to build a navigational menu.
Is my approach wrong when I think of categories as menu entries? How would you suggest to go about this problem?
(BTW: I use TYPO3 11 with Aimeos 22.10 on a php 8.1 system.)
Re: How to get all categories (for a nav menu)?
Add "&include=catalog" to your JSON API URL for the "catalog" resource (or &ai[include]=catalog for TYPO3).
To get the whole tree, you have to add this setting to your configuration:
https://aimeos.org/docs/2022.x/config/c ... alog/#deep
Categories are almost always used for menu entries so this is totally OK.
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: How to get all categories (for a nav menu)?
Thank you!
I use a Aimeos Distribution setup (TYPO3 11.5, Aimeos 22.10) on a local ddev with php 8.1. I do not get "nice" urls, at least not, what aimeos adds under "routeEnhancers". So retrieving the URLs via "curl -X OPTIONS" gives me something like this:
Is that normal? The documentation shows "nice" links in the resource section of the response data:
https://aimeos.org/docs/latest/frontend ... i/catalog/
I use a Aimeos Distribution setup (TYPO3 11.5, Aimeos 22.10) on a local ddev with php 8.1. I do not get "nice" urls, at least not, what aimeos adds under "routeEnhancers". So retrieving the URLs via "curl -X OPTIONS" gives me something like this:
Code: Select all
"resources": {
"attribute":"https:\/\/catalog.brass-trainer-be.ddev.site\/jsonapiai%5Baction%5D=options&ai%5Bcontroller%5D=Jsonapi&ai%5Bresource%5D=attribute",
"basket":"https:\/\/catalog.brass-trainer-be.ddev.site\/jsonapi?ai%5Baction%5D=options&ai%5Bcontroller%5D=Jsonapi&ai%5Bresource%5D=basket",
"catalog":"https:\/\/catalog.brass-trainer-be.ddev.site\/jsonapi?ai%5Baction%5D=options&ai%5Bcontroller%5D=Jsonapi&ai%5Bresource%5D=catalog"
https://aimeos.org/docs/latest/frontend ... i/catalog/
Last edited by rowild on 22 Feb 2023, 09:12, edited 1 time in total.
Re: How to get all categories (for a nav menu)?
I just tried it and it seems to be working. But - the json response delivers all the categories on the same level, meaning: the nesting is not mirrored in the json structure. Why?
If that is normal, what would the JS look like to create a nested tree? Checking for "hasParent" seems a rather unperformant way to solve this.
If that is normal, what would the JS look like to create a nested tree? Checking for "hasParent" seems a rather unperformant way to solve this.
Re: How to get all categories (for a nav menu)?
The resource URLs are normal and you should use the JS code described here to use that URLs and add own parameters:
https://aimeos.org/docs/latest/frontend ... parameters
The downside of the JSON:API spec is that it's optimized for de-duplication of included data, not for tree structures. Currently, you have to rebuild the tree from the relationship structure included in the "data" section and in each catalog item in the "included" section.
Meanwhile, we think about a non-conforming extension of JSON:API specs to skip the "included" section and place the data directly into the "relationship" entries when a header like this is passed:
https://aimeos.org/docs/latest/frontend ... parameters
The downside of the JSON:API spec is that it's optimized for de-duplication of included data, not for tree structures. Currently, you have to rebuild the tree from the relationship structure included in the "data" section and in each catalog item in the "included" section.
Meanwhile, we think about a non-conforming extension of JSON:API specs to skip the "included" section and place the data directly into the "relationship" entries when a header like this is passed:
Code: Select all
Accept: application/vnd.api+json;ext="https://aimeos.org/docs/latest/frontend/jsonapi/nested"
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: How to get all categories (for a nav menu)?
So the urls in the resource section of the returned JSON does NOT contain "human readable" urls???
But the documentation clearly shows that this should be the case:
https://aimeos.org/docs/latest/frontend ... -meta-data
I am very confused... Is there maybe a difference in behaviour between Laravel and TYPO3?
UPDATE
I just installed a Laravel Aimeos instance, and there curl DOES return nice urls:
{
"meta": {
"prefix": null,
"content-baseurl": ""
, "csrf": {
"name": "_token",
"value": "PZsrnCjzMqxNGEhNNTUnHAg9MYdepkPo85M9cuZa"
}
, "locale": {"locale.id":"1","pos":"0","site_id":"1","locale.currencyid":"EUR","locale.languageid":"en","locale.position":0,"locale.sitecode":"default","locale.siteid":"1.","locale.status":1}
, "resources": {"attribute":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/attribute","basket":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/basket","catalog":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/catalog","customer":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/customer","locale":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/locale","order":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/order","product":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/product","review":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/review","site":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/site","service":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/service","stock":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/stock","supplier":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/supplier"}
}
}
So I do not understand what you mean when you say "The links are ok", because in TYPO3 they are clearly not. And having installed 6, 7 instances makes me believe the error is not on my behalf. Would you please mind to take a look in your TYPO3 version of aimeos? I'd be happy to provide you access to my all-inkl server.
But the documentation clearly shows that this should be the case:
https://aimeos.org/docs/latest/frontend ... -meta-data
I am very confused... Is there maybe a difference in behaviour between Laravel and TYPO3?
UPDATE
I just installed a Laravel Aimeos instance, and there curl DOES return nice urls:
{
"meta": {
"prefix": null,
"content-baseurl": ""
, "csrf": {
"name": "_token",
"value": "PZsrnCjzMqxNGEhNNTUnHAg9MYdepkPo85M9cuZa"
}
, "locale": {"locale.id":"1","pos":"0","site_id":"1","locale.currencyid":"EUR","locale.languageid":"en","locale.position":0,"locale.sitecode":"default","locale.siteid":"1.","locale.status":1}
, "resources": {"attribute":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/attribute","basket":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/basket","catalog":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/catalog","customer":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/customer","locale":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/locale","order":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/order","product":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/product","review":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/review","site":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/site","service":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/service","stock":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/stock","supplier":"https:\/\/aimeos-laravel.ddev.site\/jsonapi\/supplier"}
}
}
So I do not understand what you mean when you say "The links are ok", because in TYPO3 they are clearly not. And having installed 6, 7 instances makes me believe the error is not on my behalf. Would you please mind to take a look in your TYPO3 version of aimeos? I'd be happy to provide you access to my all-inkl server.
Re: How to get all categories (for a nav menu)?
The docs contain URLs from Laravel which are nicer than the one for TYPO3. Add a route for the JSON API like described here if you want to get similar routes: OPTIONS return has no linksrowild wrote: ↑23 Feb 2023, 07:53 So the urls in the resource section of the returned JSON does NOT contain "human readable" urls???
But the documentation clearly shows that this should be the case:
https://aimeos.org/docs/latest/frontend ... -meta-data
I am very confused... Is there maybe a difference in behaviour between Laravel and TYPO3?
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: How to get all categories (for a nav menu)?
As written in the other post: no, the additional route does not solve the problem, neither within ddev not on all-inkl.
Did you try with ddev at least?
Did you try with ddev at least?