Stock check on Product page

I want to do a stock check whenever the user enters a product page, our current implementation is this:

    stockCheck () {
      const skus = [this.product.sku]
      if (this.product.type_id === 'configurable' && this.product.configurable_children && this.product.configurable_children.length > 0) {
        for (const confChild of this.product.configurable_children) {
          const cachedItem = rootStore.state.stock.cache[confChild.id]
          skus.push(confChild.sku)
        }
        if (skus.length > 0) {
          rootStore.dispatch('stock/list', { skus: skus }) // store it in the cache
        }
      }
    },

but it seems this goes to Magento to check for stock and not to ES. Any suggestions on how to improve this?

You can do a query on elasticsearch using quickSearchByQuery, if you ask for a specific product then the json reponse will look like this
`“stock”: {

“item_id”: 24,
“stock_id”: 1,
“qty”: 100,
“is_in_stock”: true,
“is_qty_decimal”: false,
“use_config_min_qty”: true,
“min_qty”: 0,
“use_config_min_sale_qty”: true,
“min_sale_qty”: 1,
“use_config_max_sale_qty”: true,
“max_sale_qty”: 10000,
“use_config_notify_stock_qty”: true,
“notify_stock_qty”: 1,
“use_config_qty_increments”: true,
“backorders”: false,
“use_config_backorders”: true,
“qty_increments”: 1,
“use_config_enable_qty_inc”: true,
“enable_qty_increments”: false,
“use_config_manage_stock”: true,
“manage_stock”: false,
“low_stock_date”: null,
“stock_status”: 1
},`

(i’m only reporting the stock part) and you can check if stock is not 0. Hope this is helpfull