Jump to content

Product Codes


vidmarc
 Share

Recommended Posts

Currently, in the file /includes/functions.inc.php, line 414, function generate_product_code() uses the first three characters of the product name (made uppercase), a string of five random characters (A-Z0-9), then either the category id number or a random number (0-99).

 

You can pre-define it by making sure the product name starts with letters.

 

If that is not always possible, change:

$product_code = strtoupper(substr($product_name, 0, 3)).$randChars.(int)$cat_id;

to:

$product_code = $randChars.(int)$cat_id;

 

That removes the possibility of non-letters starting the product code.

 

Next, we change the random string builder a bit:

for ($i = 0; $i < 3; ++$i) {
 $randChars = ($i == 0) ? $chars[mt_rand(0, $max_chars - 10)] : $randChars . $chars[mt_rand(0, $max_chars - 10)];
}

for ($i = 0; $i < 5; ++$i) {
  $randChars = $randChars . $chars[mt_rand(0, $max_chars)];
}

 

We have split the job into two iterations: three characters and five characters. The first three is a random character from the first character in the $chars array to the tenth from the last character (A-Z). The next five is any character in the array.

 

You can adjust the 3 and the 5 to get whatever ranges you want.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...