I'm working with Grouped products & I'm looking to retrieve the default qty for each associated product. So, in the example above, I should be returning 9 & 1 for the associated products.
Here's my code where I get the associated products:
$products = $item->getTypeInstance(true)->getAssociatedProducts($item);
foreach($products as $p){
$productSimple = Mage::getModel('catalog/product')->load($p->getId());
$_stockQty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($p->getId())->getQty();
Mage::log($p->getId() . ' Qty ' .$_stockQty);
$_minQty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($p->getId())->getMinSaleQty();
Mage::log($p->getId() . ' Qty ' .$_minQty);
.....
}
It's the bit where I'm calling:
$_minQty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($p->getId())->getMinSaleQty();
that's not getting me the correct result. I've tried variations on getMinQty(), getDefaultQty(), etc but w/o success.
I've tried to find where in Core this might be used to get the default qty but can't find it.
Any suggestions?
Thanks,
Solved! Go to Solution.
If you are talking about image qty then you can get by following code.
foreach($products as $p){ echo $p->getQty(); //this will give you default quntity }
Here you can get quantity of product . This is tested code
$_itemcur=Mage::getModel('catalog/product')->load($p->getEntityId()); $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_itemcur); echo $stock->getQty();
Hi Qaisar,
Thanks for replying. However, your code returns the actual stock inventory - how many are left. This I'm already using:
foreach($products as $p){
$_stockQty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($p->getId())->getQty();
The only real difference is the way we load the product - I load the product by Product ID but you use Entity ID. Does that make a difference?
What I'm trying to retrieve is the default number of this product that is sold with this grouped product rather than the current stock quantity.
Thanks again,
Eddie
If you are talking about image qty then you can get by following code.
foreach($products as $p){ echo $p->getQty(); //this will give you default quntity }
Hi Qaisar,
Yes! that code gives me the default sales qty for the associated product.
Thank you very much.
Cheers,