Jump to content

Duplicated Friendly Url (Link_Rewrite) Issue


Recommended Posts

Hi.

 

I noticed that if i have 2 items that have the same Friendly URL (in the database it called link_rewrite field), even if both are located under different categories, when clicking on the image of the product on the list page, it takes you to the first item from the two, no matter what.

 

So i made a script to fix all the table's field link_rewrite (located under ps_product_lang). This script adds the category name before the item's ID. So AB1234 will be CAT1-AB1234 and CAT2-AB1234.

 

This is working great, but, i want to do the change also for future uploading.

 

How and where should i get the function that placing the value to link_rewrite?

 

Thanks.

 

p.s. If someone needs the function i used to fix an existing bug, see attached file. Upload to root and run it with browser. (www.yourdomain.com/php_process.php) Be careful if you are using any signs or symbols in the product category name (for example Shail K. - the dot will make issues.) so i fixed only the dot issue... You can modify it for better use.

php_process.php

Edited by Yossefelbaz (see edit history)
Link to comment
Share on other sites

OK, i found solution.

When i am typing now the name of the product it adds the category name with the product name to the friendly url field.

 

2 files needs to me modified: (i am using ver.1.4.9.0)

- js/admin.js

- admin/tabs/AdminProducts.php

 

1. js/admin.js -> line 101 (function copy2friendlyURL())

 

function copy2friendlyURL()
{
$('#link_rewrite_' + id_language).val(str2url($('#name_' + id_language).val().replace(/^[0-9]+\./, ''), 'UTF-8'));
}

 

to

 

function copy2friendlyURL(catForFU)
{
$('#link_rewrite_' + id_language).val(catForFU + '-' + str2url($('#name_' + id_language).val().replace(/^[0-9]+\./, ''), 'UTF-8'));
}

 

 

2. admin/tabs/AdminProducts.php -> line 2220 (the lines that related to the field Name with the function copy2friendlyURL() in it)

 

Add this before the foreach loop

 

$cat_row = mysql_fetch_array(mysql_query("SELECT * FROM ps_category_lang WHERE id_category = $_GET[id_category] LIMIT 1"));

 

And change the part with the function

 

' onkeyup="if (isArrowKey(event)) return; copy2friendlyURL();"' : '').'

 

to

 

' onkeyup="if (isArrowKey(event)) return; copy2friendlyURL(\''.strtolower(str_replace(" ","-",$cat_row['name'])).'\');"' : '').'

 

That's it.

Edited by Yossefelbaz (see edit history)
  • Like 1
Link to comment
Share on other sites

Great. I'll have look at these functions. I myself have problems with this field as my shop is in Thai, and the friendly URL doesn't like Thai characters. Every time I edit a product, it destroys my friendly URL with some Thai rubbish, that cannot be saved then. This may give me a hint how to find a solution for this problem. Thanks!

Link to comment
Share on other sites

×
×
  • Create New...