cancel
Showing results for 
Search instead for 
Did you mean: 

Get default quantity for associated products of a grouped product

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Get default quantity for associated products of a grouped product

Screen Shot 2017-02-17 at 09.11.34.png

 

 

 

 

 

 

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,

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Get default quantity for associated products of a grouped product

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
}
Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

View solution in original post

4 REPLIES 4

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();
Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

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

Re: Get default quantity for associated products of a grouped product

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
}
Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

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,