I need to add a custom attribute to the order model (" dynamic_ord ").
This attribute should be determined by the administrator’s staff after successfully saving the order, ideally on admin / sales_order / view in the main order block.
It must be independent of invoice / dispatch, etc. - possibly attached to event " edit".
I made some custom attributes for other objects (especially clients). And I understand that this is the same process. But I can’t figure out how to reorder this attribute, since there is no obvious “update” action. “Change” may make sense, but I would prefer not to duplicate orders to no avail.
Once this attr is in place, I want to display it in the sales_order / index grid . (Note = see this related thread for a working solution.)
The final state of this module (and for those who need this solution):
/ sales_order / view / 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>
<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 / sale / 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();
Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id'=> $id)));
}
}
- , SO- , . , .
, Mage 1.11 - , EAV .
-
Update
( .)
- sales_flat_order
- WACI_SalesExt_Block_Adminhtml_Sales_Dynamicsord
- , .
, , . <?php echo $this->getEditFormUrl(); ?>. , URL- , . , .
action =
action ="http://my.domain.com/index.php/my_admin/sales_order/editord/key/2e56d7f560dc4d356e3ef9519764b8a84858e5cd40d3c1f5821a423b949b9a6a/"
" ". , . ; , , - . , key/ee6... , , , .
Update
. : "AdminHtml" vs "Adminhtml", .
Oh Magento...
@R.S. .