Jump to content

Suddenly I can not create new products and I can't import .cvs


Recommended Posts

Hi,
I was importing my porducts wit .cvs files and it worked as expected. Then I wanted to ad a few other products extra via the "add new products" thing in the catalogue. That have always worked before flawless. Suddenly I can't create new products or import new .cvs files without error messages. see attached images.

1. What has happened?
2. How can I solve it?

Thank you for your help!

11548_sF17oW2mCb5hlkQl461c_t

11550_e0bUHP5hTRXbW4XWlsfQ_t

Link to comment
Share on other sites

I had the same problem with a customer - don't know what was the cause - maybe the buggy import??

anyway the problem is because product and product_lang don't have the ids in sync anymore

to solve the problem open phpmyadmin:

1. go to product table - and check it's max id_product -> let's say it is 3000
2. go to product_lang and you'll notice the max id_product is bigger than 3000
3. delete all entries from product_lang that are bigger than 3000

done


Please submit a bug report to presta if you have the time

Link to comment
Share on other sites

From the MYSQL error on the first screen what is happening is that a non-unique value is attempting to be inserted into a column that is set as being unique. Unfortunately, there is not enough detail in that error message to know which table for sure was affected as it could be a case of an invalid CSV file causing columns getting stuffed into the wrong spots in which case the product name shown may not actually be in the product name column as far as Prestashop is concerned.

It depends on your technical level here how best to troubleshoot things.

If you want to know what specific field is causing the above error you need to edit:

admin/tabs/AdminImport.php

and then search for "cannot be added". You will see lot of lines like this where a given field is attempted to be inserted into the database and then an error raised if that fails:

$this->_errors[] = $categoryToCreate->name[$defaultLanguageId].(isset($categoryToCreate->id) ? ' ('.$categoryToCreate->id.')' : '').' '.Tools::displayError('cannot be saved');



You should add a prefix in there so it is clear which section of the code is raising the error. Something like this:

$this->_errors[] = $categoryToCreate->name[$defaultLanguageId].(isset($categoryToCreate->id) ? ' ('.$categoryToCreate->id.')' : '').' '.Tools::displayError('cannot be saved [category: '.__LINE__.']');



That will let you know in the error message that it was a category create that failed and in what line in the script. Once you know where exactly it is failing you can then figure out what table is having the issue and then look at it with phpMyAdmin to see what might be going on here.

Cheers

Link to comment
Share on other sites

Most commercial web hosts have a global phpMyAdmin install accessible via you control panel. phpMyAdmin is a web interface for manipulating MySQL databases. So the assumption here is that you have at least a basic understanding of MySQL, enough to take a look at a table and see if certain things are obviously amiss.

For example, a corrupted table could be the issue or you could have something funny in a given column or you could have a table that has a small limit on autoincrement IDs and you have exhausted the number of rows you can insert or something else like that that has led to this specific issue.

Basically you are needing to sort out what query is failing and then figure out why that is happening. There might also be a debug option in Prestashop to show all queries sent to MySQL but I have not dug deep enough myself to know for sure.

If you do not have much data in the system you could also try clearing out the product database (and associated things like manufacturers) to see if that corrects the problem.

Cheers

Link to comment
Share on other sites

I have now replaced the code with the one provided by you. I simply took the adminimport.php from my ftp server and located the code and added ...__LINE__... etc.
Nothing happened so I guess I have to figure out how to use phpmyadmin. I do not have that many products actually so maybe I should just delete them all. I would like to know what had happened though so I don't make the same "mistake" again.

Link to comment
Share on other sites

The fact that the error message still does not include anything useful makes me think you did not catch all instances of "cannot be saved" in the import script. I just did a command line search and that is the only file in the latest version of Prestahop that has that string of text. Make sure you catch all of them and change the line to reflect what the code is updating (i.e. if it is updating the supplier, change the extra text to "supplier" instead of category):

$this->_errors[] = $supplier->name.(isset($supplier->id) ? ' ('.$supplier->id.')' : '').' '.Tools::displayError('cannot be saved');

becomes:

$supplier->name.(isset($supplier->id) ? ' ('.$supplier->id.')' : '').' '.Tools::displayError('cannot be saved [supplier: '.__LINE__.']');

etc.

The goal is to figure out what query is failing and that requires nailing down where in the import script things are going wrong.

Cheers

Link to comment
Share on other sites

  • 2 months later...

a problem can be, see my message above:

anyway the problem is because product and product_lang don’t have the ids in sync anymore

to solve the problem open phpmyadmin:

1. go to product table – and check it’s max id_product -> let’s say it is 3000
2. go to product_lang and you’ll notice the max id_product is bigger than 3000
3. delete all entries from product_lang that are bigger than 3000

Link to comment
Share on other sites

×
×
  • Create New...