Here is an example how to access the is salable state or the stock quantity of all associated child products.
this first method is simply to fetch the child product ids from the bundled product.
function getBundledProductChildIds(Mage_Catalog_Model_Product $product)
{
$childrenIds = [];
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
$childrenIds = array_reduce(
$product->getTypeInstance(true)->getChildrenIds($product->getId()),
function (array $reduce, $value) {
return array_merge($reduce, $value);
}, []);
}
return $childrenIds;
}
The next example gives you the in stock or out of stock for each child product.
$bundledProduct = Mage::getModel('catalog/product')->load(BUNDLED_PRODUCT_ID);
// Just get the is salable state of the child products
$childProducts = Mage::getResourceModel('catalog/product_collection')
->addIdFilter(getBundledProductChildIds($bundledProduct));
foreach ($childProducts as $child) {
printf("%s -> %s stock\n", $child->getId(), ($child->getIsSalable() ? 'in' : 'out of'));
}
The final example gives you the stock qty of each child product.
Note that the key difference is that the require_stock_items
flag is set on the collection before it is loaded.
$bundledProduct = Mage::getModel('catalog/product')->load(BUNDLED_PRODUCT_ID);
// Get the inventory qty of each child item
$childProducts = Mage::getResourceModel('catalog/product_collection')
->addIdFilter(getBundledProductChildIds($bundledProduct))
->setFlag('require_stock_items', true);
foreach ($childProducts as $child) {
printf("%s -> stock qty: %d\n", $child->getId(), $child->getStockItem()->getQty());
}
printf("Total stock item qty sum: %d\n", array_reduce(
$childProducts->getItems(),
function ($sum, $child) {
return $sum + $child->getStockItem()->getQty();
}, 0));
printf("Highest stock qty: %d\n", array_reduce(
$childProducts->getItems(),
function ($max, $child) {
return max($max, $child->getStockItem()->getQty();
}, 0));
That should hopefully enable you to get what you need.
Why I can not use bundle products
It is not possible to add fixed products. In addition user can change
the qty (the qty of each item is fixed, only model can be chosen)
Good news: That's not true. You can add fixed products as well as selectable products with fixed qty.
For the fixed items, create one option each, as follows:
- Type: Drop-down
- Is Required: Yes
- One Selection
- Default Qty: 1
- User Defined Qty: No
For the other items, create one option each as follows:
- Type: Drop-down
- Is Required: Yes
- Multiple Selections for the different models:
- Default Qty: 1
- User Defined Qty: No
Best Answer
But...This isn't a bundle.
Here's some reading on grouped versus bundle:
But for real, this is a sales rule, with minimum cart quantity and discount.