如何强制magento使用完整的产品路径?

发布于 2024-09-24 09:27:52 字数 642 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蓝海 2024-10-01 09:27:53

在管理员中,转到系统>配置>目录>搜索引擎优化并设置使用产品URL的类别路径

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

掩于岁月 2024-10-01 09:27:53

您可能需要刷新“目录 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.

十二 2024-10-01 09:27:53

另请确保您使用方法 $product->getProductUrl() 来利用上述设置。

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

再见回来 2024-10-01 09:27:53

我认为搜索结果不会为您提供完整的链接,因为 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.

神也荒唐 2024-10-01 09:27:52

搜索结果不会为您提供完整链接,因为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文