Post by dbdropper » Fri Apr 30, 2021 5:24 pm

Hi everyone,

Here's a piece from system/library/url.php on my Opencart 2.3:

Code: Select all

	public function addRewrite($rewrite) {
		$this->rewrite[] = $rewrite;
	}
The addRewrite() function appends the argument to $this->rewrite, which is the class property of type array. This behaviour is the same on Opencart 3 and, apparently, it will be on Opencart 4 (although there is a known issue with that code, the general idea stays the same).

What is the purpose of having $this->rewrite as an array? I would guess this is so that more rewrites can be added as needed, but my whole Opencart 2 code contains only one addRewrite() call, which happens to be inside catalog/controller/startup/seo_url.php. Any ideas?

User avatar
New member

Posts

Joined
Mon Oct 24, 2016 4:42 pm

Post by straightlight » Fri May 07, 2021 8:56 pm

catalog/controller/startup/seo_url.php file:

Code: Select all

// Add rewrite to url class
		if ($this->config->get('config_seo_url')) {
			$this->url->addRewrite($this);
		}
It adds: $this into the parameter.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by dbdropper » Fri May 07, 2021 9:23 pm

@straightlight Thank you for participating, but unless I'm misreading your answer, unfortunately it doesn't seem to clarify anything for me

User avatar
New member

Posts

Joined
Mon Oct 24, 2016 4:42 pm

Post by straightlight » Fri May 07, 2021 10:08 pm

dbdropper wrote:
Fri May 07, 2021 9:23 pm
@straightlight Thank you for participating, but unless I'm misreading your answer, unfortunately it doesn't seem to clarify anything for me
Just run some tests in your development environment on the platform with the SEOs. You'll see the results.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by dbdropper » Fri May 07, 2021 10:13 pm

straightlight wrote:
Fri May 07, 2021 10:08 pm
dbdropper wrote:
Fri May 07, 2021 9:23 pm
@straightlight Thank you for participating, but unless I'm misreading your answer, unfortunately it doesn't seem to clarify anything for me
Just run some tests in your development environment on the platform with the SEOs. You'll see the results.
Sorry, what tests?

I understand addRewrite() is being used for SEO. No questions about it's purpose.

I am asking why have

Code: Select all

$this->rewrite[] = $rewrite;
instead of simply

Code: Select all

$this->rewrite = $rewrite;

User avatar
New member

Posts

Joined
Mon Oct 24, 2016 4:42 pm

Post by JNeuhoff » Sat May 08, 2021 3:03 am

It's because you can have multiple rewrites. While a standard OpenCart only calls the addRewrite once, there are extensions which use extended SEO rewrite functionality, we have several of them on our sites, such as our CMS-blog. Therefore it's good that the rewrites are stored in an array.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by dbdropper » Thu Sep 30, 2021 4:14 pm

JNeuhoff wrote:
Sat May 08, 2021 3:03 am
It's because you can have multiple rewrites. While a standard OpenCart only calls the addRewrite once, there are extensions which use extended SEO rewrite functionality, we have several of them on our sites, such as our CMS-blog. Therefore it's good that the rewrites are stored in an array.
Got it, thank you for clarifying! Do you happen to know if there's a usage example for this feature posted on Github?

Finding something with search, but not definitive:

User avatar
New member

Posts

Joined
Mon Oct 24, 2016 4:42 pm

Post by straightlight » Thu Sep 30, 2021 6:10 pm

Close to 6 months ...

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by dbdropper » Thu Sep 30, 2021 6:22 pm

straightlight wrote:
Thu Sep 30, 2021 6:10 pm
Close to 6 months ...
I understand this "forum" thinking, but isn't it old school? When Google shows something directly relevant in search results, it doesn't care if it's 6 months old or not. Look at Stack Overflow, 10 year old questions are being answered and updated there.

And am I wrong for asking for clarification simply because I want to learn? Yes, even in 6 months.

Lastly, the rewrite feature in question is still in the core, even in 6 month, and this information may benefit someone else coming from search engines.

So come on, do you really think it was worth to bring it up? You yourself are unnecessarily cluttering the forum after all.

User avatar
New member

Posts

Joined
Mon Oct 24, 2016 4:42 pm

Post by straightlight » Thu Sep 30, 2021 6:25 pm

dbdropper wrote:
Thu Sep 30, 2021 6:22 pm
straightlight wrote:
Thu Sep 30, 2021 6:10 pm
Close to 6 months ...
I understand this "forum" thinking, but isn't it old school? When Google shows something directly relevant in search results, it doesn't care if it's 6 months old or not. Look at Stack Overflow, 10 year old questions are being answered and updated there.

And am I wrong for asking for clarification simply because I want to learn? Yes, even in 6 months.

Lastly, the rewrite feature in question is still in the core, even in 6 month, and this information may benefit someone else coming from search engines.

So come on, do you really think it was worth to bring it up? You yourself are unnecessarily cluttering the forum after all.
Then don't bother yourself on why you do need to use Google if someone needs to wait this long to reply to his own topic since, as you said, on Google, the search result is directly relevant.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by dbdropper » Thu Sep 30, 2021 6:44 pm

straightlight wrote:
Thu Sep 30, 2021 6:25 pm
Then don't bother yourself on why you do need to use Google if someone needs to wait this long to reply to his own topic since, as you said, on Google, the search result is directly relevant.
The thing is other than this thread there was nothing relevant on Google, and the Opencart documentation is lacking. So by asking for examples, my intent was to make the thread helpful for future visitors, and for myself because I hoped to learn from those examples.

Come on man, you're wasting bandwidth and electricity arguing here :) And also flooding, if I remember the correct old, forum-era word for this

User avatar
New member

Posts

Joined
Mon Oct 24, 2016 4:42 pm

Post by straightlight » Thu Sep 30, 2021 6:59 pm

dbdropper wrote:
Thu Sep 30, 2021 6:44 pm
straightlight wrote:
Thu Sep 30, 2021 6:25 pm
Then don't bother yourself on why you do need to use Google if someone needs to wait this long to reply to his own topic since, as you said, on Google, the search result is directly relevant.
The thing is other than this thread there was nothing relevant on Google, and the Opencart documentation is lacking. So by asking for examples, my intent was to make the thread helpful for future visitors, and for myself because I hoped to learn from those examples.

Come on man, you're wasting bandwidth and electricity arguing here :) And also flooding, if I remember the correct old, forum-era word for this
The bandwidth will remain the same on the bills (or quite similar on monthly charge) as the electricity isn't counted by posts. If it had to be by posts, then I am sure nobody would consider to take the risk posting anywhere on the internet especially if 6 months would have to be awaited.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 89 guests