0

The Mage::getResourceModel('catalog/product_collection') didn't calculate stock for configurable products.

I think, with MySQL, there is a way, to calculate configurable product stock from simple products stock.

  • simple product = 1 cataloginventory_stock_item
  • configurable product = 2 or more cataloginventory_stock_item

Can someone help us to create a SQL query to do this?

  • you need to assign associated products qty to configurable product – saravanavelu Jun 11 '15 at 11:37
1

Try it the magento way,

$product = Mage::getModel('catalog/product')->load(874); // 874 is the product_id of configurable product

$config = Mage::getModel('catalog/product_type_configurable')
        ->setProduct($product);

$collection = $config->getUsedProductCollection()
                     ->addAttributeToSelect('*')->addFilterByRequiredOptions();

$total_qty = 0;
foreach ($collection as $sprod) {
     //$sprod = Mage::getModel('catalog/product')->load($sprod->getId());
     $qty = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($sprod)->getQty());
     $total_qty+=$qty;
}
echo $total_qty;
  • Have a look at Mage_CatalogInventory_Model_Stock_Status::addStockStatusToProducts. It would be a magento way of adding the stock item to each product in your collection. – Luke Rodgers Jun 11 '15 at 11:05

Your Answer

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