Removing Unwanted Magento Pages Permanently: The Orders and Returns Example
As an experienced developer working with Magento platforms, you’ve likely come across unwanted pages that appear by default but don’t align with your site’s layout or SEO strategy. One common culprit is the “Orders and Returns” page introduced in Magento versions 1.6 and later.
Understanding the Default Behavior
By default, Magento creates an Orders and Returns page at the URL structure www.yourstore.com/sales/guest/form/. This page allows guest users to view their order history. However, many stores prefer to manage returns through a dedicated system or custom functionality rather than this built-in feature.
Moreover, if not properly managed, this page can be indexed by search engines like Google, potentially leading to duplicate content issues and confusing navigation for customers.
Removing the Link in the Footer
The first step is to remove the link to this page from your site’s footer. This is a straightforward process involving layout updates in your local.xml file.
Here’s how you can do it:
- Navigate to your
app/design/frontend/<your_package>/<your_theme>/layout/directory. - Open or create a
local.xmlfile if one doesn’t exist. - Add the following code inside the
<layout>tags:
<default>
<reference name="footer_links">
<action method="removeLink" link_id="guest_order_history"></action>
</reference>
</default>
This XML snippet removes the “Guest order history” link from your footer.
Removing the Page Itself: A More Advanced Approach
While removing the link hides the page from users, it doesn’t prevent the page from being created or indexed. To completely remove this functionality, you need to override or disable the core Magento modules responsible for creating these pages.
Overriding the Controller
The Orders and Returns page is generated by a controller action in the Mage_Sales module. You can override this controller to prevent it from executing.
-
Create a new folder named
app/code/local/Mage/Sales/controllers/. -
Inside this folder, create another folder named
Guest. -
Copy or clone the existing
GuestController.phpfile located inapp/code/core/Mage/Sales/controllers/Guest/and paste it into your newly created folders. -
Open the new
GuestController.phpfile and add a line of code at the beginning of the_construct()method:
public function _construct()
{
$this->_redirect('*');
}
This code redirects all requests to any URL in your site, effectively preventing the GuestController from executing.
- Save the changes and clear your cache.
Disabling the Module
If you want a more drastic approach that disables the entire Mage_Sales module to prevent it from creating unnecessary pages, you can use Magento’s built-in module disabling feature.
- Navigate to your
app/etc/modules/Mage_All.xmlfile. - Find the line for the
Mage_Salesmodule:
<Mage_Sales>
<active>true</active>
<codePool>core</codePool>
<depends>
<Mage_Core />
</depends>
</Mage_Sales>
- Change
<active>true</active>to<active>false</active>. - Save the changes and clear your cache.
Conclusion
Removing unwanted pages in Magento isn’t always straightforward, but it’s a crucial part of maintaining a clean, secure, and optimized e-commerce site. By understanding how to override controllers and disable modules, you can prevent unnecessary pages from being created and indexed.
Remember, whenever modifying core files or disabling modules, always make sure you have a backup of your system in case something goes wrong. It’s also recommended to thoroughly test any changes before deploying them to a live environment.
At Laravel Company, we specialize in helping businesses optimize their Magento platforms for performance and security. If you need assistance with advanced customizations like this, don’t hesitate to reach out to our team of experienced developers.