OC 1.5.6
我已经安装了一个模块来根据制造商过滤类别的产品。
我可以通过以下网址覆盖每个“搜索结果页”:
example.com/index.php?route=product/category&path=X&manufacturer=Y
我想创建一个SEO网址,如:
example.com/alias-for-category/alias-for-manufacturer
(例如/ bikes / honda或/ cars / bmw)
但我无法弄明白该怎么做。
我尝试过测试和简化只转换一个网址:
product/category&path=1&manufacturer=1
所以我使用此查询和关键字
添加了url_alias
条记录
cat1-man1
然后我修改了catalog/common/seo_url.php
功能指数
if (isset($this->request->get['product_id'])) {
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path'])) {
$this->request->get['route'] = 'product/category';
} elseif (isset($this->request->get['manufacturer_id'])) {
$this->request->get['route'] = 'product/manufacturer/info';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = 'information/information';
}
//ADDED BELOW CODE TO ROUTE ALL URL
else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($this->request->get['_route_']) . "'");
if ($query->num_rows) {
$this->request->get['route'] = $query->row['query'];
}
}
和函数重写
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
} elseif ($key == 'path') {
$categories = explode('_', $value);
foreach ($categories as $category) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
}
}
unset($data[$key]);
}
//ADDED CODE BELOW TO CONVERT ALL URL
else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($data['route']) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
}
但此简化版本根本不起作用,显示未找到页面。
我做错了什么?任何小费都会非常感激
答案 0 :(得分:0)
首先,我安装的自定义模块要求制造商的参数为“manufacturer”而不是“manufacturer_id”,因此转换后的网址如下:
example.com/index.php?route=product/category&path=X&manufacturer_id=Y
模块未正确处理。
所以我的问题的答案是:OC已经将alias-cat / alias-manufacturer转换为正确的内部网址
另一方面,OC不会转换类型的网址
example.com/index.php?route=product/category&path=X&manufacturer_id=Y
进入SEO友好网址,如:
example.com/alias-for-category/alias-for-manufacturer
在菜单或链接中,为此,请修改catalog/common/seo_url.php
,如下所示:
public function rewrite($link) {
$url_info = parse_url(str_replace('&', '&', $link));
$url = '';
$data = array();
parse_str($url_info['query'], $data);
foreach ($data as $key => $value) {
if (isset($data['route'])) {
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
} elseif ($key == 'path') {
$categories = explode('_', $value);
foreach ($categories as $category) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
}
}
unset($data[$key]);
}
// ADD THIS CODE
elseif ($key == 'manufacturer_id') {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'manufacturer_id=" . (int)$value . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
}
unset($data[$key]);
}
// END ADDED CODE----------------
else {
.....