Dynamic data Category

Hello!

First of all i want to say thanks for this awesome opensource project!
Currently we are building an API integration for Odoo (Will be opensource on release).
Now my question is everything about dynamic data such as

  • product_count
  • children_data
  • children_count

etc…

Is there a way to calculate this data based on the given available data?
If i import categories with a parent_id and products with a category_id, is there a way after the import to reindex those fields without manually doing so?

Currently those fields are generated from the api integration but it would be great if there is a way to just import all the basic information of categories and products and have vue storefront fill in the missing fields.

Greetings
Rob Conings
CompactCode

Or is it so that you need to nest the categories and do not need to include them yourself? So it is a tree that you give to Elasticsearch?

Hi! Please check the magento native indexer which is updating Elastic on-deman changes: https://github.com/DivanteLtd/magento2-vsbridge-indexer.

If You’d like to have the product_count fields dynamic take a look at the recet vue-storefront-api feature of extending the API results with dynamically injected data (so You can read these fields directly from the API and inject the data into results): https://github.com/DivanteLtd/vue-storefront-api/pull/270

Thanks for your response!

The git is a Magento module. We are specialized in Magento work and i understand that you can adjust any platform to deliver the correct data to vue storefront. But i want this integration to just be plug and play for an Odoo instance without adjusting Odoo itself.

I am not quite sure of the pull reference. Is this adjusting the search results from vue-storefront to vue-storefront-api? It is not adjusting the actual data within elasticsearch?

1 Like

I have populated the categories with the following data

{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":5,"max_score":1,"hits":[{"_index":"vue_storefront_catalog_1560337981","_type":"category","_id":"9","_score":1,"_source":{"is_active":true,"level":2,"children_data":[],"product_count":200,"children_count":0,"id":9,"name":"New","parent_id":null,"child_id":[],"position":0,"url_key":"new"}},{"_index":"vue_storefront_catalog_1560337981","_type":"category","_id":"10","_score":1,"_source":{"is_active":true,"level":2,"children_data":[],"product_count":200,"children_count":0,"id":10,"name":"Best Seller","parent_id":null,"child_id":[],"position":10,"url_key":"best-seller"}},{"_index":"vue_storefront_catalog_1560337981","_type":"category","_id":"6","_score":1,"_source":{"is_active":true,"level":2,"children_data":[{"is_active":true,"level":3,"children_data":[{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":8,"name":"MORE AWESOME","parent_id":7,"child_id":[],"position":0,"url_key":"more-awesome"},{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":11,"name":"Awesome sub sub","parent_id":7,"child_id":[],"position":0,"url_key":"awesome-sub-sub"}],"product_count":200,"children_count":2,"id":7,"name":"Awesome sub","parent_id":6,"child_id":[11,8],"position":0,"url_key":"awesome-sub"}],"product_count":200,"children_count":1,"id":6,"name":"Awesome","parent_id":null,"child_id":[7],"position":0,"url_key":"awesome"}},{"_index":"vue_storefront_catalog_1560337981","_type":"category","_id":"1","_score":1,"_source":{"is_active":true,"level":2,"children_data":[{"is_active":true,"level":3,"children_data":[],"product_count":200,"children_count":0,"id":5,"name":"Just another one","parent_id":1,"child_id":[],"position":0,"url_key":"just-another-one"},{"is_active":true,"level":3,"children_data":[{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":4,"name":"Another sub","parent_id":2,"child_id":[],"position":0,"url_key":"another-sub"}],"product_count":200,"children_count":1,"id":2,"name":"Testing Sub","parent_id":1,"child_id":[4],"position":0,"url_key":"testing-sub"}],"product_count":200,"children_count":2,"id":1,"name":"Shop Testing","parent_id":null,"child_id":[5,2],"position":0,"url_key":"shop-testing"}},{"_index":"vue_storefront_catalog_1560337981","_type":"category","_id":"3","_score":1,"_source":{"is_active":true,"level":2,"children_data":[],"product_count":200,"children_count":0,"id":3,"name":"Shopping test 2","parent_id":null,"child_id":[],"position":0,"url_key":"shopping-test-2"}}]}}

Note that i start with level 2 categories and use their ‘children-data’ to fill in the subcategories. However now the menu does not show them anymore when you go to the subcategory. Do i need to define them as a child and ‘normal’ category?

So i have them synced now as a separate category and as a child. That seems to work. However there is still data missing apparently to get the link_route of the breadcrumbs and some categories do not open when you click on them

{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":12,"max_score":1,"hits":[{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"10","_score":1,"_source":{"is_active":true,"level":2,"children_data":[],"product_count":200,"children_count":0,"id":10,"name":"Best Seller","parent_id":null,"child_id":[],"position":10,"url_key":"best-seller"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"9","_score":1,"_source":{"is_active":true,"level":2,"children_data":[],"product_count":200,"children_count":0,"id":9,"name":"New","parent_id":null,"child_id":[],"position":9,"url_key":"new"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"5","_score":1,"_source":{"is_active":true,"level":3,"children_data":[],"product_count":200,"children_count":0,"id":5,"name":"Just another one","parent_id":1,"child_id":[],"position":0,"url_key":"just-another-one"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"12","_score":1,"_source":{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":12,"name":"Awesome sub sub 2","parent_id":7,"child_id":[],"position":0,"url_key":"awesome-sub-sub-2"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"8","_score":1,"_source":{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":8,"name":"MORE AWESOME","parent_id":7,"child_id":[],"position":1,"url_key":"more-awesome"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"2","_score":1,"_source":{"is_active":true,"level":3,"children_data":[{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":4,"name":"Another sub","parent_id":2,"child_id":[],"position":0,"url_key":"another-sub"}],"product_count":200,"children_count":1,"id":2,"name":"Testing Sub","parent_id":1,"child_id":[4],"position":0,"url_key":"testing-sub"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"6","_score":1,"_source":{"is_active":true,"level":2,"children_data":[{"is_active":true,"level":3,"children_data":[{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":11,"name":"Awesome sub sub","parent_id":7,"child_id":[],"position":0,"url_key":"awesome-sub-sub"},{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":12,"name":"Awesome sub sub 2","parent_id":7,"child_id":[],"position":0,"url_key":"awesome-sub-sub-2"},{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":8,"name":"MORE AWESOME","parent_id":7,"child_id":[],"position":1,"url_key":"more-awesome"}],"product_count":200,"children_count":3,"id":7,"name":"Awesome sub","parent_id":6,"child_id":[11,12,8],"position":0,"url_key":"awesome-sub"}],"product_count":200,"children_count":1,"id":6,"name":"Awesome","parent_id":null,"child_id":[7],"position":3,"url_key":"awesome"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"4","_score":1,"_source":{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":4,"name":"Another sub","parent_id":2,"child_id":[],"position":0,"url_key":"another-sub"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"1","_score":1,"_source":{"is_active":true,"level":2,"children_data":[{"is_active":true,"level":3,"children_data":[],"product_count":200,"children_count":0,"id":5,"name":"Just another one","parent_id":1,"child_id":[],"position":0,"url_key":"just-another-one"},{"is_active":true,"level":3,"children_data":[{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":4,"name":"Another sub","parent_id":2,"child_id":[],"position":0,"url_key":"another-sub"}],"product_count":200,"children_count":1,"id":2,"name":"Testing Sub","parent_id":1,"child_id":[4],"position":0,"url_key":"testing-sub"}],"product_count":200,"children_count":2,"id":1,"name":"Shop Testing","parent_id":null,"child_id":[5,2],"position":1,"url_key":"shop-testing"}},{"_index":"vue_storefront_catalog_1560345028","_type":"category","_id":"7","_score":1,"_source":{"is_active":true,"level":3,"children_data":[{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":11,"name":"Awesome sub sub","parent_id":7,"child_id":[],"position":0,"url_key":"awesome-sub-sub"},{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":12,"name":"Awesome sub sub 2","parent_id":7,"child_id":[],"position":0,"url_key":"awesome-sub-sub-2"},{"is_active":true,"level":4,"children_data":[],"product_count":200,"children_count":0,"id":8,"name":"MORE AWESOME","parent_id":7,"child_id":[],"position":1,"url_key":"more-awesome"}],"product_count":200,"children_count":3,"id":7,"name":"Awesome sub","parent_id":6,"child_id":[11,12,8],"position":0,"url_key":"awesome-sub"}}]}}

I’m not totally sure but as far as I overlooked the pasted JSON - it’s missing the url_path property which is the full url path of the category as it’s being used by VS from 1.9. Details: https://docs.vuestorefront.io/guide/basics/url.html

That is weird. I thought only an url-key was needed (which they have)
Then this document is out of date?

For example this url seems to work

But this url doesn’t

(which is a level 4 categories)
It is not that it doesn’t find it. It is just that it does not load the page. Still debugging why.

The docs might have been outdated - that’s true. To have the urlDispatcher on you must have url_path set on products and categories