Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:09:06+00:00 2026-06-18T03:09:06+00:00

I need to add a custom attribute to the order model ( dynamics_ord ).

  • 0

I need to add a custom attribute to the order model (“dynamics_ord“).

This attr needs to be defined by admin staff, after the order has been successfully saved, ideally on the admin/sales_order/view, in the main order block.

It needs to be independent of invoice / shipment etc – maybe attached to an order “edit” event.

I’ve made a number of custom attributes for other entities (notably – customers). And I realize this is the same process. But I’m not clear how to go about amending an order with this attribute, as there is no obvious “update” action. “Edit” may make sense, but I’d rather not duplicate orders needlessly.

Once this attr is in place, I want to display it in the sales_order/index grid.
(Note = check out this related thread for a working solution.)

Final State of this module (and for anyone else in need of this solution):

/sales_order/view/ screenshot :
Screenshot

WACI_SalesExt

app/local/WACI/SalesExt
 /Block
   /Adminhtml
     /Sales
       -Dynamicsord.php
 /controllers
   /Adminhtml
     /Sales
       - OrderController.php
 /etc
  - config.xml
 /Helper
   - Data.php
 /sql
   /waci_salesext_setup
     -mysql4-install-0.2.0.php

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <WACI_SalesExt>
            <version>0.2.0</version>
        </WACI_SalesExt>
    </modules>
    <global>

        <helpers>
            <WACI_SalesExt>
                <class>WACI_SalesExt_Helper</class>
            </WACI_SalesExt>
        </helpers>

        <blocks>
            <WACI_SalesExt>
                <class>WACI_SalesExt_Block</class>
            </WACI_SalesExt>

            <adminhtml> <!-- unclear if i need this second declaration for admin-->
                <WACI_SalesExt>
                    <class>WACI_SalesExt_Block</class>
                </WACI_SalesExt>
            </adminhtml>

        </blocks>

        <models>
            <WACI_SalesExt>
                <class>WACI_SalesExt_Model</class>
                <resourceModel>salesext_mysql4</resourceModel>
            </WACI_SalesExt>

        </models>

        <resources>
            <waci_salesext_setup>
                <setup>
                    <module>WACI_SalesExt</module>
                    <class>Mage_Sales_Model_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </waci_salesext_setup>
            <waci_salesext_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </waci_salesext_write>
            <waci_salesext_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </waci_salesext_read>
        </resources>

    </global>

<admin>
    <routers>
        <adminhtml>
            <use>admin</use>
            <args>
                <modules>
                    <WACI_SalesExt after="Mage_Adminhtml_Sales">WACI_SalesExt_Adminhtml</WACI_SalesExt>
                </modules>
            </args>
        </adminhtml>    
    </routers>
</admin>
</config>

WACI / SalesExt / sql / waci_salesext_setup / mysql4-install-0.2.0.php

    $installer = $this;
    $installer->startSetup();

    $installer->addAttribute('order', 'dynamics_ord', array(
                                'type'              =>'varchar', 
                                'visible'           => true, 
                                'required'          => false, 
                                'is_user_defined'   => false, 
                                'note'              => 'Dynamics ORD')
                            );

$installer->getConnection()->addColumn($installer->getTable('sales_flat_order'), 'dynamics_ord','VARCHAR(255) NULL DEFAULT NULL');
$installer->getConnection()->addColumn($installer->getTable('sales_flat_order_grid'), 'dynamics_ord','VARCHAR(255) NULL DEFAULT NULL');

    $installer->endSetup();

template/sales/order/view/info.phtml

<?php echo $this->getLayout()->createBlock('WACI_SalesExt/adminhtml_sales_dynamicsord')->setOrderId($_order->getId())->toHtml() ?>

template/sales/ord_form.phtml

<?php if ('sales_order' == Mage::app()->getRequest()->getControllerName() ): ?>
<tr>
    <td class="label"><label for="dynamics_ord">Dynamics ORD</label></td>
    <td class="value">
        <form action="<?php echo $this->getFormUrl(); ?>" method="post" id="ord_form">
            <input type="hidden" name="form_key" value="<?php echo $this->getFormKey(); ?>" />
            <input type="hidden" name="token" value="<?php echo $this->getToken(); ?>" />  
            <div class="">
                <input type="text" class="input-text" name="dynamics_ord" value="<?php echo $this->getOrder()->getData('dynamics_ord'); ?>" style="width:150px; float:left; display:inline;" />
                <button onclick="editForm.submit()" style="float:left;margin:3px 10px 0;">Update</button>  
            </div> 
        </form>
        <script type="text/javascript">
            editForm = new varienForm('ord_form');
        </script>
    </td>
</tr>
<?php endif; ?>

WACI_SalesExt_Block_Adminhtml_Sales_Dynamicsord

class WACI_SalesExt_Block_Adminhtml_Sales_Dynamicsord extends Mage_Adminhtml_Block_Template
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('sales/ord_form.phtml');
    }

    public function getOrder(){
        return Mage::registry('current_order');
    }

    public function getFormUrl(){
        return Mage::helper("adminhtml")->getUrl('*/sales_order/editord', array('order_id'=>$this->getOrder()->getId()) );
    }

}

WACI_SalesExt_Adminhtml_Sales_OrderController

include_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Sales' . DS . 'OrderController.php';

class WACI_SalesExt_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{

    public function editordAction()
    {

        $postData = $this->getRequest()->getPost();

        Mage::log('WACI_SalesExt_Adminhtml_Sales_OrderController::ordEditAction'.print_r($postData, true) );

        $id = $this->getRequest()->getParam('order_id');
        $order = Mage::getModel('sales/order')->load($id);
        $order->setDynamicsOrd($postData['dynamics_ord']);

        $order->save();

        // return to sales_order view
        Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id'=> $id)));

    }

}

Been looking around for some info on this issue, and this SO thread seems pretty close to what I want to do. But it’s not clear that I’ll be able to create an editable input via this workflow.

I’ll note that I’m on Mage 1.11 – and I’ve gathered that the standard EAV pattern is no longer used for the order model.

Cheers –


Update

(note the “current” module contents.)

  • The field has been added to the sales_flat_order
  • WACI_SalesExt_Block_Adminhtml_Sales_Dynamicsord block is getting constructed correctly
  • i have some test data in place that is getting pulled in correctly

At this point, I don’t think i have my router set up correctly. In your example, you called <?php echo $this->getEditFormUrl(); ?> . I’m not sure if that is supposed to output a formatted action url, but it wasn’t. I dropped my own in, but its still not hitting the router correctly.

Currently, the value in the form action =

   action ="http://my.domain.com/index.php/my_admin/sales_order/editord/key/2e56d7f560dc4d356e3ef9519764b8a84858e5cd40d3c1f5821a423b949b9a6a/"

And just hits a “page not found”. As far as I can tell, the router should be accurate here. I’ve tried a number of different combinations; I’m apparently missing something important on the admin router issue. I understand the key/ee6… is probably messing with me, but I’m not clear how to deal with it appropriately.


Update

Routing problem was simple error I was needlessly making complex: I had a miss-spelled directory name “AdminHtml” vs “Adminhtml” – causing the router to get lost.

Oh Magento…

Thanks @R.S. for teh help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:09:07+00:00Added an answer on June 18, 2026 at 3:09 am

    You could try adding the ‘editable input’ to the ‘Account Information’ section on your order detail page.

    In /app/design/adminhtml/default/default/template/sales/order/view/info.phtml

    enter image description here

    Add

    <?php echo $this->getLayout()->createBlock('salesext/adminhtml_editform')->setOrderId($_order->getId())->toHtml() ?>
    

    In your block

    <?php
    
    class WACI_SalesExt_Block_Adminhtml_Editform extends Mage_Adminhtml_Block_Template
    {
        public function __construct()
        {
            parent::__construct();
           $this->setTemplate('salesext/edit_form.phtml');
        }
    
        public function getOrder(){
            return Mage::registry('current_order');
        }
    
       public function getFormUrl(){
           return Mage::helper("adminhtml")->getUrl('*/sales_order/editField', array('order_id'=>$this->getOrder()->getId());
      }
      ...
    

    in /app/design/adminhtml/default/default/template/salesext/edit_form.phtml

    <?php if ('sales_order' == Mage::app()->getRequest()->getControllerName() : ?>
    <div id="change-order-email" style="display:none">
        <form action="<?php echo $this->getEditFormUrl(); ?>" method="post" id="edit_form">
            <input type="hidden" name="form_key" value="<?php echo $this->getFormKey(); ?>" />
            <input type="hidden" name="token" value="<?php echo $this->getToken(); ?>" />  
            <table cellspacing="4" class="form-list">
                <tr>
                    <td>Field</td>
                    <td><input .... class="required-entry validate-email" /></td>
                </tr>
            </table>
        </form>
        <button onclick="editForm.submit()">Change</button> 
    </div>
    <script type="text/javascript">
        editForm = new varienForm('edit_form');
    </script>
    <?php endif; ?>
    

    In /app/code/local/CWACI/SalesExt/controllers/Adminhtml/Sales/OrderController.php

    <?php
    include_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Sales' . DS . 'OrderController.php';
    
    class CWACI_SalesExt_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
    {
    
        public function editFieldAction()
        {
            $postData = $this->getRequest()->getPost();
            $id = $this->getRequest()->getParam('order_id');
            $order = Mage::getModel('sales/order')->load($id);
            $order->setFieldName($postData[field_name]);
            .....
            $order->save();
    

    In your config.xml

    ...
    <admin>
        <routers>
            <adminhtml>
                <use>admin</use>
                <args>
                    <modules>
                        <CWACI_SalesExt after="Mage_Adminhtml_Sales">CWACI_SalesExt_Adminhtml</CWACI_SalesExt>
                    </modules>
                </args>
            </adminhtml>    
        </routers>
    </admin>
    

    …..

    Also see Setting custom Admin theme from a Module to prevent making modification directly to core templates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add custom variable to new order E-mail. This variables are custom
I need to add a custom attribute to the selected text in an NSTextView.
Can I add custom model attribute titles, so forms could automatically render them instead
I need to add a custom attribute with incrementing number to every HTML tag
I need to add custom validator for comparing two dates - start date and
I need to add a custom search engine to Firefox. I have a name
I have an XSL style sheet for which I need to add some custom
I am making a custom control I need to add some default keybindings, microsoft
I making a custom button, and I need to add a PreviewKeyDown event, whenever
I need add a new user group for mediawiki. The new group has more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.