Post by sukhbirgs » Wed Feb 28, 2018 5:42 am

Hello, i have a custom download module that have same structure as categories. Main category and then subcategory and so on. I was trying to implement seo url for this mod. So for testing i added few links in url_alias table.

Opencart Version 2.3.0.2

download_category_id=2 testdownload
download_category_id=178 manuals

In this case category with id 2 is sub category of 178.

Edited startup/seo_url.php [ copy category code and modified ]

public function index() {

Code: Select all

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] == 'download_category_id') {
       if (!isset($this->request->get['dpath'])) {
                $this->request->get['dpath'] = $url[1];
         } else {
                 $this->request->get['dpath'] .= '_' . $url[1];
         }
}

Code: Select all

if (!isset($this->request->get['route'])) {
				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';
				}elseif (isset($this->request->get['dpath'])) {
                    $this->request->get['route'] = 'download/download_category';
                }
			}
public function rewrite($link) {

Code: Select all

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 && $query->row['keyword']) {
			$url .= '/' . $query->row['keyword'];
		} else {
			$url = '';
			break;
		}
	}
   unset($data[$key]);
}elseif ($key == 'dpath') {
       $categories = explode('_', $value);
        foreach ($categories as $category) {
               $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'download_category_id=" . (int)$category . "'");
                if ($query->num_rows && $query->row['keyword']) {
                     $url .= '/' . $query->row['keyword'];
                     } else {
                            $url = '';
                            break;
                    }
           }
    unset($data[$key]);
}

This builds my seo url but i get page not found.
Url : www.mydomain.com/manuals/testdownloads
This url is correct, but page is not found. So i did print on url_info array in rewrite function.

For categories i get

Code: Select all

Array
(
    [scheme] => https
    [host] => www.mydomain.com
    [path] => /index.php
    [query] => route=product/category&path=76
)
For Download Categories

Code: Select all

Array
(
    [scheme] => https
    [host] => www.mydomain.com
    [path] => /index.php
    [query] => route=download_category_id=2&dpath=178_2
)
download_category_id=2 should be download/download_category

What i am missing or doing wrong, any help would be appreciated.
Thanks

Newbie

Posts

Joined
Sat Oct 01, 2016 5:24 am

Post by sukhbirgs » Wed Feb 28, 2018 6:11 am

Sorry for long post, going over the code found 1 place that i missed .

if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'download_category_id' && $url[0] != 'product_id')

this was missing, after adding this its working.

Newbie

Posts

Joined
Sat Oct 01, 2016 5:24 am
Who is online

Users browsing this forum: grgr and 16 guests