2
votes

I have a problem with magento product links. When I search a product and then click the product link, Magento redirects me to index.php/test666.html when it supposed to be index.php/products/grocery/miso-soup/test666.html.

is it possible to force Magento use product's full path?

Added:

I can't get it to work by enabling 'Use Categories Path for Product URLs'. So I ended up with the following code.

$categories = $_product->getCategoryIds();
$lastCategory = $_categoryModel->load(end($categories));

$urlPath = explode("/",$lastCategory->getUrlPath());

$urlPathCnt = count($urlPath)-1;
$urlPath[$urlPathCnt] = str_replace(".html","",$urlPath[$urlPathCnt]);
$productUrl = "/".implode("/",$urlPath)."/".$_product->getUrlKey().".html";

but I really don't like this way. It uses unnecessary resource. Any ideas??

5
@Moon where i have to paste this code..As i am new in magento Thanks :) - user5134497

5 Answers

2
votes

Search results won't give you a full link because Magento allows any product to be in multiple categories. There is no way to guess the correct category for the product if you are using the search box. In other words, a product link could have multiple URLs.

If you are completely sure you're only assigning one category per product, you may change the search source code or make an extension, to show a link with full path for every search result.

1
votes

In the admin, go to System>Configuration>Catalog>Search Engine Optimizations and set Use Categories Path for Product URLs

0
votes

You may need to refresh the "Catalog URL Rewrites" index. The HTML may also be served from the cache, so refreshing it wouldn't hurt.

0
votes

Also make sure you're using the method $product->getProductUrl() to take advantage of the setting mentioned above.

0
votes

I assume that search results won't give you a full link because Magento allows any product to be in multiple categories. There is no way to guess the correct category for the product if you are using the search box. In other words, a product link could have multiple URLs.

But if you are completely sure you're only assigning one category per product, you may change the search source code or make an extension, to show a link with full path for every search result.