Skip to content

Product Quantity not coming for the Configurable product in Magento-2.4.4

I have a code getting stock status(quantity) for a configurable product the code is working fine till Magento-2.4.3 for both swatch and dropdown. But In Magento-2.4.4 it is giving an error for the swatch.
enter image description here

Here is the code attached:

<script type="text/javascript">
        requirejs(['jquery','underscore'], function(jQuery,_){
            jQuery(window).on('load',function(){
                jQuery( ".product-options-wrapper div" ).click(function() {
                    selpro();
                });        
            });
            function selpro () {
                var selected_options = {};
                jQuery('div.swatch-attribute').each(function(k,v){
                    var attribute_id    = jQuery(this).data('attribute-id');
                    var option_selected = jQuery(this).data('option-selected');
                    if(!attribute_id || !option_selected){ return;}
                    selected_options[attribute_id] = option_selected.toString();
                });
    
                var product_id_index = jQuery('[data-role=swatch-options]').data('mageSwatchRenderer').options.jsonConfig.index;
                
                var found_ids = [];
                jQuery.each(product_id_index, function(product_id,attributes){
                    var productIsSelected = function(attributes, selected_options){
                         return _.isEqual(attributes, selected_options);
                    }
                    if(productIsSelected(attributes, selected_options)){
                        found_ids.push(product_id);
                    }
                });
                console.log(found_ids);
                if (found_ids.length) {
                    var selected_product_id = found_ids[0];
                    jQuery('.myli').css('display','none');
                    console.log("selected_product_id : " +selected_product_id);
                    jQuery('#div'+selected_product_id).toggle();
                }
            }
        }); </script>