My client doesn't want customers landing on a 404 due to a product being disabled. My first thought was write an observer that would fire as soon as someone 'viewed' a product, however that solution didn't pan out for myself or another dev (who is much more experienced). I decided to go the route of rewriting the ProductController, specifically the viewAction within it. My current hope, was that when a normal 'enabled' product was viewed that things would run as normal, and when a disabled product was viewed, that it would avoid the 404 and direct you to a custom CMS page.

Below is the viewAction() function. Currently, if you view an enabled product it enters the viewAction function and hits the exit;(leaving you with a blank page), however with a disabled product, it never enters this function and leaves you with a 404. Which leaves me with 2 possibilities;

  1. I need to find where, if a product is 'disabled' it directs you to a 404 (I've spent a few hours on it to no avail).
  2. It IS supposed to come through this function, but isn't because something else is wrong/affecting it locally
public function viewAction() {
    $categoryId = (int) $this->getRequest()->getParam('category', false);
    $productId  = (int) $this->getRequest()->getParam('id');
    $specifyOptions = $this->getRequest()->getParam('options');

    // Prepare helper and params
    $viewHelper = Mage::helper('catalog/product_view');

    $params = new Varien_Object();

    try {
        $viewHelper->prepareAndRender($productId, $this, $params);
    } catch (Exception $e) {
        if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) {
            if (isset($_GET['store'])  && !$this->getResponse()->isRedirect()) {
            } elseif (!$this->getResponse()->isRedirect()) {
        } else {

Update** I tried performing the same rewrite on another project I'm currently on, and it appears to be working correctly. Seems the issue is my local project.


1 Answer 1


Why not just display out of stock products? This is an option under system > configuration > inventory

enter image description here

Make sure Display Out of Stock Products is set to yes.

Optionally, if you don't want to have them in the list view either set the visibility of the specific product to, for example, search manually or write an observer to do so when product is Out Of Stock

  • This is actually already set as enabled, yet when a product has a status of 'Disabled' Magento still gives a 404. The only way view a disabled product is to manually enter the url in the address bar. Im not sure if my client expects a lot of people to do this, they just want to avoid the 404, and direct users to an editable CMS page that I already created - the 'disabled-redirect' you see near the end of the viewAction.
    – PRstafki
    Dec 21, 2015 at 21:54
  • @PRstafki just tried it on a vanilla Magento install and it should work afak. Might be a caching or reindex issue? Dec 22, 2015 at 17:16
  • I appreciate the try @SanderMangel, but all caching is turned off, things have been reindexed correctly. I'm now trying to figure out at which point a 'disabled product' view is redirected since only 'enabled product' view attempts seem to be entering the 'viewAction'.
    – PRstafki
    Dec 22, 2015 at 20:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.