Last Updated: February 25, 2016
·
1.274K
· philippfrank

Magento, custom order numbers and the duplicate order id error

If you customize the order number format for your Magento installation to contain non-numeric characters you may experience the following behaviour: After an order was placed Magento is not able to retrieve a 'fresh' order number and report something like:

'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'MY-ORDER-001337' for key 'UNQ_SK24_SALES_FLAT_ORDER_INCREMENT_ID'' in /.../Zend/Db/Statement/Pdo.php:234

This is a bug in Magentos way to retrieve a new order number. To get rid of it just create a local copy of

app/code/core/Mage/Sales/Model/Resource/Quote.php

to

app/code/local/Mage/Sales/Model/Resource/Quote.php

and replace

$bind = array(':increment_id' => (int)$orderIncrementId);

by

$bind = array(':increment_id' => $orderIncrementId);

This way Magento is not trying to perform an integer type cast on your non-numeric order id.