最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How can I show configurable product stock quantity in Magento? - Stack Overflow

programmeradmin2浏览0评论

I have made this code to show if some configurable product has or not stock. But I can't get the stock quantity anywhere in varien/product.js

updateStock: function(){
    var tempProducts = [];
    var allowedProducts = [];

    var idColor = jQuery('#attribute85').val();
    var idTalla = jQuery('#attribute127').val();

    // productos por color 
    var options = this.getAttributeOptions(85);
    for (var i = 0; i < options.length; i++ ) {
        if (options[i].id == idColor) {
            for (var j = 0; j < options[i].products.length; j++) {
                tempProducts.push(options[i].products[j]);
            }
        }
    }

    jQuery('#input-box-127 a').each(function(index) {
        // jQuery(this).find('.talla').removeClass('seleccionado');
        jQuery(this).find('div').addClass('sin_stock');

        idTalla = jQuery(this).attr('rel');
        options = spConfig.getAttributeOptions(127);
        for (var i = 0; i < options.length; i++ ) {
            if (options[i].id == idTalla) {
                for (var j = 0; j < options[i].products.length; j++) {
                    for (var index = 0; index < tempProducts.length; index++) {
                        if (tempProducts.indexOf(options[i].products[j]) > -1) {
                            //alert(jQuery(this).text());
                            jQuery(this).find('div').removeClass('sin_stock');
                        }
                    }
                }
            }
        }
    });

    return allowedProducts.length > 0;
}, 

Is there any variable in magento where I can get the configurable product stock?

I have made this code to show if some configurable product has or not stock. But I can't get the stock quantity anywhere in varien/product.js

updateStock: function(){
    var tempProducts = [];
    var allowedProducts = [];

    var idColor = jQuery('#attribute85').val();
    var idTalla = jQuery('#attribute127').val();

    // productos por color 
    var options = this.getAttributeOptions(85);
    for (var i = 0; i < options.length; i++ ) {
        if (options[i].id == idColor) {
            for (var j = 0; j < options[i].products.length; j++) {
                tempProducts.push(options[i].products[j]);
            }
        }
    }

    jQuery('#input-box-127 a').each(function(index) {
        // jQuery(this).find('.talla').removeClass('seleccionado');
        jQuery(this).find('div').addClass('sin_stock');

        idTalla = jQuery(this).attr('rel');
        options = spConfig.getAttributeOptions(127);
        for (var i = 0; i < options.length; i++ ) {
            if (options[i].id == idTalla) {
                for (var j = 0; j < options[i].products.length; j++) {
                    for (var index = 0; index < tempProducts.length; index++) {
                        if (tempProducts.indexOf(options[i].products[j]) > -1) {
                            //alert(jQuery(this).text());
                            jQuery(this).find('div').removeClass('sin_stock');
                        }
                    }
                }
            }
        }
    });

    return allowedProducts.length > 0;
}, 

Is there any variable in magento where I can get the configurable product stock?

Share Improve this question edited Jul 26, 2012 at 16:59 DaveRandom 88.7k11 gold badges158 silver badges173 bronze badges asked Jul 26, 2012 at 16:34 iVelaiVela 1,2011 gold badge22 silver badges40 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

You can get sub products list and count all sub product quantities as configurable product's quantity...

$product=Mage::getModel("catalog/product");         
$prod=$product->load($prod_id);
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($prod);
    $col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

    $total_qty=0;
    foreach($col as $sprod){
        $sprod=$product->load($sprod->getId());
        $qty = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($sprod)->getQty());
        $total_qty+=$qty;
    }       

In Magento there is NO stock level for a configurable product.

Each child product / variation has it's own stock level so you would need to check the stock of the variation currently selected.

发布评论

评论列表(0)

  1. 暂无评论