4

在我的商店中,其中一个类别只有一种产品。每当用户在导航栏中单击此类别时,是否可以直接将用户带到该产品的产品详细信息页面?

4

3 回答 3

7

是的,这可以通过使用Magento Admin中的URL Rewrite Management选项来完成。

在 Magento 管理员中:

  1. 从菜单栏Catalog > URL Rewrite Management中选择。
  2. 单击添加 URLRewrite按钮。
  3. 选择要从中重定向的类别。
  4. 记下ID 路径(例如:category/10)和请求路径(例如:flowerpots.html
  5. 重复步骤1 和 2,但这次从Create Urlrewrite下拉框中选择Custom 。
  6. 在每个字段中输入值:

    • ID 路径(从第 4 步开始)
    • 请求路径(从第 4 步开始)
    • 目标路径- 输入产品的路径(或要重定向到的页面)。
      • 示例 1:对于产品网址www.myswebsite.co.uk/flowers.html输入flowers.html
      • 示例 2:对于产品网址www.myswebsite.co.uk/sale/garden/flowers.html输入sale/garden/flowers.html
  7. 重定向下拉列表中选择永久重定向 (301) 。

  8. 节省。

现在,当在您的网站上单击该类别时,它将重定向到该产品。

于 2011-07-30T06:48:22.647 回答
0

这可以通过将代码添加到主题文件夹中的页面模板来以编程方式完成,该文件夹被称为显示类别。在此处查看完整的解决方案 - http://www.codeboss.in/web-funda/2015/01/30/magento-auto-redirect-to-product-details-page-if-category-have-only-one-product /

于 2015-01-30T23:44:30.637 回答
0

按照步骤:

  1. 打开分配给类别页面的页面模板。您将在主题目录的“template/page/”文件夹下找到它。例如,让我们假设页面是 1column.phtml(用于单列布局)。

  2. 就在线条之后

/** * Mage_Page_Block_Html 的模板 */

  1. 添加以下代码:
<?php 
$product = Mage::registry('current_product');
if($product == ''){
$category = Mage::registry('current_category');
if(is_object($category)){
$catLoaded = Mage::getModel('catalog/category')->load($category->getEntityId());
 $collection = $catLoaded->getProductCollection();
$collection->addAttributeToSelect('*');
if(count($collection) == 1){
foreach($collection as $product){
 $productUrl = $product->getProductUrl();
 header("location:$productUrl");
 exit;
  }
 }
 }
} 
?>
于 2016-10-07T06:46:13.083 回答