2
votes

I'm trying to add a custom order status to my magento install. I've found several tutorials detailing how to do this and they all speak of editing app/code/core/Mage/Sales/etc/config.xml

But, when I look at that file, it contains the statement: @depraceted after 1.4.2, statuses are saved into sales_order_status table

I'm unsure how to add a new status to the DB.

It looks as if all I need to do is insert a new row into sales_order_status with my status's code and frontend label, then associate that status to a state by adding a row to sales_order_status_state with the status's code and the code of all the states I wan't the status to be available for.

But I'm a little hazy on the state/status relationship, and I've been burned in the past by using raw SQL with a magento installation. So, I'm wondering if anyone else has added custom status in 1.5, and how they did it.

4

4 Answers

9
votes

This is how you can create a custom status using Magento:

$installer = $this;
/**
 * Prepare database for install
 */
$installer->startSetup();

$status = Mage::getModel('sales/order_status');

$status->setStatus('your_status_code')->setLabel('Your Status Label')
    ->assignState(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) //for example, use any available existing state
    ->save();

/**
 * Prepare database after install
 */
$installer->endSetup();
5
votes

Since Magento 1.5 custom order statuses can be configured via the backend. Navigate to System -> Order Statuses and you can create and edit order statuses and codes.

3
votes

To create statuses programmatically for use in your extension use the extension installer to create the status in your database using the following:

<?php
$installer = $this;
$installer->startSetup();
$installer->run("
    INSERT INTO  `{$this->getTable('sales/order_status')}` (
        `status` ,
        `label`
    ) VALUES (
        'status_code',  'Status Label'
    );
    INSERT INTO  `{$this->getTable('sales/order_status_state')}` (
        `status` ,
        `state` ,
        `is_default`
    ) VALUES (
        'status_code',  'processing',  '0'
    );
");
$installer->endSetup();
0
votes

I'm using.

$status = Mage::getModel('sales/order_status');
$status->setStatus('xyz')->setLabel('Your Status Label');
$status->save();
$status->assignState(Mage_Sales_Model_Order::STATE_PROCESSING);

You can use it in installer or not.