JSON API - search catalog

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

JSON API - search catalog

Post by Kevin1596 » 06 Jan 2021, 07:01

AIMEOS Laravel 2020.10.*

Thank you for all your great supports,

1) . Currently I am trying to get the catalog list from JSON API, by following this https://aimeos.org/docs/latest/frontend ... categories

This is great if I am using for only 1 level
In my case, I need to get more level of the catalog, the problem is: there will be too many JSON API
if I have:
level 1: 8catalogs
level2: 3 catalogs
that will be 24 JSON API call

there will be greater way to get around this
2) . I am trying to call this API on the Laravel demo

Code: Select all

var url = `https://laravel.demo.aimeos.org/default/jsonapi`; // Base URL from config

var promise = $.ajax( url, {
    method: "OPTIONS",
    dataType: "json"
});

promise.done( function( options ) {
    var args = {};
    var params = {
    'include': 'text,catalog',

    'filter': {
        '&&': [
            {'==': {'catalog.level':  0}
            }
        ]
    }


    };
    console.log(options)
    console.log('end points')
    console.log(options.meta.resources)

    var result = $.ajax({
        method: "GET",
        dataType: "json",
        url: `${options.meta.resources['catalog']}`,
        data: params
    });

    result.done( function( result ) {
        console.log('resource data')
        console.log( result.data );
    });
});
As you will see the result of the response will be all the catalog level with the specified level,
The problem is it does not include the child catalog in the response but only the text.
------------------------------------------------------------------------------------------
I am checking the source code of Json API and found the reason here:

Code: Select all

ext/ai-client-jsonapi/client/jsonapi/templates/catalog/standard.php
Screen Shot 2021-01-06 at 1.54.13 PM.png
Screen Shot 2021-01-06 at 1.54.13 PM.png (180.91 KiB) Viewed 1839 times
- The catalog relationships are manage by the catalog table rather than catalog.list so the line 66 wont execute
- The line 59:
if you call the API with the First way (follow the docs) it is execute.
if you use the second way, (search catalog with level: 0 , include:text, catalog) this will not execute.

Please help me check it, and give me the way to get the Include Child catalogs from the search without using catalog.lists manage relationship

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

Re: JSON API - search catalog

Post by aimeos » 07 Jan 2021, 13:14

If you restrict the categories to level "0" in your filter, only the root node will be returned. Instead, use this to get the root node and all categories one level below:

Code: Select all

var url = `https://laravel.demo.aimeos.org/default/jsonapi`; // Base URL from config

$.ajax( url, {
    method: "OPTIONS",
    dataType: "json"
}).done( function( options ) {
    $.ajax({
        method: "GET",
        dataType: "json",
        url: `${options.meta.resources['catalog']}`,
        data: {'include': 'text,catalog'}
    }).done( function( result ) {
        console.log( result.data );
    });
});
The sub-categories data in the "included" section contains links to retrieve the sub-category and their sub-sub-categories if you use "'include': 'catalog'" again. You only need to fetch the sub-sub-categories on user request, so you need 1-2 requests max. in all cases.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - search catalog

Post by Kevin1596 » 07 Jan 2021, 13:51

The problem in my case is:

I need to pre-fetch all the catalogs in the sub-sub-categrory

example:
level: 0 : 1 catalog
level: 1 : "N" catalog
level: 2: 4 catalog each
------------------------------------
If i call as you I will need to call "N" requests to get all the level 2

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

Re: JSON API - search catalog

Post by aimeos » 08 Jan 2021, 15:59

There may be cases where this a valid requirement provided you have a low number categories (like in your case). We've added a new configuration in the dev-master branch to allow fetching the complete catalog tree now:
https://github.com/aimeos/ai-client-jso ... 0b0dbafc6b
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - search catalog

Post by Kevin1596 » 09 Jan 2021, 16:11

I tried this but it did not work,

How do you config it?

Will this enable when I use filter search catalog, the JSON api will also return the children of found catalogs?

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

Re: JSON API - search catalog

Post by aimeos » 11 Jan 2021, 08:50

Remember, it's only in dev-master branch of the aimeos/ai-client-jsonapi package. You are likely using a ~2020.10 version.

Yes, the whole tree will be returned if you enable this option and use "include=catalog" in your request.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - search catalog

Post by Kevin1596 » 18 Jan 2021, 09:57

yes that's worked,

thank you so much for your help

Post Reply