Opencart duplicate URL keywords

前端 未结 5 1064
天涯浪人
天涯浪人 2020-12-20 01:36

How would I go about fixing the issue where two categories/products have the same URL in Opencart? Or if their is a module which already does this?

E.g: categories

5条回答
  •  不思量自难忘°
    2020-12-20 02:07

    I know this is a late answer, but this is a deep rooted problem with OpenCarts architecture.

    Personally I am not a fan of vQmod, so here is a (what some would call a hack) solution to the problem without using one.

    I have seen many alterations to catalog/controller/common/seo_url.php that add custom seo urls. This fix is compatible with such modifications.

    I would also like to add that is by no means the most sophisticated solution in the world but it will guarantee that sub categories with duplicate seo url entries will work as they should.

    Find in 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];
        }
    }
    

    Replace with the following

    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'];
                }
            }
        }
    }
    

    Add the following line to the top of the method index()

    $this->load->model('catalog/category');
    

    Find the line...

    foreach ($parts as $part) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
    

    And replace with the following

    $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]) . "'");
    

提交回复
热议问题