1

I have configurable_product's id and color=red and size=x How can I get that product current stock in programmatically. Their inventory is:

------------------------------------------------------------ | Name | id | Stock | ------------------------------------------------------- | configurable_product | 6 | 0(not visible) | ------------------------------------------------------- | configurable_product_red_X | 7 | 1 | ------------------------------------------------------- | configurable_product_red_l | 8 | 5 | ------------------------------------------------------- | configurable_product_blue_s | 9 | 0 | ------------------------------------------------------- | configurable_product_blue_x | 10 | 2 | -------------------------------------------------------

1

Magento configurable products does not have it own stock.It stock is totally depends on it child's product stocks.

If you want a particular products variance (color=red and size=x) stock then first check which child product have those two option (color=red and size=x) and after that get that child product and by child product inventory module,you will get ur desire result

$stock = Mage::getModel('cataloginventory/stock_item')
                ->loadByProduct($_Childproduct);

You can try this:

<?php
/* Get Child Product ids from  parent product ids */

$ids=Mage::getResourceSingleton('catalog/product_type_configurable')
            ->getChildrenIds($_ParentId);
/* Create Custom product collection which is filter by Child Product ids */         
 $_subproducts = Mage::getModel('catalog/product')->getCollection()
    ->addIdFilter($ids)->addFieldToSelect('name');
/* add another  filter by color =red, size=x
@ assume that  red option id is 10;
@also assume that  x option is 52

*/  
$_subproducts->addFieldToFilter('color',10)->ddFieldToFilter('size',52);
        foreach ( $_subproducts  as $simple) {
                $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple);
                print_r($stock);

        }
?>      

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.