Post by Monarchy Catering » Sat May 23, 2020 1:34 am

OC: 3.0.3.3, Php 7.3, Apache.

Set my site live and ging through some system checks to reveal that the 'canonical' and sitemap.xml are show the URLs of the products without category information, e.g.

"https://www.example.com/austria/beer/glasses.html" - but canonical and sitemap show as "https://www.example.com/glasses.html".

Check the Header Status, shows a 301 redirect, so not brilliant.

If I copy "https://www.example.com/glasses.html" into the browser its directs to the correct page. Should I be using any Extensions as I've INSERTED all the SEO URL in the database directly.

I understand why the canonical is just the page name ('query' field) as they are defined as such in the SEO URL database. Should the 'query field entry have the categories listed as well as the page? But then have does that effect the functionality of the categories in relation to standard OpenCart URL rendering?

Rreally confused by his one as what to do.

Thanks.

New member

Posts

Joined
Sat Oct 28, 2017 11:52 pm

User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Monarchy Catering » Sat May 23, 2020 2:25 am

JNeuhoff wrote:
Sat May 23, 2020 2:15 am
So what exactly is the problem?
Actual URL is "https://www.example.com/austria/beer/glasses.html", with Austria (parent menu) and Beer (sub-menu), but canonical and sitemap show as "https://www.example.com/glasses.html", when it should be outputing the same URL.

Looking at examples I'm now thinking that the 'keyword' should contain the qualified URL with categorries and page detail, e.g. 'query' product_id=1 and 'keyword' for a unique product page - 'austria/beer/glass1.html'.
Does that mean there's an option to stop OpenCart from automatically appending the categories to the url, otherwises the categories appear twice in the qualified URL.

Thanks.

New member

Posts

Joined
Sat Oct 28, 2017 11:52 pm

Post by letxobnav » Sat May 23, 2020 11:35 am

It all depends on how many paths you advertise to reach unique page glasses.html and which path you would like to get indexed.

Normally https://www.example.com/glasses.html is the correct canonical for https://www.example.com/austria/beer/glasses.html as you can get to glasses.html either way and in OC you can actually put the same product under multiple categories creating multiple paths to the same page so a canonical stripped of the categories is the best choice.

But if you want the canonical for glasses.html to be https://www.example.com/austria/beer/glasses.html, then fine but then you would also have to use that canonical for https://www.example.com/glasses.html and any other path you advertise to reach glasses.html.

So in the product controller you would now have to determine the category and parent category of the product and add those to the canonical url which is a pain when you add that product under multiple categories, which to choose?
Same applies to the google sitemap feed, that also does not take the path into account.

ps. lose the .html part, useless.

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 Monarchy Catering » Sat May 23, 2020 4:08 pm

letxobnav wrote:
Sat May 23, 2020 11:35 am
It all depends on how many paths you advertise to reach unique page glasses.html and which path you would like to get indexed.

Normally https://www.example.com/glasses.html is the correct canonical for https://www.example.com/austria/beer/glasses.html as you can get to glasses.html either way and in OC you can actually put the same product under multiple categories creating multiple paths to the same page so a canonical stripped of the categories is the best choice.

But if you want the canonical for glasses.html to be https://www.example.com/austria/beer/glasses.html, then fine but then you would also have to use that canonical for https://www.example.com/glasses.html and any other path you advertise to reach glasses.html.

So in the product controller you would now have to determine the category and parent category of the product and add those to the canonical url which is a pain when you add that product under multiple categories, which to choose?
Same applies to the google sitemap feed, that also does not take the path into account.

ps. lose the .html part, useless.
Thanks for your reply.

I'm looking to impliment 1 unique URL for each individual Product with Categories (and sub-cats) prefixing the actual page name. Each Product only appears in a single Category (sub-cat). If you hover over the Product in the Categories, the get a different URL with Categories pre-fixed.
Currently is not possible as the "SEO URL keyword" would conflict with the OC URL construction of appending Categories,i.e. doubling of the Categories in the Product URL.

I like the .html as it tells everybody that they have reached the bottom of the tree. All my websites work this way :)

Thanks for any advice as I'm lost as SEO is about structure and houskeeping.
https://www.monarchycatering.com/new

P.S. also ?manufacturer_id=59 appended to the same product URLs appear in the sitemap. How can that be disabled please?

I'm really loathed to dive into changing core code as I know an update will over-write my changes.
Last edited by Monarchy Catering on Sat May 23, 2020 7:59 pm, edited 1 time in total.

New member

Posts

Joined
Sat Oct 28, 2017 11:52 pm

Post by letxobnav » Sat May 23, 2020 7:56 pm

SEO is about structure and houskeeping
True but canonical is all about choices and consistency.

There is no issue with seo urls here.
Currently the product canonical is created in controller product/product via

Code: Select all

$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
that is without category paths.

All you have to do is add that path if your choice it to have it with.
If you get to that controller via the categories (menu), you already have the path in your get variables, if not (via search or some other module), you have to retrieve it.

I use these functions (not for canonical but for making my breadcrumbs more meaningful, a breadcrumb with only home and a product is meaningless)

Code: Select all

	// retrieve category id for product assuming product has a single category or it will take the first one
	public function getCategoryIdFromProductId($product_id) {
		$query = $this->db->query("SELECT category_id FROM oc_product_to_category WHERE product_id = '" . (int)$product_id . "' ORDER by category_id DESC");
		if ($query->num_rows) return $query->row['category_id'];
		else return false; 
	}
	// retrieve parent category id of category
	public function getCategoryParentId($category_id) {
		$query = $this->db->query("SELECT parent_id FROM oc_category WHERE category_id = '" . (int)$category_id . "' ORDER by parent_id DESC");
		if ($query->num_rows) return $query->row['parent_id'];
		else return false; 
	}
	// retrieve category path for product
	public function getProductPath ($product_id) {
		if ($category_id = $this->getCategoryIdFromProductId($product_id)) {
			$path = $category_id;
			if ($parent_id = $this->getCategoryParentId($category_id)) $path = $parent_id . '_' . $path;
			return $path;
		}
		return false;
	}


Then for canonical you can use:

Code: Select all

		// get and set the product category path if not already present in get variables of the page to set canonical
		if (!isset($this->request->get['path]'])) {
			// retrieve the product path
			$retrieved_product_path = $this->getProductPath($this->request->get['product_id']);
			if ($retrieved_product_path) {
				// has one
				$this->document->addLink($this->url->link('product/product', 'path='.$retrieved_product_path.'&product_id=' . $this->request->get['product_id']), 'canonical');
			} else {
				// has none
				$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
			}
		} else {
			// already has one
			$this->document->addLink($this->url->link('product/product', 'path='.$this->request->get['path'].'&product_id=' . $this->request->get['product_id']), 'canonical');
		}
		
that would make your product page canonical always domain/parent-category/child-category/product regardless of how you got to the product 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 Monarchy Catering » Tue May 26, 2020 4:05 pm

Brilliant thanks for your help and advice.

New member

Posts

Joined
Sat Oct 28, 2017 11:52 pm

Post by paulfeakins » Tue May 26, 2020 6:51 pm

It might be worth buying an SEO extension that does this.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by Monarchy Catering » Sun May 31, 2020 12:34 am

paulfeakins wrote:
Tue May 26, 2020 6:51 pm
It might be worth buying an SEO extension that does this.
Thanks for the reply :) I just think feel that after migrating from Magento 1.9.x to an ultimately mature product, multi-language should be handled a little bit better. I understand the drive to supply extensions, but this basic usage for a multi-language system. It's not like I'm trying to re-invent the wheel.
I love OC because of the ease of tailoring a solution and adding those little bespoke touches.

The solution to change the page names to reflect the language is wrong on so many technical / SEO levels. The default behaviour should be to append the language code to the domain name when any language pack is installed. More consistent with other systems and improves url readability.

Please don;t get me wrong, as a single languae shopping system OC is fantastic and have used many times and will continue to use. I have spent 2 weeks on this now and see no clean way of getting it right.

Thanks and all stay safe.

New member

Posts

Joined
Sat Oct 28, 2017 11:52 pm
Who is online

Users browsing this forum: thekrotek and 38 guests