vidmarc Posted September 25, 2013 Share Posted September 25, 2013 If we set this to "Generate Product Code", is there a way we can pre-define it to include letters first, then a number? Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 25, 2013 Share Posted September 25, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.