I want to do an automatic replace of spaces and a few other characters e.g. ?, &, / etc in the SEO keyword field when products are created or edited.
This should happen by default but it doesn't.
Can someone point me to where the insert or update for products happens? I can't track it down.
Thanks in advance
This should happen by default but it doesn't.
Can someone point me to where the insert or update for products happens? I can't track it down.
Thanks in advance
As far as index.php?route=, that is already replaced. If you see a / in an SEO url it is simply separating directories. The - that you speak of can be entered manually where you type in the SEO keyword for that product or category.

OK, I'll explain the problem slowly.
If a person has a product named "this is my fabulous product" and they copy and paste it as the SEO keyword it becomes "this%20is%20my%20fabulous%20product". I think we agree that "this-is-my-fabulous-product" is preferable.
So instead of having to manually replace the spaces etc with a - on save (or update) a clever and simple piece of code would be something like
strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $str), '-'));
That's the easy part. Where to put it is what the question was.
Okay I understand now. Yes, that would make sense if you want the "-" as the seperator
That code would go in the model file prior to the INSERT query. Obviously you want to set up a check for strings that have the extra space, and }ELSE{ to the default $data['keyword'] if not.
Here is your variable: $data['keyword']
File: admin/model/catalog/product.php
Insert:
You sound like you know PHP just fine. Get it done!
That code would go in the model file prior to the INSERT query. Obviously you want to set up a check for strings that have the extra space, and }ELSE{ to the default $data['keyword'] if not.
Here is your variable: $data['keyword']
File: admin/model/catalog/product.php
Code: Select all
$new_seo_keyword = strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $str), $data['keyword']));
Code: Select all
if ($data['keyword']) {
$this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($new_seo_keyword) . "'");
}
Last edited by Avvici on Sun Apr 15, 2012 8:53 am, edited 1 time in total.
Thanks almost perfect.
In fact rather than meta-keyword, it was just keyword and it ended up being
to
in 2 places
Hope this helps someone else AND it should be considered for future releases
In fact rather than meta-keyword, it was just keyword and it ended up being
Code: Select all
$this->db->escape($data['keyword'])
Code: Select all
$this->db->escape(strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $data['keyword']), '-')))
Hope this helps someone else AND it should be considered for future releases
Who is online
Users browsing this forum: Majestic-12 [Bot], Semrush [Bot] and 7 guests