Adding a new attribute to order in magento

Adding a new attribute to order in magento

August 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Adding a new attribute to order in magento

Adding a New Order Attribute in Magento

Adding custom attributes to orders in Magento is a common task when you need additional data associated with each order that isn’t covered by default attributes. In this post, we’ll guide you through creating an attribute for your specific needs and using it effectively within the system.

Step 1: Create the New Order Attribute

First, let’s create our new order status attribute:

  1. Navigate to Stores > Attributes > Manage Attributes.
  2. Click on the “Add New Attribute” button.
  3. Select “Order” as the Entity Type.
  4. Fill in the basic details:
    • Attribute Code: custom_order_status
    • Frontend Label: Custom Order Status
    • Input Type for Store Owner: Text Field
  5. Click Save.

Step 2: Configure the New Attribute

Now, configure the attribute:

  1. In the Data Configuration section, set:
    • Apply To: All Store Views
    • Used in Forms: Sales Order (default)
    • Is Required: No
    • Default Value: Leave empty
    • Input Validation for Store Owner: Text
  2. Click Save.

Step 3: Add the Attribute to the Admin Grid

To display this attribute in the admin order grid:

  1. Open app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php.
  2. Find the _prepareCollection() method and add the following line:
$collection->addAttributeToSelect('custom_order_status');
  1. Save your changes.

Step 4: Update Your Order Models

Next, update your order models to set or get your custom attribute:

  1. Open lib/Zend/Db/Table/Abstract.php.
  2. Find the function getData() and add a line:
'custom_order_status' => $this->getAttribute('custom_order_status'),
  1. Save your changes.

Step 5: Use Your Custom Attribute in Code

You can now use this attribute in your code like any other order status:

  1. In your custom module, you can access the attribute via:
$order = Mage::getModel('sales/order')->load($orderId);
echo $order->getCustomOrderStatus();
  1. Remember to clear your cache after making changes.

Step 6: Update Your Order Status Grid

To show this status in the admin/sales/orders grid:

  1. Open app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php.
  2. Find the function addColumns() and add:
$this->addColumn('custom_order_status', array(
    'header' => Mage::helper('sales')->__('Custom Order Status'),
    'index'  => 'custom_order_status',
));
  1. Save your changes.

Conclusion

Adding a new order attribute in Magento involves creating the attribute, configuring it correctly, and updating various parts of the system to reflect these changes. By following this guide, you should now have a custom order status that isn’t visible to customers but can be used for sorting and processing orders in the admin interface.

Don’t forget to clear your cache after making any modifications. If you need further assistance with Magento development or would like to explore more about our services at Laravel Company, feel free to reach out!

The key takeaways are:

  • Always use unique attribute codes for easy reference.
  • Ensure you clear the cache after making changes.
  • Update your models and grid files as needed.

Happy coding!

Database Admin Configuration Orders

Our network