Jump to content

How to have unique SKU


diego

Recommended Posts

Hi, I need not allow the insert of two products with the same SKU, how can I do? I found some solutions by modifying the AdminProductscontroller.php file but without success.
I would not change the characteristics of the DB columns.
Any suggestions?
prestashop 1.7
Thanks for your help

Link to comment
Share on other sites

  • 2 weeks later...
On 9/8/2018 at 3:33 PM, Knowband Plugins dice:

Hi,

 

As per my knowledge, Prestashop allows the addition of the products with duplicate SKU (Reference number). I have also tried the same on PS1.7.3.

image.png.1fc60d2e5b472918703c24334baab42b.png

 

Kindly confirm which version you are using.

Hi tks for your reply,

I use Prestashop 1.7 but what I need is that prestashop does not insert a new product if the SKU is already present, displaying an error message like "Sku already in use"

Link to comment
Share on other sites

1 ora fa, Knowband Plugins dice:

Can you please share the screenshot?

It seems you are using some third party module which is generating this error.

 

 

Thanks, but maybe I have not explained the problem well I'll try again.

Prestashop allows the insertion of two products with the same SKU. In my case I would not allow this behavior. I need that when a new product is inserted and there is already another product with the same SKU, will show an error like "SKU already present" when the save button is clicked and does not allow saving.

 

Now i try this solution in controller->admin->AdminProductController.php

public function checkUniqueRef()
	{
		$reference = Tools::getValue('reference');
		$idproduct = Tools::getValue('id_product');
		if ($reference!=""){
			$sql = 'SELECT id_product FROM `'._DB_PREFIX_.'product` WHERE reference="'.$reference.'" AND id_product<>'.$idproduct;
			$res = Db::getInstance()->getValue($sql);
			if($res)
			{
			    $this->errors[] = $this->trans('Product with this reference is already exists.', array(), 'Admin.Notifications.Error');
			    //alternative
				//$this->errors[] = sprintf(Tools::displayError('Product with reference %s is already exists.'), $reference);
			}
		}
	}

And i call:

public function checkProduct()
    {
     
		$this->checkUniqueRef();
		if (!empty($this->errors)) {
            $this->display = 'update';
            return false;
        }

the product don't save the reference but the message not show.

I hope I have been clearer
Thanks for the help

 

Edited by diego
integrazione (see edit history)
Link to comment
Share on other sites

18 ore fa, Knowband Plugins dice:

Sorry!! my mistake.

Will check if it can be achieved easily but as per my current understanding it will require lots of changes.

 

 

thanks a lot, I await some solution

 

Link to comment
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...