Hiding the base price from the category page view in Magento is a common task when you have products with custom options. The default configuration displays the price on both list and grid views, but you can easily modify this behavior.
Understanding the Price Display
In Magento, the price display is controlled by several files and settings. The core file responsible for rendering prices in category view is catalog/product/list.phtml. This file calls various other templates to render different parts of the product information block, including the price.
The default theme’s price.phtml file (located under app/design/frontend/{package}/{theme}/template/catalog/product/price.phtml) contains the base logic for displaying prices. It uses the Mage_Core_Block_Template class to render the price based on Magento’s configuration settings.
Removing the Base Price
To remove the base price from the category page, you have a few options:
1. Override the price.phtml Template
You can override the price.phtml template file in your custom theme. This allows you to modify the price display logic without changing any core files.
First, create a new folder structure under your custom theme’s template directory:
app/design/frontend/{package}/{theme}/template/catalog/product/
Then, copy the price.phtml file from the default theme and paste it into this new folder. Now you can modify this copied file to remove the base price logic.
Open your custom price.phtml file and locate the following line:
<?php echo $this->getPriceHtml($_product, true) ?>
Replace this line with an empty string or any other HTML element that won’t display a price:
<!-- Hide Base Price -->
2. Use Magento’s Configuration Settings
Magento provides a configuration setting to hide the base price in the catalog category view. To enable this:
- Log in to your Magento admin panel.
- Navigate to System > Configuration.
- Click on Sales > Catalog.
- Under the “Product Options” section, find the “Display Base Price” option and set it to “No”.
- Save the configuration changes.
This setting will hide the base price from all category views across your storefront. Note that this method doesn’t remove the price completely; it just hides it based on the Magento configuration.
3. Use an Event Observer
For a more flexible approach, you can create an event observer to modify the price display dynamically. This allows you to hide or show the base price based on specific conditions like product attributes or customer groups.
- Create an observer class (e.g.,
HideBasePriceObserver) under your custom module. - Implement the
observe()method to catch thecatalog_product_get_final_priceevent before it’s rendered in the category view. - Modify the price object based on your conditions and return a modified price or empty string.
Conclusion
Hiding the base price from the category page view requires either overriding the price template file, using Magento’s configuration settings, or creating an event observer to modify the price display dynamically.
The recommended approach is to override the price.phtml template in your custom theme. This method ensures that you don’t affect any core files and allows for easy modifications specific to your theme.
Remember to clear the cache after making changes and test them thoroughly on a development environment before deploying them to your live storefront.
For more advanced customizations, consider exploring Magento’s event-observer system and refer to our guide on Extending Magento Functionality for detailed instructions.