如何强制magento使用完整的产品路径?
我的 magento 产品链接有问题。当我搜索产品然后单击产品链接时,Magento 将我重定向到本应为index.php/products/grocery/miso-soup/test666.html 的index.php/test666.html。
是否可以强制 Magento 使用产品的完整路径?
添加:
我无法通过启用“使用产品 URL 的类别路径”来使其工作。所以我最终得到了以下代码。
$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";
但我真的不喜欢这种方式。它使用了不必要的资源。有什么想法吗?
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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在管理员中,转到
系统>配置>目录>搜索引擎优化
并设置使用产品URL的类别路径
In the admin, go to
System>Configuration>Catalog>Search Engine Optimizations
and setUse Categories Path for Product URLs
您可能需要刷新“目录 URL 重写”索引。 HTML 也可以从缓存中提供,因此刷新它不会有什么坏处。
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.
另请确保您使用方法
$product->getProductUrl()
来利用上述设置。Also make sure you're using the method
$product->getProductUrl()
to take advantage of the setting mentioned above.我认为搜索结果不会为您提供完整的链接,因为 Magento 允许任何产品属于多个类别。如果您使用搜索框,则无法猜测产品的正确类别。换句话说,一个产品链接可以有多个 URL。
但是,如果您完全确定只为每个产品分配一个类别,则可以更改搜索源代码或进行扩展,以显示每个搜索结果的完整路径的链接。
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.
搜索结果不会为您提供完整链接,因为 Magento 允许任何产品属于多个类别。如果您使用搜索框,则无法猜测产品的正确类别。换句话说,一个产品链接可以有多个 URL。
如果您完全确定只为每个产品分配一个类别,则可以更改搜索源代码或进行扩展,以显示每个搜索结果的完整路径的链接。
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.