We have a installed a third party module on an existing Magento installation which creates some new order statuses in its setup script like this:

$statusTable        = $installer->getTable('sales/order_status');
$data = array(
    array('status' => 'authorized', 'label' => 'Authorized Payment'),
    array('status' => 'canceled_saferpay', 'label' => 'Canceled by Saferpay')
$installer->getConnection()->insertArray($statusTable, array('status', 'label'), $data);

Everything went fine until we tried to initialize a new database with the existing Magento code (which is already including the module).

Now we get a duplicate key constraint violation in the sales_order_status table, complaining that the entry authorized already exists.


It is likely, that the 3rd party module defines a config node /config/global/sales/order/states.

Now when how have a look at /app/code/core/Mage/Sales/data/sales_setup/data-install- there is the following code:

$data     = array();
$statuses = Mage::getConfig()->getNode('global/sales/order/statuses')->asArray();
foreach ($statuses as $code => $info) {
    $data[] = array(
        'status' => $code,
        'label'  => $info['label']
    array('status', 'label'),

This means, the setup routine of the core module `Mage_Sales? already initializes all the status codes which are in the global XML config. This includes also the status of your 3rd party module.

This of course happens only if the 3rd party module is installed while initializing the code. In this case the core module already takes care of the necessary database setup. But it wouldn't, if you install the module later.

An easy solution would be to use insertOnDuplicate() in the 3rd party module to avoid those errors:

$installer->getConnection()->insertOnDuplicate($statusTable,  $data);

In addition, the 3rd party module should have an ´...entry, so the setup script is executed after the one ofMage_Sales`.

And: Of course the install script of that module must be a data-install script!

|improve this answer|||||
  • Obviously the guys which implemented the module didn't test it with a fresh installation :-) This happend to one of my modules too, last week, when I just truncated my database and I thought about fixing it, but in my case, this won't happen again :-) This is a bug and they should fix it. – Fabian Blechschmidt Feb 20 '13 at 11:12
  • 1
    I will send them my patch :-) – Alex Feb 20 '13 at 11:17
  • Great, do it. I hope they'll use it :D – Fabian Blechschmidt Feb 20 '13 at 11:21
  • 2
    Already pinged magento.stackexchange.com/users/93/tim who is working for that company to this post... :-) – Alex Feb 20 '13 at 11:23
  • Ok, then I'm sure, this will be fixed :D – Fabian Blechschmidt Feb 20 '13 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.