Skip to content
Menu
WebHero | Yahya Mohammadi | Blog
  • Home
  • Web Development
  • Entertainment
WebHero | Yahya Mohammadi | Blog

Opencart Root Categories SEO URLs Not Working When Path Contains Zero [SOLVED]

Posted on June 1, 2019June 1, 2019

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,

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Popular Posts

  • How I built webhero.ir
    January 20, 2019
    I challenged myself to produce a flawless portfolio which has maximum optimization in performance, accessibility and page speed. I did the following steps to achieve the goals I had in my mind!

  • Game of Thrones Season 8 Episode Run Times Reportedly Revealed
    January 23, 2019
    Form unofficial sources it has been reported the final four episodes of Game of Thrones will be as long as a feature film.

  • After a very long absence Opencart is back!
    January 28, 2019
    Almost a year and a half have passed since Opencart has released its 3.0.2.0 version and the failed 3.1.0.0 version!

Recent Posts

  • Opencart Oc blog SEO URL and keyword issue [solved]
  • The CV has been updated!
  • OC blog for Opencart 3.x and up
  • Opencart Root Categories SEO URLs Not Working When Path Contains Zero [SOLVED]
  • After a very long absence Opencart is back!

Categories

  • Entertainment
  • Web Development

Archives

  • January 2020
  • December 2019
  • June 2019
  • January 2019

Most Tags

blog CV ecommerce game-of-thrones GitHub hbo job opencart page-speed seo seo-urls tv-series ui version-update web-design web-development

Social Login

Continue with Google

Sorted By Months

  • January 2020
  • December 2019
  • June 2019
  • January 2019

Topics

  • Entertainment
  • Web Development

Qoutes

“Truth can only be found in one place: the code.”
― Robert C. Martin

©2023 WebHero | Yahya Mohammadi | Blog | Powered by SuperbThemes & WordPress