Magento upgrade services are essential if you own a Magento store. Upgrade to the latest version of Magento 2 and create seamless shopping experiences to your customers.
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 |
---|---|
New | Processing |
Pending Payment | Pending Payment |
Processing | Suspected Fraud |
Complete | Payment Review |
Closed | Pending |
Canceled | On Hold |
On Hold | Complete |
Payment Review | Closed |
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
1 2 3 4 5 6 7 8 9 |
<?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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<?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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?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.
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.
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.
Custom added states are not appearing in status drop-down in comment box!
Hi Pardeep Kumar,
Can you please share your code. We will check and let you know.
Thanks.
Subscribe to our blogs.
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
Thanks for sharing!
Hi Rafael,
Thanks for your comments.
Please subscribe to our blogs for more insights on eCommerce,Magento & QA.
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?
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.
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.
How the code will look if we want to add 2 or more states?
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
)
)
);
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!!!
Hi Samuele,
Thanks so much for your feedback.
Please keep reading our blogs.