Removing “Search by Color” from Magento Product Lists
As an eCommerce developer, I often receive requests to customize the product listing view in Magento stores. One common requirement is to remove certain filters or options that don’t align with the site’s design or user experience.
If you want to disable the “Search by Color” option in your product list, this guide will walk you through the process step-by-step.
Understanding the Magento Layered Navigation
Before we begin, let’s quickly understand how Magento manages layered navigation. It uses a module called magento_layerednavigation that handles all the filtersâincluding color swatchesâin the product grid view.
The color swatch is rendered using a block called catalog_category_layer_view. When you remove this block or change its configuration, the “Search by Color” option disappears from your site.
Disabling Color Swatches in Product Lists
To disable color swatches in Magento, we’ll need to modify two files:
- App/design/frontend/
/ /template/catalog/layer/view.phtml
Open this file using your favorite text editor or IDE. You’ll see a section of code that looks like this:
<?php if($_colorCount): ?>
<div class="block-layered-nav-block">
<h2><span><?php echo $this->__('Color') ?></span></h2>
<?php $i=0; foreach($_colorCount as $_colorCode=>$_colorName): ?>
<?php if($i++%4==0): ?>
<div class="block-layered-nav">
<ul id="color-nav">
<?php endif; ?>
<li><a href="<?php echo $this->getColorUrl($_colorCode) ?>"><?php echo $this->htmlEscape($_colorName)?></a> (<?php echo $_colorCount[$_colorCode] ?>)</li>
<?php if($i%4==0): ?>
</ul>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
This is the heart of the color swatch functionality. To remove it, simply comment out or delete this entire section.
- App/design/frontend/
/ /layout/catalog.xml
Next, open your theme’s catalog.xml layout file (or create one if it doesn’t exist).
Find the <reference name="content"> block and add the following code:
<remove name="catalog.product.list.layered.nav" />
This line removes the “catalog.product.list.layered.nav” block, which is responsible for rendering all filters in the product listâincluding the color swatches.
Testing Your Changes
After making these modifications, clear your cache and refresh a product listing page on your site. The “Search by Color” option should now be completely removed.
Remember, changing theme files directly may cause your changes to be lost when you update the theme in the future. It’s always recommended to override theme files using Magento’s built-in mechanism for customization (usually found under app/design/frontend/<Vendor>/<Theme>/).
Conclusion
Disabling color swatches in Magento product lists is a straightforward process involving simple PHP and XML modifications.
By following this guide, you’ve learned how to:
- Identify the key files responsible for rendering layered navigation options.
- Remove specific filters like “Search by Color” without affecting other filter types.
- Use Magento’s theme layout and template files for customization.
As an expert developer at Laravel Company, I always recommend keeping your Magento installations up-to-date to benefit from performance improvements, security patches, and new features. If you find yourself needing advanced customizations or facing technical challenges in your development process, don’t hesitate to reach out for professional assistance.
Happy coding!