Product code in url

Can anyone tell me how to modify it so I can use the product code in the url?

for instance, instead of just


I could also use


I had a fix to this for my 1.X version but I can’t find any posts for 2.x. I have 2.12.



Is there a reason why you’re not using SEO? You could then set the product code encoded into the SEO name of your choosing.

I didn’t see an option to use the product code. It only had a category/subcat/product_name option. Plus if I were to switch to that I wouldn’t want to use product code as that doesn’t help with SEO. I just want to be able to link to a product page by either product_id or product_code.

Thanks for your input.

My products are mostly named same, solution of name-1.html or similar is no good.

this is why I got mod that makes product-name-SKU.html


I just want to be able to link to a product page by either product_id or product_code.


Not quite sure what you mean by wanting to “link to”. The most useful SEO name woud be the product name, not a product code and certainly not a product_id.

We track everything by the product_code, not the product_id, so when I get a list of items I need to feature in a mailing, for instance, I would like to be able to have my generic index.php?dispatch=products.view&product_code= and enter the product code there. What I have to do is search out the product_id for each of those items in order to get a link to the corresponding page. You see what I mean? If I could just use the product_code in the link it would be simpler.


Create the file addons/my_changes/controllers/customer/products.pre.php

Add something similar to:


if( !defined('AREA') ) die('Access denied');

if( $mode == 'view' && !empty($_REQUEST['product_code']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
$pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code=?s", $_REQUEST['product_code']);
if( $pid ) {
$_GET['product_id'] = $id;
fn_redirect(fn_url("dispatch=$controller.$mode&".implode('&', $_GET)));


This is NOT tested and is given as an example.

Thanks for the tip. That exact code didn’t seem to take but at least you’ve given me a place to start. I will post if I get it working.

Thanks again.

I got it working thanks to the code above with a couple of changes. Also I had to put this bit of code into the controllers/customer/products.php file because there was no hook in the file and don't know how to put one in yet. I put it around line 67 under the line

} elseif ($mode == 'view') {


if(!empty($_REQUEST['product_code']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {

$pid = db_get_field(“SELECT product_id FROM ?:products WHERE product_code=?s”, $_REQUEST['product_code']);

if( $pid ) {


$_GET['product_id'] = $pid;





I changed the $id which should have been $pid and changed the code in the fn_redirect to get it to work. Thanks for your help. So far it seems to work fine.

[font=“Verdana”]Would be nice to see an easier approach to this. Seems like to much messing around with the core files. And it would certainly fail after an update of CS-Cart… :S

There should an option in the SEO addon so that it asks in the DROP DOWN “Display Product Code in URL /PID/”, or allow for it to be used in unison with the other options in the drop down???

That would be a much better approach, and call the SEO addon “SEO v1.1” :)

Fingers crossed for an update! :)[/font]

Good day to all,

Heres my solution that so far works with 2.1.4 and older. Not tested with 2.2.x

In addons/seo/func.php add bold text

[quote]function fn_create_seo_name($object_id, $object_type, $object_name, $index = 0, $dispatch = '', $lang_code = CART_LANGUAGE)


//SKU MOD v1.3 by Darius 2009

if ($object_type == 'p') {

$product_data = ($_REQUEST['product_data']) ? $_REQUEST['product_data'] : fn_get_product_data($object_id, & $_SESSION['auth']);

if ($product_data) $object_name = (!empty($product_data['seo_name'])) ? $product_data['seo_name'] : (!empty($product_data['product_code'])) ? $product_data['product'] . ' ' . $product_data['product_code'] : $product_data['product'];


$_object_name = fn_generate_name($object_name);

if (empty($_object_name)) {

$__name = fn_get_seo_vars($object_type);

$_object_name = $__name['description'] . '-' . (empty($object_id) ? $dispatch : $object_id);

} [/quote]

[font=“Verdana”]Any idea how to resolve issues with categories going spaz?



There is only one /apparel/mens so why the -en and 2-3-4? Weird…

Surely it can act as a path? There is only 1 “outdoors” under “mens” so why not leave it as “outdoors”?

Seems like if you removed the -2-3-4… it would redirect you to another category with the same name?

I’m trying to merge the Product Code modifications PLUS solve a problem when multiple category names are the same… (eg. /A/B/C/example/ and /A/C/B/example-1/ and /B/A/C/example-1-2/ and /A/B/example-1-2-3/C/ and /A/example-1-2-3-4/B/C/…)

Would appreciate any “input” in to optimising the /category/category/product_code/product_name (or any variation of this…).

If anyone can suggest a paid or free addon, a modification, or anything, i’d really appreciate it ;)


[quote name='Darius' timestamp='1315373786' post='121126']

Good day to all,

[color=#282828][font=arial, verdana, tahoma, sans-serif][size=3]function fn_create_seo_name($object_id, $object_type, $object_name, $index = 0, $dispatch = '', $lang_code = CART_LANGUAGE)[/size][/font][/color]

[color=#282828][font=arial, verdana, tahoma, sans-serif][size=3]{[/size][/font][/color]

//SKU MOD v1.3 by Darius 2009

if ($object_type == 'p') {

$product_data = ($_REQUEST['product_data']) ? $_REQUEST['product_data'] : fn_get_product_data($object_id, & $_SESSION['auth']);

if ($product_data) $object_name = (!empty($product_data['seo_name'])) ? $product_data['seo_name'] : (!empty($product_data['product_code'])) ? $product_data['product'] . ' ' . $product_data['product_code'] : $product_data['product'];


[color=#282828][font=arial, verdana, tahoma, sans-serif][size=3]$_object_name = fn_generate_name($object_name);[/size][/font][/color]

[color=#282828][font=arial, verdana, tahoma, sans-serif][size=3]if (empty($_object_name)) {[/size][/font][/color]

[color=#282828][font=arial, verdana, tahoma, sans-serif][size=3]$__name = fn_get_seo_vars($object_type);[/size][/font][/color]

[color=#282828][font=arial, verdana, tahoma, sans-serif][size=3]$_object_name = $__name['description'] . '-' . (empty($object_id) ? $dispatch : $object_id);[/size][/font][/color]

[color=#282828][font=arial, verdana, tahoma, sans-serif][size=3]}[/size][/font][/color]

In addons/seo/func.php add bold text


Dose any one know a code like this that will work with 4.3.3?