Copy: /app/code/core/mage/catalog/model/url.php
To: /app/code/local/mage/catalog/model/url.php
replace public function getProductRequestPath($product, $category) with following
public function getProductRequestPath($product, $category)
{
if ($product->getUrlKey() == '') {
$urlKey = $this->getProductModel()->formatUrlKey($product->getName());
} else {
$urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
}
$storeId = $category->getStoreId();
$suffix = $this->getProductUrlSuffix($storeId);
$idPath = $this->generatePath('id', $product, $category);
/**
* 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 = 'product-prefix/' .$categoryUrl . '/' . $urlKey;
} else {
$requestPath = 'product-prefix/' .$urlKey;
}
if (strlen($requestPath) > self::MAX_REQUEST_PATH_LENGTH + self::ALLOWED_REQUEST_PATH_OVERFLOW) {
$requestPath = substr($requestPath, 0, self::MAX_REQUEST_PATH_LENGTH);
}
$this->_rewrite = null;
/**
* Check $requestPath should be unique
*/
if (isset($this->_rewrites[$idPath])) {
$this->_rewrite = $this->_rewrites[$idPath];
$existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
if ($existingRequestPath == $requestPath . $suffix) {
return $existingRequestPath;
}
$existingRequestPath = preg_replace('/' . preg_quote($suffix, '/') . '$/', '', $existingRequestPath);
/**
* Check if existing request past can be used
*/
if ($product->getUrlKey() == '' && !empty($requestPath)
&& strpos($existingRequestPath, $requestPath) === 0
) {
$existingRequestPath = preg_replace(
'/^' . preg_quote($requestPath, '/') . '/', '', $existingRequestPath
);
if (preg_match('#^-([0-9]+)$#i', $existingRequestPath)) {
return $this->_rewrites[$idPath]->getRequestPath();
}
}
$fullPath = $requestPath.$suffix;
if ($this->_deleteOldTargetPath($fullPath, $idPath, $storeId)) {
return $fullPath;
}
}
/**
* Check 2 variants: $requestPath and $requestPath . '-' . $productId
*/
$validatedPath = $this->getResource()->checkRequestPaths(
array($requestPath.$suffix, $requestPath.'-'.$product->getId().$suffix),
$storeId
);
if ($validatedPath) {
return $validatedPath;
}
/**
* Use unique path generator
*/
return $this->getUnusedPath($storeId, $requestPath.$suffix, $idPath);
}
find product-prefix and replace it with your prefix.
flush cache and reindex.