Reputation: 777
My development website has a traffic light graphic system to illustrate stock levels for each item. In amongst those simple products, I have a few bundle products (more to come in future). On the product listings (and details) pages, the stock graphic is always showing red, or out of stock - even when every product contained in the bundle is IN stock.
I figure the only way around this is to hide the stock graphic for all bundle products.
Does anyone know how to do this? How do I perform a test in code to display (or not) the stock graphic based on the products type_id being bundle?
My worry is that this isn't a great idea due to the added overhead of testing each product before displaying the page??
Any other suggestions are more than welcome! Cheers!
Upvotes: 1
Views: 1349
Reputation: 777
It turns out this is far simpler than previously thought. The following code will check if a product is of type "Bundle" and then conditionally show the stock counter.
<?php if($_product->getTypeId() != "bundle"): ?>
[Stock counter display code here]
<?php endif; ?>
I hope that helps someone else looking for this!
Upvotes: 1
Reputation: 37700
By looking at the default theme I see the bundle has it's own template for showing stock status which checks Mage_Bundle_Model_Product_Type::isSalable()
, this already does the costly operation of loading all it's component products and checking them individually. Also the price works in a similar way, loading the components. It is costly because this is a big EAV operation. Some of the slowest stores I've worked on have notably had a lot of bundle/configurable products.
So the work is already done by the database and looping through the loaded products one more time to check the stock again will probably not be a big deal. Besides you can limit the impact by using something like CatalogCache.
Unfortunately I don't see a stock quantity event so you may have to extend Mage_Bundle_Model_Product_Type
with your own getStockQty()
method to do the appropriate lookups and calculation.
If you have already changed the stock display then it would have been in the template/bundle/catalog/product/view/type/bundle.phtml
file. Remove the 'traffic lights' from there if you want the simplest way to hide bundle's stock level. This does not affect other product types.
Upvotes: 1