2014-10-18 72 views
0

对我店的产品现在的网址是这样的:Opencart的:如何使产品的网址以全品类路径

example.com/category1/product1

example.com/category1/subcategory1/product1

它是一个和相同的产品只分配到2个类别。 URL取决于你是否从cateogry1子类别1

我想迫使opencart总是去example.com/category1/subcategory1/product1(最深的子类别)。

你知道该怎么做吗?我没有找到任何扩展名。我可能不得不改变/catalog/controller/common/seo_url.php,但我不知道要改变什么,我不想制动它。

我在OpenCart 1.5.6上运行。

+0

http://www.opencart.com/index.php?route=extension/extension/info&extension_id=5023 – 2014-10-18 21:34:14

+0

@JayGilford谢谢,但有还有任何免费解决方案我认为我需要的只是在seo_url.php – matlos 2014-10-18 22:15:11

+0

可能的重复[产品的不同链接对seo有益或有害?]中的一些小改动(http://stackoverflow.com/questions/14697968/different-links-for-一个副产物 - 是益 - 或有害换SEO) – shadyyx 2014-10-20 08:42:31

回答

1

转到管理面板并打开类别表单并删除类别和子类别的关键字。

然后您将获得该类别的完整路径。

0

您需要添加一些代码才能做到这一点,而不需要扩展名。

在控制器/ seo_url.php添加此功能

public function getFullProductPath($product_id) { 

    $path = array(); 
    $categories = $this->db->query("SELECT c.category_id, c.parent_id FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "category c ON (p2c.category_id = c.category_id) WHERE product_id = '" . (int)$product_id . "'")->rows; 

    foreach($categories as $key => $category) 
    { 
     $path[$key] = ''; 
     if (!$category) continue; 
     $path[$key] = $category['category_id']; 

     while ($category['parent_id']){ 
      $path[$key] = $category['parent_id'] . '_' . $path[$key]; 
      $category = $this->db->query("SELECT category_id, parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . $category['parent_id']. "'")->row; 
     } 

     $path[$key] = $path[$key]; 
    } 

    if (!count($path)) return ''; 

    // wich one is the largest ? 
    $whichone = array_map('strlen', $path); 
    asort($whichone); 
    $whichone = array_keys($whichone); 

    $whichone = array_pop($whichone); 

    return $path[$whichone]; 
}