The file to edit is /app/code/core/Mage/Catalog/Model/Url.php though i advise rather than editing this directly you create a copy in /app/code/local/Mage/Catalog/Model/Url.php.
Then within function getProductRequestPath (around line 685) amend the following code
1
2
3
4
5
6
7
8
9
10
11
12
|
/** * Prepare product base request path */ if ($category->getLevel() > 1) { // To ensure, that category has path either from attribute or generated now $this->_addCategoryUrlPath($category); $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $storeId); $requestPath = $categoryUrl . '/' . $urlKey; } else { $requestPath = $urlKey; } |
to this
1
2
3
4
5
6
7
8
9
10
11
12
|
/** * Prepare product base request path */ /*if ($category->getLevel() > 1) { // To ensure, that category has path either from attribute or generated now $this->_addCategoryUrlPath($category); $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $storeId); $requestPath = $categoryUrl . '/' . $urlKey; } else {*/ $requestPath = $urlKey; //} |
And for good measure also amend the function generatePath to edit around line 831 and comment out this section.
1
2
3
4
5
6
7
8
9
10
|
/*if ($category->getLevel() > 1) { // To ensure, that category has url path either from attribute or generated now $this->_addCategoryUrlPath($category); $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $category->getStoreId()); return $this->getUnusedPath($category->getStoreId(), $categoryUrl . '/' . $urlKey . $productUrlSuffix, $this->generatePath('id', $product, $category) ); }*/ |
and around 851
1
2
3
4
|
/*if ($category && $category->getLevel() > 1) { return 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId(); }*/ |
and around 348
1
2
3
4
5
|
/*if ($category->getLevel() > 1) { $categoryId = $category->getId(); $updateKeys = false; }*/ |
The next file to edit is /app/code/core/Mage/Catalog/Model/Product/Url.php (again I advise rather than editing this directly you create a copy in /app/code/local) in which we need to ensure the categoryid used for generating the links is always set to null. Edit the function getUrl around line 172 and make the follow amend
1
2
3
4
5
6
7
8
9
10
11
|
/* commenting this out and setting the categoryId to null everytime if (isset($params['_ignore_category'])) { unset($params['_ignore_category']); $categoryId = null; } else { $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null; }*/ $categoryId = null; |
http://blueclawecommerce.co.uk/blog/remove-category-path-from-product-url-in-magento/