Jump to content
Ezequielb

Auto Generate a unique random product reference number

Recommended Posts

Posted (edited)

Hello,

I need to use this function to generate a ramdon product reference number for PS 1.7.6.x. I need to assign this number to products in database as unique. How should  I get this done?

//Function to get random alphanumeric code

function random_code() 

  
    // String of all numeric characters 
    
   $start_letter = str_shuffle('ABCD');
   $number = str_shuffle('0123456789');
   $letter = str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ');    
      
  return substr(($start_letter), 0, 1).substr(($number), 0, 4).'-'.substr(($letter), 0, 1); 

echo random_code(); 
 

// Result is a random number like: A6789-M

Edited by Ezequielb (see edit history)

Share this post


Link to post
Share on other sites
Posted (edited)

Hi,

Did you find your answer? What is the code you used and what file? I need the same thing . To make it unique, i selected the table ps_product in phpmyadmin and make it UNIQUE.

Edited by MrBraco2
modification (see edit history)

Share this post


Link to post
Share on other sites
20 hours ago, MrBraco2 said:

Hi,

Did you find your answer? What is the code you used and what file? I need the same thing . To make it unique, i selected the table ps_product in phpmyadmin and make it UNIQUE.

Hi, this was solved here..

best regards!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More