2014-10-18 71 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]; 
}