I'm getting the simple products of a configurable with the following code:-
if($_product->getTypeId() == "configurable"): $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); $simple_collection = $conf->getUsedProductCollection() ->addAttributeToSelect('*') ->addFilterByRequiredOptions(); endif;
And then with this collection, I'm conditionally displaying a size chart which works perfectly (
foreach($simple_collection as $simple_product)) however I need to determine what table headers to use in the chart by another condition (and currently, I can only think of doing this by category unfortunately).
Rather than just loading the above collection by category ID though, is there any way I can build into the existing collection a way to determine what the category ID is of the configurable product and then use an
if statement as necessary in the chart to display various data based on the category ID?
I know how to load the collection from a category ID but unsure if it is possible to determine the current category from
getUsedProductCollection. You have to get the category ids from the configurable product
$_product->getCategoryIds()and then go up the tree for each id you get until you get the level 2 that you need. Here is a way to go up the tree without loading the full category collection. But just for the record, this approach seams prone to errors from my point of view because you have to hard code ids. it would be better to have a product attribute linked to the headers in my opinion.