I'm fairly new to Magento and came across a situation where I need to get data (specifically available quantity) of all simple products connected to its configurable product.
I've managed to get the id's of the simple products like this:
$simpleProductIds = Mage::getModel('catalog/product_type_configurable')->getUsedProductIds($product);
This gives me an array with all the ids of the simple products linked to the configurable product. But now I'd like to get the quantities of all these simple products (to put in array and later check their availability, as requirement due to custom add to cart action). I'd like to do this in a single request so as to minimize the load.
What I've got so far (and doesn't work), is the following:
$stockItemCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()
->addAttributeToFilter('product_id', array('in' => $simpleProductIds));
I've also tried it with ->addAttributeToSelect
and both versions with the following after it:
->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
);
(as found in this entry)
So far none of these things have yielded any results. What am I missing/doing wrong?
Please note that once I have the simple product ids (which works as desired), I want to get all the simple products with only one database call, which I know is possible, somehow (if all of this can be done with just one database call, instead of first getting all the id's, that would be even better).
Any wizard know this magic spell? Many thanks.