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.
As you already know the real category filtering is taking place in app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php
, more specifically in _getItemsData()
. Let us inspect that method.
<?php
$categoty = $this->getCategory();
$categories = $categoty->getChildrenCategories();
$this->getLayer()->getProductCollection()
->addCountToCategories($categories);
$data = array();
foreach ($categories as $category) {
if ($category->getIsActive() && $category->getProductCount()) {
$data[] = array(
'label' => Mage::helper('core')->escapeHtml($category->getName()),
'value' => $category->getId(),
'count' => $category->getProductCount(),
);
}
}
As you can see, the method loads child categories of $categoty
in layered navigation filter. That means we need to set this variable to a parent category in level 2 (Every main categories lies in level 2), according to the current category that we stands.
We can achieve this in many ways. In my method, I dig into the codes further and find the exact position where the category is set for layered navigation.
It resides here app/code/core/Mage/Catalog/Model/Layer.php
in getCurrentCategory()
. The method look like this.
<?php
public function getCurrentCategory()
{
$category = $this->getData('current_category');
if (is_null($category)) {
if ($category = Mage::registry('current_category')) {
$this->setData('current_category', $category);
}
else {
$category = Mage::getModel('catalog/category')->load($this->getCurrentStore()->getRootCategoryId());
$this->setData('current_category', $category);
}
}
return $category;
}
In short, it loads the current category to the variable $categoty
(variable that I mentioned in _getItemsData()
) if it set, otherwise loads the root-category
to variable categoty
. Replace this method with this code
<?php
/**
* Retrieve current category model
* If no category found in registry, the root will be taken
*
* @return Mage_Catalog_Model_Category
*/
public function getCurrentCategory()
{
$category = $this->getData('current_category');
if (is_null($category)) {
$category = Mage::registry('current_category');
if ($category) {
/*
* Check whether the current category is in level 2.
* If yes set it as current category.
* Else check for any parent categories with level 2
*/
if($category->getLevel() != 2) {
//gets all parent categories
$parentCategories = Mage::registry('current_category')->getParentCategories();
/*
* If parent categories exist,search for parent categories in level 2.
* If exist set it as current category.
*else set root category as current category.
*/
if(count($parentCategories) > 0)
{
foreach ( $parentCategories as $parentCategory ) {
if($parentCategory->getLevel() == 2 ) {
$category = Mage::getModel('catalog/category')->load($parentCategory->getId());
$this->setData('current_category', $category);
break;
}
}
}
else {
$category = Mage::getModel('catalog/category')->load($this->getCurrentStore()->getRootCategoryId());
$this->setData('current_category', $category);
}
}
else {
$this->setData('current_category', $category);
}
}
else {
$category = Mage::getModel('catalog/category')->load($this->getCurrentStore()->getRootCategoryId());
$this->setData('current_category', $category);
}
}
return $category;
}
What we are doing here is, we get the parent category in level 2 from the current category and set it to $categoty
, so that we can see all child categories in layered navigation.
As I already mentioned, you can achieve it in many ways. All you need to do is to set $categoty
variable with parent category in level 2. Above I have altered the root files. It is not a good practice. You have to create a module that rewrites the model file app/code/core/Mage/Catalog/Model/Layer.php
and then overwrite the method getCurrentCategory()
.
Hope it helps
Best Answer
Yes there is. U can go to stores-->configuration -->catalog --> category top navigation --> maximal depth (0= no limits).
Also if u use a custom mega menu or something they have also a setting for this