How to display bundled products in category list when simple product is out of stock?
-
16-10-2019 - |
سؤال
I'm trying to display the bundled product in the category product list on the frontend even when the simple product it concists of is out of stock. I only want to hide the add to cart button.
I've looked into changing the Mage_Bundle_Model_Product_Type
class to return true on the stock check but that is not really a solution.
Is there a way to do this in a clean way either trough settings or by extending as little core code as possible?
المحلول
You could create some method in one of the helpers
public function isBundleAvailable($_product) {
$bundle = Mage::getModel('catalog/product')->load($_product->getId());
$selectionCollection = $bundle->getTypeInstance(true)->getSelectionsCollection(
$bundle->getTypeInstance(true)->getOptionsIds($bundle), $bundle
);
$items = array();
foreach($selectionCollection as $option) {
$isAvailable = $option->getStockItem()->getIsInStock();
if (!$isAvailable) {
return false;
}
}
return true;
}
Then in template you could use something like that:
<?php if (Mage::helper('my_module')->isBundleAvailable($_product)): ?>
<?php //display add to cart button
<?php endif ?>
نصائح أخرى
The bundled product should be visible when you have the option: System > Configuration > Inventory > Stock Options > Display Out of Stock Products set to Yes. All out of stock products are listed but you have no Add to Cart button.