Post by olga » Tue Oct 06, 2020 10:26 pm

Hello, I have some issues with the SEO links on my opencart site, specific with my DEFAULT opencart pages like "contact us"

► I have enables SEO from Settings⇾ Server⇾ Use SEO URLs
► I have cleared the Cache
► and I created new entry in Design⇾ SEO URL (e.g. for contact us page) see settings bellow

Query 1
Query⇾ information/contact
Keyword⇾ contact-us
Language⇾ English

Query 2
Query⇾ information/contact
Keyword⇾ επικοινωνία
Language⇾ Greek

So when I click on a link, that suppose to go to contact us, the page has the default URL (MVC style URL) and not the SEO URL that I declared.
When I'm writing the URL my self, like "domain.com/contact-us" the URL works perfectly.

What is happening ? I'm new to opencart, so I don't know what else I can do.

General Information
OC Version: 3.0.3.6
Theme: Journal 3
Note: Multilingual Site (2 Languages)

Thank you in advance,
Olga

Newbie

Posts

Joined
Tue Jul 07, 2020 9:18 pm

Post by letxobnav » Tue Oct 06, 2020 11:28 pm

Default OC can translate seo keywords to a route, it just does not translate a route to a keyword.
In order to do that you need to add code to catalog/controller/startup/seo_url.php

you change this:

Code: Select all

				} elseif ($key == 'path') {
					$categories = explode('_', $value);

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

					unset($data[$key]);
				}
to this:

Code: Select all

				} elseif ($key == 'path') {
					$categories = explode('_', $value);
					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;
						}
					}
					unset($data[$key]);
				} elseif (!in_array($data['route'],array('common/language/language','common/currency/currency','product/product','product/category','product/manufacturer/info','information/information'))) {
					// all other cases for just route settings & eliminating unnecessary queries
					if ($key == 'route') {
						// no need to query root
						if ($value == 'common/home') {
							$url = '/';
						} else {
							$sql = "SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . $this->config->get('config_language_id') . "'";
							$query = $this->db->query($sql);
							if ($query->num_rows) {
								if ($url != '/') $url .= '/';
								$url .= $query->row['keyword'];
								unset($data[$key]);
							}
						}
					}
				}
then it also writes the seo url for just routes like information/contact, account/register, etc.
It also removes the index.php?route=common/home from the home page.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by olga » Wed Oct 07, 2020 3:05 pm

I will give it a try! Thank you for your answer :)

Newbie

Posts

Joined
Tue Jul 07, 2020 9:18 pm

Post by katalin » Fri Jan 20, 2023 11:53 pm

letxobnav wrote:
Tue Oct 06, 2020 11:28 pm
Default OC can translate seo keywords to a route, it just does not translate a route to a keyword.
In order to do that you need to add code to catalog/controller/startup/seo_url.php

you change this:

Code: Select all

				} elseif ($key == 'path') {
					$categories = explode('_', $value);

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

					unset($data[$key]);
				}
to this:

Code: Select all

				} elseif ($key == 'path') {
					$categories = explode('_', $value);
					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;
						}
					}
					unset($data[$key]);
				} elseif (!in_array($data['route'],array('common/language/language','common/currency/currency','product/product','product/category','product/manufacturer/info','information/information'))) {
					// all other cases for just route settings & eliminating unnecessary queries
					if ($key == 'route') {
						// no need to query root
						if ($value == 'common/home') {
							$url = '/';
						} else {
							$sql = "SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . $this->config->get('config_language_id') . "'";
							$query = $this->db->query($sql);
							if ($query->num_rows) {
								if ($url != '/') $url .= '/';
								$url .= $query->row['keyword'];
								unset($data[$key]);
							}
						}
					}
				}
then it also writes the seo url for just routes like information/contact, account/register, etc.
It also removes the index.php?route=common/home from the home page.
Hello, I tried this on OC 3.0.3.8 with Journal3 and it's not working. Any other fix?

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by by mona » Sat Jan 21, 2023 1:05 am

katalin wrote:
Fri Jan 20, 2023 11:53 pm
Hello, I tried this on OC 3.0.3.8 with Journal3 and it's not working. Any other fix?
https://support.journal-theme.com
viewforum.php?f=88

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


Spinning Social : Links : Menus : Payments : Socials : Ads : Screen Backgrounds : Galleries : Headers : Banners : Promos


Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am
Who is online

Users browsing this forum: No registered users and 4 guests