As I built one of my recent online shopping projects with Opencart, I’ve found that on Opencart URLs for root categories there is a zero in path variable which breaks SEO URL functioning.
The problem occurs in line 90 of catalog\controller\startup\seo_url.php inside the foreach loop. When you don’t have a category with the ID of Zero it breaks!
foreach ($categories as $category) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); if ($query->num_rows && $query->row['keyword']) { $url .= '/' . $query->row['keyword']; } else { $url = ''; break; } }
The simple fix for this is to add an IF condition which checks the zero ID and just to replace above code with this:
foreach ($categories as $category) {
if ($category == 0){
$url .= '';
}else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
if ($query->num_rows && $query->row['keyword']) {
$url .= '/' . $query->row['keyword'];
} else {
$url = '';
break;
}
}
}
Hope it helps you in your projects.
Cheers,