With the caveat that layered navigation changes are always more complicated than they seem, the product collection for the layered navigation is instantiated in
#File: app/code/core/Mage/Catalog/Model/Layer.php
public function getProductCollection()
{
if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
} else {
$collection = $this->getCurrentCategory()->getProductCollection();
$this->prepareProductCollection($collection);
$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
}
return $collection;
}
It also has its default filters added in
#File: app/code/core/Mage/Catalog/Model/Layer.php
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addUrlRewrite($this->getCurrentCategory()->getId());
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
return $this;
}
And an intriguingly named getFilterableAttributes
#File: app/code/core/Mage/Catalog/Model/Layer.php
public function getFilterableAttributes()
{
$setIds = $this->_getSetIds();
if (!$setIds) {
return array();
}
/** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection
->setItemObjectClass('catalog/resource_eav_attribute')
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection = $this->_prepareAttributeCollection($collection);
$collection->load();
return $collection;
}
A rewrite of any one of those methods would be a good place to start (adding an type=configurable
filter, restricting the filterable attributes, etc.)
You will only be able to do this hardcoded.
So filtering out the manufacturer and category on the left side and creating a custom PHTML file that generates links/dropdowns for the manufacturer and category in the center.
so in app/design/frontend/[template]/[package]/template/catalog/layer/view.phtml
around line 49 edit
<?php if($_filter->getItemsCount() && ($_filter->getName()!='manufacturer' || $_filter->getName()!='categories')): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
Would eliminate manufacturer
and categories
from the list. Optionally try to use getCode
, I think that would return the attribute_code
instead of the name.
For your center layered navigation create a new PHTML file and add it to the layout
<reference name="content">
<block type="core/template" name="center_layered_nav" template="catalog/layer/center.phtml"/>
</reference>
and in the file catalog/layer/center.phtml
something like this
<form method="GET" id="center_layered">
<select name="manufacturer" onchange="document.getElementById('center_layered').submit();">
<?php
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'manufacturer');
$options = $attribute->getSource()->getAllOptions(false);
foreach ($options as $option)
{
echo '<option value="'.$option['value'].'">'.$option['label'].'</option>';
}
?>
</select>
</form>
when a user selects a manufacturer it should add manufacturer to the layered navigation URL. Manufacturer
does have to be a filterable attribute tho.
This is highly untested code so may need a tweak or two but it's basically what you need. And I'm in no way pretending this is best practice but as far as I know it's the only way to do it.
Best Answer
You need to rewrite how
Mage_Catalog_Model_Layer
builds the attribute collection using the current product collection's attribute sets:For this context, you'll want to check the product collection for grouped products and return the attribute set IDs of grouped children. These are then evaluated in
getFilterableAttributes()
:You will likely need to deal with the cache key. I would develop with block caching off and then test extensively with it on.