In Magento, defining an appropriate Order Status provides a clear idea for the operations team to understand the position of the order and take the necessary action. Magento has an Order State and Order Status that describes the current position of the order. The Default Order State and the corresponding statuses available in Magento are:

Order State
Order Status
NewProcessing
Pending PaymentPending Payment
ProcessingSuspected Fraud
CompletePayment Review
ClosedPending
CanceledOn Hold
On HoldComplete
Payment ReviewClosed
Canceled
Pending PayPal

Each Order State can be associated with different kinds of Order Statuses to provide a clear picture about the order. While Magento provides an option to customize the Order Status, the Order State still has the default options. In few occasions, retailers look out for a customized Order State so that there is no miscommunication across different verticals in the organization.

We are planning to add a new Order State called “Partially paid”.  Let’s have a look at the method to create a customized Order State in Magento.

Step-1:

First we need register the new module in Magento. To accomplish this, create a new xml file in this path.  app/etc/modules/Custom_Orderstate.xml

<?xml version="1.0"?>
    <config>
        <modules>
            <Custom_Orderstate>
                <active>true</active>
                <codePool>local</codePool>
            </Custom_Orderstate>
         </modules>
    </config>

Step-2:

Next, we need to configure our module. The configuration files can be found in the “etc” folder inside our module directory. So let’s create the configuration xml file: app/code/local/Custom/Orderstate/etc/config.xml

<?xml version="1.0"?>
  <config>
    <modules>
      <Custom_Orderstate>
        <version>0.1.0</version>
      </Custom_Orderstate>
    </modules>
    <global>
      <resources>
        <orderstate_setup>
          <setup>
            <module>Custom_Orderstate</module>
          </setup>
          <connection>
            <use>core_setup</use>
          </connection>
        </orderstate_setup>
        <orderstate_write>
          <connection>
            <use>core_write</use>
          </connection>
        </orderstate_write>
        <orderstate_read>
          <connection>
            <use>core_read</use>
          </connection>
        </orderstate_read>
      </resources>
    <sales>
      <order>
        <statuses>
          <partial_paid translate="label">
            <label>Partial Paid</label>
          </partial_paid>
        </statuses>
        <states>
          <partial_paid translate="label">
            <label>Partial Paid</label>
            <statuses>
              <partial_paid default="1"/>
            </statuses>
          </partial_paid>
        </states>
      </order>
    </sales>
   </global>
 </config>

Step-3:

Once the configuration is done, we need to create a SQL script file to insert our order state on the database tables (sales_order_status & sales_order_status_state).  Let’s create a new PHP file in the following folder:
app/code/local/Custom/Orderstate/sql/orderstate_setup/mysql4-install-0.1.0.php

<?php
    $installer = $this;

    // Required tables
    $statusTable = $installer->getTable('sales/order_status');
    $statusStateTable = $installer->getTable('sales/order_status_state');

    // Insert statuses
    $installer->getConnection()->insertArray(
        $statusTable,
        array('status', 'label'),
        array(
            array(
                'status' => 'partial_paid', 
                'label' => 'Partial Paid'
            )
        )
    );

    // Insert states and mapping of statuses to states
    $installer->getConnection()->insertArray(
        $statusStateTable,
        array('status', 'state', 'is_default'),
            array(
                array(
                    'status' => 'partial_paid', 
                    'state' => 'partial_paid', 
                    'is_default' => 1
                )
            )
        );

Step-4:

The final step is to login your Magento admin side. You can see the newly created order state ‘Partial Paid’ under the System > Order Statuses path.

Magento Order State

With changing market dynamic retailers, look out for methods to improve the operational efficiency by providing an appropriate order state.  This will allow a clear flow of communication across different departments in the organization enabling retailers to avoid confusions and increase productivity.

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

13 Comments on "How To Create A Custom Order State In Magento?"


Guest
b7itzz
9 months 2 days ago

I tried the code above to the tee. It’s showing under system/order statuses but not showing as an option to change the status of an order.

Guest
pardeep kumar
1 year 21 days ago

Custom added states are not appearing in status drop-down in comment box!

Balasubramaniam
Author
1 year 13 days ago

Hi Pardeep Kumar,
Can you please share your code. We will check and let you know.
Thanks.
Subscribe to our blogs.

Guest
pardeep kumar
1 year 21 days ago

I tested the code first with one state only and it worked but when added 2 more states, its not working.

I followed every step, also the code given in comment but nothing is working!!

Any suggestion please

Guest
Rafael Corrêa Gomes
1 year 6 months ago

Thanks for sharing!

Balasubramaniam
Author
1 year 6 months ago

Hi Rafael,

Thanks for your comments.
Please subscribe to our blogs for more insights on eCommerce,Magento & QA.

Guest
lounik
1 year 7 months ago

Hi, very nice tutorial! A question: how can I have the new custom state assigned to a particular process.. example: I need that when a credit memo is created for an order, the order does not go into complete state but goes into custom state. How do I achieve that?

Balasubramaniam
Author
1 year 6 months ago

Hi Lounik,
Thanks for your mail.
By using the above code, we can only create the new order state. For assigning that state to a particular process, we have to customaize the default code.
Let us know if you have any further queries.
Please subscribe to our blogs.
Thanks.

Guest
Mujahidh
1 year 11 months ago

awsom tutorial, but a kind request it would be better if you write the complete code like $installer->startSetup(); .It will help to new beginners.

Guest
Pk
1 year 11 months ago

How the code will look if we want to add 2 or more states?

Balasubramaniam
Author
1 year 7 months ago

Hi PK,

Sorry for the late reply.

Here is the code…please test it before you implement the same.
Thanks.
Please subscribe to our blogs. Mail us if you have any queries.

In the app/code/local/Custom/Orderstate/etc/config.xml file, add your state lists like follows,

Partial Paid

Partial Paid New State

Partial Paid

Partial Paid New State

In the app/code/local/Custom/Orderstate/sql/orderstate_setup/mysql4-install-0.1.0.php file, add your state lists like follows,

// Insert statuses
$installer->getConnection()->insertArray(
$statusTable,
array(‘status’, ‘label’),
array(
array(
‘status’ => ‘partial_paid’,
‘label’ => ‘Partial Paid’
),
array(
‘status’ => ‘partial_paid_new’,
‘label’ => ‘Partial Paid New State’
)
)
);

// Insert states and mapping of statuses to states
$installer->getConnection()->insertArray(
$statusStateTable,
array(‘status’, ‘state’, ‘is_default’),
array(
array(
‘status’ => ‘partial_paid’,
‘state’ => ‘partial_paid’,
‘is_default’ => 1
),
array(
‘status’ => ‘partial_paid_new’,
‘state’ => ‘partial_paid_new’,
‘is_default’ => 1
)
)
);

Guest
Samuele
2 years 9 months ago

Yeah!
The only guide that explains exactly which files to create, in what path and how to set the config properly.
The other guides put only portions of code without saying where and how they must to be written!
Thanks so much!!!

admin
Admin
2 years 9 months ago

Hi Samuele,

Thanks so much for your feedback.
Please keep reading our blogs.