如何解决两个类别/产品在Opencart中具有相同网址的问题?或者,如果他们是一个已经这样做的模块?
例如:类别
Ladies -> Trousers (URL: ladies/trousers)
Mens -> Trousers (URL: mens/trousers)
这打破了Opencart,因为我们有两个子类别,URL =裤子?
答案 0 :(得分:4)
我知道这是一个迟到的答案,但这是OpenCarts架构的一个根深蒂固的问题。
就我个人而言,我不是vQmod的粉丝,所以这里有一个(有些人称之为黑客攻击)解决问题而不使用它。
我看到catalog/controller/common/seo_url.php
添加了自定义搜索引擎优化的许多更改。此修复程序与此类修改兼容。
我还想补充一点,这绝不是世界上最复杂的解决方案,但它可以保证具有重复seo url条目的子类别能够正常工作。
在catalog/controller/common/seo_url.php
if ($url[0] == 'category_id') {
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $url[1];
} else {
$this->request->get['path'] .= '_' . $url[1];
}
}
替换为以下
if ($url[0] == 'category_id') {
$categories[$i] = $this->model_catalog_category->getCategory($url[1]);
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $categories[$i]['category_id'];
} else {
foreach ($query->rows as $row) {
$url = explode('=', $row['query']);
$category_id = $url[1];
$category = $this->model_catalog_category->getCategory($category_id);
if ($category['parent_id'] == $categories[$i - 1]['category_id']) {
$this->request->get['path'] .= '_' . $category['category_id'];
}
}
}
}
将以下行添加到方法索引()
的顶部$this->load->model('catalog/category');
找到行......
foreach ($parts as $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
并替换为以下
$categories = array();
for ($i = 0; $i < count($parts); $i++) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($parts[$i]) . "'");
答案 1 :(得分:0)
我为那个确切的场景开发了this vqmod
答案 2 :(得分:0)
我已经解决了这个问题,我已经制作了一个vqmode xml文件
请参阅opencart,为下面的网址提供相同的结果
http://mycart/mp3-players/iPod-Classic
http://mycart/mp3-players/some-child/iPod-Classic
http://mycart/some-parent/mp3-players/iPod-Classic
http://mycart/iPod-Classic
很难对该产品“iPod-Classic”进行搜索引擎优化
所以我用这个脚本编写一个“vqmod”脚本,你可以将用户重定向到一个特定的正确页面
即使是用户输入了错误的网址
即
http://mycart/mp3-players/dddfsdgf/sdf/sdf/iPod-Classic
它会自动将其重定向到
http://mycart/mp3-players/iPod-Classic
你只需要从“方框”或
下载'controller_common_seo_url.xml' <modification>
<id>public function index() add more functions</id>
<version>1.0</version>
<vqmver>2.1.5</vqmver>
<author>http://www.bhardwajabhi.wordpress.com</author>
<file name=”catalog/controller/common/seo_url.php”>
<operation>
<search position=”before”><![CDATA[ public function index() { ]]></search>
<add><![CDATA[
public function get_seo_title($id, $type)
{
$query = $this->db->query("SELECT keyword FROM " . DB_PREFIX . "url_alias WHERE query = '". $type ."=" . (int)$id . "'");
if($query->row)
return $query->row['keyword'];
else
return $id;
}
public function get_path_level($id)
{
$query = $this->db->query(“select `level` from ” . DB_PREFIX . “category_path where `category_id` = ‘”. $id. “‘ order by level desc LIMIT 1″);
return $query->row['level'];
}
public function get_product_relative($parts, $product_id)
{
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == ‘on’) || ($this->request->server['HTTPS'] == ’1′))) {
$this->data['base'] = $this->config->get(‘config_ssl’);
} else {
$this->data['base'] = $this->config->get(‘config_url’);
}
$path = $this->get_seo_title($product_id, ‘product_id’);
$query = $this->db->query(“SELECT category_id FROM ” . DB_PREFIX . “product_to_category WHERE product_id = ‘” . (int)$product_id . “‘”);
$i =0;
foreach($query->rows as $pro_cat):
$i++;
$sub_query = $this->db->query(“select `path_id` from ” . DB_PREFIX . “category_path where `category_id` = ‘”. $pro_cat['category_id']. “‘ order by level desc”);
foreach($sub_query->rows as $pro_sub_cat):
$path = $this->get_seo_title($pro_sub_cat['path_id'], ‘category_id’) . “/” . $path;
endforeach;
$path1 = ‘/’. $path;
$array1 = explode(‘/’, $path1);
$array2 = explode(‘/’, $this->request->get['_route_']);
$result = array_diff($array1, $array2);
$new_path[$i]['path'] = $path;
$new_path[$i]['count'] = count($result);
$path = $this->get_seo_title($product_id, ‘product_id’);
endforeach;
$min = PHP_INT_MAX;
$max = 0;
foreach ($new_path as $i) {
$min = min($min, $i['count']);
}
foreach($new_path as $value):
if($value['count']==$min):
$final_path = $value['path'];
break;
endif;
endforeach;
similar_text($this->request->get['_route_'], $final_path, $percent);
if($percent<>100)
header (‘location:’ . $this->data['base'] .”. $final_path);
}
]]></add>
</operation>
</file>
<file name=”catalog/controller/common/seo_url.php”>
<operation info=”After ABC, add 123″>
<search position=”after”><![CDATA[
$this->request->get['product_id'] = $url[1];
]]></search>
<add><![CDATA[
/*Start url redirection*/
$this->get_product_relative($parts, $url[1]);
/*End Url Redirection*/
]]></add>
</operation>
</file>
</modification>
现在是这样的,当有人点击任何产品时,购物车会显示如
的页面http://www.yourSiteUrl/parent-category/child-category/product
注意:你必须为每个类别,子类别和产品提供seo标题,因为脚本搜索seo标题,如果seo标题不可用,那么它给它id,所以假设我们没有给出seo-title子类别和vew其产品然后网址将像
http://www.yourSiteurl/parent-category/56/product
您可以在here
上获得有关它的更多详细信息答案 3 :(得分:0)
if ($url[0] == 'category_id') {
$categories[$i] = $this->model_catalog_category->getCategory($url[1]);
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $categories[$i]['category_id'];
} else {
foreach ($query->rows as $row) {
$url = explode('=', $row['query']);
$category_id = $url[1];
$category = $this->model_catalog_category->getCategory($category_id);
if ($category['parent_id'] == $categories[$i - 1]['category_id']) {
$this->request->get['path'] .= '_' . $category['category_id'];
}
}
}
}
如果它是3级别的话,这将不起作用。我希望有人能有更好的解决方案。
答案 4 :(得分:0)
除了@Ian Brindley之外,您还应该编辑另外两个文件,以便在管理面板中输入关键字:
Admin/Controller/Catalog/category.php
在方法validateForm
if (utf8_strlen($this->request->post['keyword']) > 0) {
$this->load->model('catalog/url_alias');
$url_alias_info = $this->model_catalog_url_alias->getUrlAlias($this->request->post['keyword']);
if ($url_alias_info && isset($this->request->get['category_id']) && $url_alias_info['query'] != 'category_id=' . $this->request->get['category_id']) {
$this->error['keyword'] = sprintf($this->language->get('error_keyword'));
}
if ($url_alias_info && !isset($this->request->get['category_id'])) {
$this->error['keyword'] = sprintf($this->language->get('error_keyword'));
}
if ($this->error && !isset($this->error['warning'])) {
$this->error['warning'] = $this->language->get('error_warning');
}
}
并将其更改为:
if (utf8_strlen($this->request->post['keyword']) > 0) {
$this->load->model('catalog/url_alias');
$url_alias_info = $this->model_catalog_url_alias->getUrlAlias($this->request->post['keyword']);
if ($url_alias_info && !isset($this->request->get['category_id'])) {
$this->error['keyword'] = sprintf($this->language->get('error_keyword'));
}
if ($this->error && !isset($this->error['warning'])) {
$this->error['warning'] = $this->language->get('error_warning');
}
}
如果seo关键字是重复的,这将解除检查。这样您就可以在 adminpanel 中输入seo关键字,而不是 phpmyadmin