Question

Today just before lunch (around the time a reindex was being pushed through) the category urls started throwing up 404 errors.

Site in question:

http://www.awesomegti.com

However, if you search a product (eg: ttrs) the search works fine, as do the product links. Also all CMS pages such as company info work perfect.

Anyone got any ideas?

Ive a feeling its an issue with the Catalog URL Rewrite Reindex as this seems to fail/remain unfinished.

Any help appreciated :)

Was it helpful?

Solution

Programmatically speaking, the category page will return a noRoute/404 page when the call to _initCategory returns false.

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
if ($category = $this->_initCatagory()) {
    //...
}
elseif (!$this->getResponse()->isRedirect()) {
    $this->_forward('noRoute');
}

The _initCategory method returns false for three reasons

When a category id can't be extracted from the request,

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
$categoryId = (int) $this->getRequest()->getParam('id', false);
if (!$categoryId) {
    return false;
}

When the catalog/category helper's canShow method returns false,

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
if (!Mage::helper('catalog/category')->canShow($category)) {
    return false;
}

When an observer of the catalog_controller_category_init_after event throws an exception

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
try {
    Mage::dispatchEvent(
        'catalog_controller_category_init_after',
        array(
            'category' => $category,
            'controller_action' => $this
        )
    );
} catch (Mage_Core_Exception $e) {
    Mage::logException($e);
    return false;
}

The canShow method mentioned above returns false for three reasons.

If the category has no id,

#File: app/code/core/Mage/Catalog/Helper/Category.php
if (!$category->getId()) {
    return false;
}

The category's active property is set to false

#File: app/code/core/Mage/Catalog/Helper/Category.php
if (!$category->getIsActive()) {
    return false;
}

Or the category isn't in the root category list

#File: app/code/core/Mage/Catalog/Helper/Category.php
if (!$category->isInRootCategoryList()) {
    return false;
}

Some quick temporary debugging code in the above files should get to the bottom of your problem.

If viewAction method isn't being called, it means your rewrites aren't being created. If you're using Commerce Bug (my commercial Magento debugging extension) the Request tab will quickly tell you which controller action method is being called.

OTHER TIPS

On my case the url rewrites seems to be wrong, looks like some categories url were created without a store id, and that made magento try to load a category of the wrong store, thus the isInRootCategoryList (that alan storms mentions) was giving a false.

you can quickly find out if you have wrong urls on your url rewrites:

select * from core_url_rewrite where target_path like 'catalog/category/view/%' and store_id = 0

I still haven't find out the issue that made those urls end up there, but deleting them seems to solve the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top