edit the file /app/design/frontend/{package}/{theme}/template/catalog/layer/view.phtml
and replace this line:
<?php if($_filter->getItemsCount()): ?>
with
<?php if($_filter->getItemsCount() > 1): ?>
I only see one problem with this approach.
If all your filters have only one option they you will still get the section title
<p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
But this can easily be overcome if you loop through the available filters and see if you have at least one that has the items count bigger than 1.
This is a broad subject. Most probably you won't get a fully working answer, but I can give you some tips on where to start.
I would add 2 more category attributes:
One being a yes/no attribute called Use custom filter attributes
with the code use_custom_filters
. If this is set to no
then all the available attributes will be used in the filters.
The second attribute should be a multiselect with all the attributes available for filtering. let's call it Attributes for filter
with code filter_attributes
.
You can get the product attributes available for filtering like this:
$collection = Mage::getResourceModel('catalog/product_attribute_collection')->addFieldToFilter('is_fiterable', 1);
Here is a tutorial on how to add a category attribute.
Also here is a tutorial on how to add an attribute with custom options. The example is for products, but it works the same for categories. Just replace catalog_product
with catalog_category
.
Now you need to change the functionality that determines the filterable attributes.
This happens in the layer model: https://github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/core/Mage/Catalog/Model/Layer.php#L215.
You just need to rewrite that method and check if you are in a category context (if Mage::registry('current_category')
returns something other than null
).
then check this ($collection is the variable in the method mentioned):
if (Mage::registry('current_category')->getUseCustomFilters()) {
$allowedAttributeIds = Mage::registry('current_category')->getFilterAttributes();
$collection->addFieldToFilter('attribute_id', array('in' => $allowedAttributeIds))
}
//else, do nothing, let the script behave as it does.
Not sure if getFilterAttributes
will return an array or a string. If it returns a string you just have to explode
it by comma before using it.
Best Answer
We required this too and we use a very similiar solution as zhartaunik has suggested ...
You have to modifiy/rewrite
Mage_Catalog_Block_Layer_View
andAdd:
And change
Now you can go to
local.xml
or "Custom Layout Update" and add this: