Jump to content

Product reference number validation


Recommended Posts

Is there a way to validate reference number when adding a new product? Iam wondering how to make sure that there won't be products with same number by mistake.

Two different things.

 

To ensure the uniqueness of each reference change the column of PREFIX_product table, reference column to be UNIQUE (make a backup first).

 

ALTER TABLE `your_database`.`PREFIX_product` ADD UNIQUE INDEX `unique_reference`(`reference`);

Uniqueness will be enforced by the DB and if you try to enter a duplicate reference you will get an error.

 

To answer the validation question I need to know the format of the reference numbers you are using.

Link to comment
Share on other sites

  • 2 years later...

Hello,

 

I am using Prestashop 1.6 and I wonder if you can explain where i should include the validation for the back-office.

Should i change the file "\classes\Product.php", at line 247:

public static $definition = array(
(...)
'reference' =>  array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),

and add ", 'validate' => 'checkUniqueRef' "

and insert into the file '\classes\Validade.php' the an validation like:

 
public static function checkUniqueRef($reference)
{
return <DB..SQL... select ... from product... where referece = $reference>;
}

Is that the way to get unique reference validation in Prestashop back office?

 

Thanks

 

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

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...