Duplicate Entry In Cscart_Order_Details

We are starting to get this error upon checkout:

<br />
Database error: Duplicate entry '0-104' for key 'PRIMARY' (1062)<br />
Invalid query: INSERT INTO cscart_order_details (`item_id`, `order_id`, `product_id`, `product_code`, `price`, `amount`, `extra`) VALUES ('-1581168983', '104',<br />

```<br />
<br />
Please note that the item_id is -1581168983 which is not valid. The latest item_id in this table is 4294458594. I assume we have exceeded the maximum value for item_id (int11) so it is defaulting to 0 resulting in the duplicate entry. How to fix this issue? Thank you!

Odd that this is returning such a large number. Never seen that before. But yes, the immediate solution to your problem is to change the schema definition of item_id from int(11) to int(13). But before you do that, make sure that it's defined as 'unsigned'.

Generally the product key in the cart (item_id for the cart item) is generated from the product_id and the options. Different things happen depending on whether you have inventory tracking enabled, etc.

I would first check that the definition is “int(11) unsigned not null” and if so, I would submit an urgent defect to bugtracker and temporarily change the definition to “int(13) unsigned not null”. But that's getting to be a pretty big number and could break other things if it's allowed.

item_id is unsigned not null with a default of 0.

In 4.3.1 beta with the demo data, the highest item_id is 4283906614. I will report it in the bugtracker and see what they have to say.

We are currently using ultimate 3.0.4. Perhaps this was fixed in a later version.


I am starting to think the high number is fine. Why is it returning a negative value that is the mystery?

I'm guessing that the high number exceeds the integer size of your version of PHP and so when it's computed, it is being displayed as a negative number. Note that the log may be printing it as a negative when in fact is is being passed as an unsigned. I.e. the format is not set for an unsigned value.

But the sql error says dup entry for 0-104. The zero would be the item_id and 104 is the order_id (primary key is the pair of item_id/order_id) So would need to understand what it's seeing it as a zero. Suggest you let the DBA's at cs-cart figure it out.

We tracked it down to the following in fn.cart.php.

$_id = 2763169656 before

$ids[$_id] = $product_id;

$_id = -1531797640 after

Why the conversion for the index in the array???

Probably because it's being used as a string in the first instance and a signed number in the second. This is all going to depend on which version php you are running, whether it's 32 or 64 bit, etc.

Again, I would suggest you contact helpdesk and have them deal with it as a bug.