- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 }
Problem solved? Click Accept as Solution!"
Qaisar Satti
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Get default quantity for associated products of a grouped product
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();
Problem solved? Click Accept as Solution!"
Qaisar Satti
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Get default quantity for associated products of a grouped product
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 }
Problem solved? Click Accept as Solution!"
Qaisar Satti
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Get default quantity for associated products of a grouped product
Hi Qaisar,
Yes! that code gives me the default sales qty for the associated product.
Thank you very much.
Cheers,