Skip to content

How to get stock value in dropdown options on configurable probuct page?

I need to get the stock value of a simple product in the dropdown selector from the configurable product page.

I found the _fillSelect method in

module-configurable-product/view/frontend/web/js/configurable.js

I override it with

app/code/Vendor/ConfigurableProduct/view/frontend/web/js/configurable-mixin.js

But I don’t understand how to get the stock value and add it like this in the select :

<select>                   
         <option value="">Choose a size</option>
         <option data-stock="xxx">S</option>
         <option data-stock="xxx">M</option>
         <option data-stock="xxx">L</option>
</select>

Could you help me ?