我店里的产品现在有这样的URL:
example.com/category/product1
或
example.com/category/subcategory/product1
它是同一种产品,只分为两类。URL取决于您是从类别1还是子类别1。
我想强制opencart始终转到example.com/category1/subcategory1/product1
(最深的子类别)。
你知道怎么做吗?我没有找到任何扩展。我可能不得不更改/catalog/controller/common/seo_url.php
,但我不确定该更改什么,我不想刹车。
我在OpenCart 1.5.6上运行。
转到管理面板并打开类别窗体,删除类别和子类别的seo关键字。
然后您将获得该类别的完整路径。
您需要添加一些代码来实现这一点,而不需要扩展。
在controller/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];
}