Capybara with custom backend; no subcategories

The regular theme works fine, but capybara doesn’t show subcategories:

(Bekijk alles points to undefined)

The requests I’m getting are:

{"bool":{"filter":{"bool":{"must":[{"terms":{"level":[2]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"url_path":["sw.js"]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"url_path":["women/tops-women/jackets-women/jackets-23"]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"level":[2]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"url_path":["men/tops-men/tees-men/tees-16"]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"url_path":["women/tops-women/tees-women/tees-25"]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"level":[2]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"level":[2]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"level":[2]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"url_path":["gear/gear-3"]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"level":[2]}},{"terms":{"is_active":[true]}}]}}}}
{"bool":{"filter":{"bool":{"must":[{"terms":{"level":[2]}},{"terms":{"is_active":[true]}}]}}}}

For the level[2] request I’m returning:

{
   "took":0,
   "timed_out":false,
   "_shards":{
      "total":1,
      "successful":1,
      "skipped":0,
      "failed":0
   },
   "hits":{
      "total":{
         "value":0,
         "relation":"eq"
      },
      "hits":[
         {
            "_source":{
               "parent_id":null,
               "parent_ids":[

               ],
               "name":"New",
               "url_key":"new",
               "path":"new",
               "slug":"new",
               "url_path":"new",
               "is_active":true,
               "include_in_menu":true,
               "is_anchor":null,
               "children_count":"3",
               "position":0,
               "level":2,
               "product_count":null,
               "children_data":[
                  {
                     "parent_id":"fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                     "parent_ids":[
                        "fe9d564d-f345-40bd-ab50-24e1f48e89f1"
                     ],
                     "name":"Men",
                     "url_key":"new-men",
                     "path":"new-men",
                     "slug":"new-men",
                     "url_path":"new-men",
                     "is_active":true,
                     "include_in_menu":true,
                     "is_anchor":null,
                     "children_count":"4",
                     "position":0,
                     "level":3,
                     "product_count":null,
                     "children_data":[
                        {
                           "parent_id":"52f1bf1b-3689-4a3a-9b77-1d42ac34413a",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "52f1bf1b-3689-4a3a-9b77-1d42ac34413a"
                           ],
                           "name":"Clothing8",
                           "url_key":"new-men-clothing",
                           "path":"new-men-clothing",
                           "slug":"new-men-clothing",
                           "url_path":"new-men-clothing",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"2b70a42f-898e-481a-8a47-9a59a24265af",
   
                        },
                        {
                           "parent_id":"52f1bf1b-3689-4a3a-9b77-1d42ac34413a",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "52f1bf1b-3689-4a3a-9b77-1d42ac34413a"
                           ],
                           "name":"Shoes1",
                           "url_key":"new-men-shoes",
                           "path":"new-men-shoes",
                           "slug":"new-men-shoes",
                           "url_path":"new-men-shoes",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"33e41242-197f-41f7-aa72-e37aac709309",
        
                        },
                        {
                           "parent_id":"52f1bf1b-3689-4a3a-9b77-1d42ac34413a",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "52f1bf1b-3689-4a3a-9b77-1d42ac34413a"
                           ],
                           "name":"Looks",
                           "url_key":"new-men-looks",
                           "path":"new-men-looks",
                           "slug":"new-men-looks",
                           "url_path":"new-men-looks",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"8ffaca22-dede-4240-99ce-8bf2040eea1a",

                        },
                        {
                           "parent_id":"52f1bf1b-3689-4a3a-9b77-1d42ac34413a",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "52f1bf1b-3689-4a3a-9b77-1d42ac34413a"
                           ],
                           "name":"Bags1",
                           "url_key":"new-men-bags",
                           "path":"new-men-bags",
                           "slug":"new-men-bags",
                           "url_path":"new-men-bags",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"106e2b04-2a6b-43e9-aa4f-b1ed1687c32e",

                        }
                     ],
                     "tsk":0,
                     "id":"52f1bf1b-3689-4a3a-9b77-1d42ac34413a",
                     "type":null,
                     "created_at":null,
                     "updated_at":null,
                     "foreign_id":null
                  },
                  {
                     "parent_id":"fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                     "parent_ids":[
                        "fe9d564d-f345-40bd-ab50-24e1f48e89f1"
                     ],
                     "name":"Women",
                     "url_key":"new-women",
                     "path":"new-women",
                     "slug":"new-women",
                     "url_path":"new-women",
                     "is_active":true,
                     "include_in_menu":true,
                     "is_anchor":null,
                     "children_count":"4",
                     "position":0,
                     "level":3,
                     "product_count":null,
                     "children_data":[
                        {
                           "parent_id":"9b3fe690-ab1c-47a6-ac23-aad1c612bac1",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "9b3fe690-ab1c-47a6-ac23-aad1c612bac1"
                           ],
                           "name":"Looks2",
                           "url_key":"new-women-looks",
                           "path":"new-women-looks",
                           "slug":"new-women-looks",
                           "url_path":"new-women-looks",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"8b0fa9a7-2917-4534-9463-53c5e8dbb021",
                           "type":null,
                           "created_at":null,
                           "updated_at":null,
                           "foreign_id":null
                        },
                        {
                           "parent_id":"9b3fe690-ab1c-47a6-ac23-aad1c612bac1",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "9b3fe690-ab1c-47a6-ac23-aad1c612bac1"
                           ],
                           "name":"Bags1",
                           "url_key":"new-women-bags",
                           "path":"new-women-bags",
                           "slug":"new-women-bags",
                           "url_path":"new-women-bags",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"475c8532-ef60-4470-97e3-7c68eb4c9061",
                           "type":null,
                           "created_at":null,
                           "updated_at":null,
                           "foreign_id":null
                        },
                        {
                           "parent_id":"9b3fe690-ab1c-47a6-ac23-aad1c612bac1",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "9b3fe690-ab1c-47a6-ac23-aad1c612bac1"
                           ],
                           "name":"Clothing6",
                           "url_key":"new-women-clothing",
                           "path":"new-women-clothing",
                           "slug":"new-women-clothing",
                           "url_path":"new-women-clothing",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"2e40cdaa-1c67-425a-9326-f507611cab3b",
                           "type":null,
                           "created_at":null,
                           "updated_at":null,
                           "foreign_id":null
                        },
                        {
                           "parent_id":"9b3fe690-ab1c-47a6-ac23-aad1c612bac1",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "9b3fe690-ab1c-47a6-ac23-aad1c612bac1"
                           ],
                           "name":"Shoes4",
                           "url_key":"new-women-shoes",
                           "path":"new-women-shoes",
                           "slug":"new-women-shoes",
                           "url_path":"new-women-shoes",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"34f2b1ed-ba12-4752-a437-649d032ef4a8",
                           "type":null,
                           "created_at":null,
                           "updated_at":null,
                           "foreign_id":null
                        }
                     ],
                     "tsk":0,
                     "id":"9b3fe690-ab1c-47a6-ac23-aad1c612bac1",
                     "type":null,
                     "created_at":null,
                     "updated_at":null,
                     "foreign_id":null
                  },
                  {
                     "parent_id":"fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                     "parent_ids":[
                        "fe9d564d-f345-40bd-ab50-24e1f48e89f1"
                     ],
                     "name":"Special",
                     "url_key":"new-special",
                     "path":"new-special",
                     "slug":"new-special",
                     "url_path":"new-special",
                     "is_active":true,
                     "include_in_menu":true,
                     "is_anchor":null,
                     "children_count":"2",
                     "position":0,
                     "level":3,
                     "product_count":null,
                     "children_data":[
                        {
                           "parent_id":"2e469420-57fc-469f-bc8e-f72f89c8d3db",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "2e469420-57fc-469f-bc8e-f72f89c8d3db"
                           ],
                           "name":"Fall in love",
                           "url_key":"new-special-fall-in-love",
                           "path":"new-special-fall-in-love",
                           "slug":"new-special-fall-in-love",
                           "url_path":"new-special-fall-in-love",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"3b667151-0737-4252-a5dd-f30a0b34af92",
                           "type":null,
                           "created_at":null,
                           "updated_at":null,
                           "foreign_id":null
                        },
                        {
                           "parent_id":"2e469420-57fc-469f-bc8e-f72f89c8d3db",
                           "parent_ids":[
                              "fe9d564d-f345-40bd-ab50-24e1f48e89f1",
                              "2e469420-57fc-469f-bc8e-f72f89c8d3db"
                           ],
                           "name":"Just go",
                           "url_key":"new-special-just-go",
                           "path":"new-special-just-go",
                           "slug":"new-special-just-go",
                           "url_path":"new-special-just-go",
                           "is_active":true,
                           "include_in_menu":true,
                           "is_anchor":null,
                           "children_count":"0",
                           "position":0,
                           "level":4,
                           "product_count":null,
                           "children_data":[

                           ],
                           "tsk":0,
                           "id":"fb00236c-0aaa-403b-b36e-19ae217c0dd0",

                        }
                     ],
                     "tsk":0,
                     "id":"2e469420-57fc-469f-bc8e-f72f89c8d3db",

                  }
               ],
               "tsk":0,
               "id":"fe9d564d-f345-40bd-ab50-24e1f48e89f1",

            },
            "_index":"vue_storefront_catalog_category",
            "_type":"_doc",
            "_score":1,
            "_id":"fe9d564d-f345-40bd-ab50-24e1f48e89f1"
         }
      ]
   },
   "aggregations":null
}

(Data only has first category due to forum post size limits)

My question is: What do I need to do to make the navigation working properly?

@qiqqq can you please help on that one?

@carlokok I checked returning data, and everything looks good, I don’t see any missing property or something else.

As I see on the screenshot, the submenu is created (there is “Beklijk alle”) link), but there are missing categories data. I suppose, the problem is in categories computed property in this component:

/components/molecules/m-menu.vue

In this property, categories in the menu are searched in whole categories data, and the problem is probably there.

Do you have any environment to see the page live?

Unfortunately, not yet. We’re working on that, but I’m not sure when yet.

re m-menu.vue, yes that’s what I gathered:

categories () {
      return this.categoriesIds
        .map(({ id, children_data: childrenData = [] }) => {
          const subCategories = childrenData
            .map(subCategory => prepareCategoryMenuItem(
              this.getCategories.find(category => category.id === subCategory.id)
            ))
            .filter(Boolean)
            .sort((a, b) => a.position - b.position)

          const category = this.getCategories.find(category => category.id === id)
          const viewAllMenuItem = prepareCategoryMenuItem({
            ...category,
            name: this.$t('View all'),
            position: 0
          });

          return {
            ...prepareCategoryMenuItem(category),
            items: [viewAllMenuItem, ...subCategories]
          };
        })
        .sort((a, b) => a.position - b.position);
    },

I got as far as debugging that.

.getCategories has the 5 root categories (“new”, “woman”, “accessories”, “me”, sale") but none of the others. I don’t know what’s supposed to pull in the child categories, as the only relevant request I see is a level: [2] request, which should only return the root ones?

Ok, I know where the problem is. You have enabled dynamic prefetching for categories. That’s means, on first page load, only root categories are loading, and the next levels are dynamically prefetched when you go through the site.

Add this to your config/local.json file (or change in config/default.json if you are not using local config):

  "entities": {
    "category": {
      "categoriesDynamicPrefetch": false
    }
  }

This should help

1 Like