How to get all categories (for a nav menu)?

How to configure and adapt Aimeos based shops as developer
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!
rowild

How to get all categories (for a nav menu)?

Post by rowild » 19 Feb 2023, 22:06

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.)

User avatar
aimeos
Administrator
Posts: 7871
Joined: 01 Jan 1970, 00:00

Re: How to get all categories (for a nav menu)?

Post by aimeos » 21 Feb 2023, 08:22

rowild wrote: 19 Feb 2023, 22:06 Using the JsonAPI, how can I actually retrieve the COMPLETE catalog tree? Categories are needed to build a navigational 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
rowild wrote: 19 Feb 2023, 22:06 Is my approach wrong when I think of categories as menu entries? How would you suggest to go about this problem?
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, Image give us a star

rowild

Re: How to get all categories (for a nav menu)?

Post by rowild » 21 Feb 2023, 11:17

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:

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"
Is that normal? The documentation shows "nice" links in the resource section of the response data:
https://aimeos.org/docs/latest/frontend ... i/catalog/
Last edited by rowild on 22 Feb 2023, 09:12, edited 1 time in total.

rowild

Re: How to get all categories (for a nav menu)?

Post by rowild » 21 Feb 2023, 12:27

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.

User avatar
aimeos
Administrator
Posts: 7871
Joined: 01 Jan 1970, 00:00

Re: How to get all categories (for a nav menu)?

Post by aimeos » 22 Feb 2023, 16:56

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:

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, Image give us a star

rowild

Re: How to get all categories (for a nav menu)?

Post by rowild » 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?

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.

User avatar
aimeos
Administrator
Posts: 7871
Joined: 01 Jan 1970, 00:00

Re: How to get all categories (for a nav menu)?

Post by aimeos » 26 Feb 2023, 09:30

rowild 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?
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 links
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: How to get all categories (for a nav menu)?

Post by rowild » 27 Feb 2023, 11:35

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?

Post Reply