get the structure of Categories and subcategories?

  • neussal

    3 messages

    Espagne

    I have created a routine to get the root categories by making a GET call to the url: Lien (https)
    with idParent = 0 and showOnlyLeaves = 0, the top 19 categories are obtained correctly, henceforth rootArray.

    If I make the above call using the parameters idParent = 0 and showOnlyLeaves = 1, I get an array with 24029 elements, hereafter itemsArray.

    Case 1:
    I have made a routine that traverses rootArray and provides the id as idParent to a recursive routine which traverses the itemsArray elements stopping each recursive iteration when it reaches the end of the traversal or gets no information.

    I have tested this routine with a simulating the mentioned array and it works correctly, but with the API information it does not.

    Case 2:
    I have created a function to traverse rootArray and call a recursive function which is given as arguments the $id of the element from which I need to get the children,
    in each iteration a call is made using the GET method to the url: Lien (https) and with the arguments idParent = $id and showOnlyLeaves = 0.


    In both cases I only manage to get the root level and the next level but I don't go beyond that.

    I have manually evaluated itemsArray and I find that the information structure to generate the tree of categories and subcategories is broken after the second level.

    How can I fix it?
    Is there an API call to query the data of a category directly using its own ID?
  • Servitel

    448 messages

    Suisse

    I have created a routine to get the root categories by making a GET call to the url: Lien (https)
    with idParent = 0 and showOnlyLeaves = 0, the top 19 categories are obtained correctly, henceforth rootArray.

    If I make the above call using the parameters idParent = 0 and showOnlyLeaves = 1, I get an array with 24029 elements, hereafter itemsArray.

    Case 1:
    I have made a routine that traverses rootArray and provides the id as idParent to a recursive routine which traverses the itemsArray elements stopping each recursive iteration when it reaches the end of the traversal or gets no information.

    I have tested this routine with a simulating the mentioned array and it works correctly, but with the API information it does not.

    Case 2:
    I have created a function to traverse rootArray and call a recursive function which is given as arguments the $id of the element from which I need to get the children,
    in each iteration a call is made using the GET method to the url: Lien (https) and with the arguments idParent = $id and showOnlyLeaves = 0.


    In both cases I only manage to get the root level and the next level but I don't go beyond that.

    I have manually evaluated itemsArray and I find that the information structure to generate the tree of categories and subcategories is broken after the second level.

    How can I fix it?
    Is there an API call to query the data of a category directly using its own ID?
    • Posté le 20 août 2024 à 12:10
    • #1785813
    For retrieve the full tree structure you need to use "idParent" filter
  • neussal

    3 messages

    Espagne

    Hello.

    Thanks for answer early.

    I use the id of each category in the rootArray in the API call in the idParent parameter to get the child categories, I do this using a recursive function which stops when the ID is null or 0.

    Please, could you show me an example?

Rejoignez la communauté des collectionneurs !

S'inscrire Se connecter