Post by montanaflynn » Tue Dec 15, 2009 4:22 am

Many people have probably used the SEO keyword feature to make their URL's "Pretty" but the default way it works is flawed. URI's are not supposed to have anything but lowercase letters and hyphens, but you can add anything in the SEO keyword input. That means you can use "this is not good!" for the keyword which will turn into "http://www.domain.com/this%20is%20not%20good!" in the browser!

That is why I created an easy front-end fix for this issue with jQuery. All you have to do is add one file to your admin javascript folder and add a small (one line) script to your admin header. Thats it, two steps.

1) Download and add this file into your admin/view/javascript/jquery/ folder with the name slug.js

http://dev.complimedia.com/jquery/slug.js

2) Add this to your admin/view/template/common/header.tpl file right below the other javascript files.

Code: Select all

<script type="text/javascript" src="view/javascript/jquery/slug.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){ 
$("input[name=keyword]").addClass("slug").slug(); 
$(".buttons").clone().appendTo("#content");
}); 
</script>
Of course this is not optimal, because it relies on javascript and not PHP, but it is a step in the right direction and will work the vast majority of the time. If any PHP dev's want to jump into OpenCart and fix this from the back-end then this could be completely avoided.

User avatar
New member

Posts

Joined
Fri Oct 09, 2009 5:19 am

Post by montanaflynn » Thu Dec 17, 2009 6:38 am

Actually this script only changes your SEO keyword input into nicely formatted text without spaces or other symbol characters that should not be in the URL. I would like to add additional functionality like you described but I havn't yet cracked the code, so to speak.

User avatar
New member

Posts

Joined
Fri Oct 09, 2009 5:19 am

Active Member

Posts

Joined
Wed Aug 26, 2009 8:54 am
Location - Sweden

Post by migz » Tue Feb 09, 2010 2:31 pm

This doesn't work on Opencart 1.4.0. Any suggestions?

Active Member

Posts

Joined
Mon Feb 01, 2010 2:13 am

Post by AndyGaskell » Wed Mar 03, 2010 6:50 am

I had an idea for this that I just tried out, it kind of addresses...
migz wrote:This doesn't work on Opencart 1.4.0. Any suggestions?
...and also...
montanaflynn wrote:Of course this is not optimal, because it relies on javascript and not PHP
Though I agree with...
Qphoria wrote:This isn't really a fix.. more like a new feature.. it auto-enters the seo keyword for you.
So, sorry for the mass quotes at the beginning, now that is out of the way, I had a thought about adding a "auto seo keyword" feature. I though this might be easy to do in the validation phase, as this is used by edits and adds of products. I want to use the friendly URLs on a shop I'm working on, but the shopkeppers are not so tech savy, so I wanted to make it easier for them. Also, there are nearly 20,000 products, so any time-saver is good. Sorry, will cut to the chase. By adding a few lines to the validateForm function in admin/controller/catalog/product.php we can auto generate the keywords from the product name and id. Disclaimer first though, this is v ugly at the mo, and I'll tidy it up, but while I was reading this post, and before I forget I thought I'd chuck it into the thread.

Code: Select all

# add a default keyword
if (strlen(utf8_decode($this->request->post['keyword'])) < 3) {
    # pull the value           
    $temparr = $this->request->post['product_description'];
    # get the string from the big multi language and field array
    $tempstr = $temparr[1]['name'];
    # decode and tidy it
    $tempstr = utf8_decode($tempstr);
    $tempstr = str_replace( " ", "_", $tempstr );
    # add the product id
    $tempstr = $tempstr . "_" . $this->request->get['product_id'];
    # save it back 
    $this->request->post['keyword'] = $tempstr;
}    
This is on 1.4 by the way. Not intended as code for sharing (too ugly, particularly that language hack) but just to get some thoughts and feedback on the general idea.

Andy

I'm a web developer at http://www.ssofb.co.uk in Aberdeen, Scotland.
Got a random blog at http://www.andygaskell.blogspot.com/.


User avatar
New member

Posts

Joined
Thu Dec 10, 2009 3:59 am
Location - Aberdeen UK
Who is online

Users browsing this forum: No registered users and 4 guests