我想添加一些自定义文本区域来为前端添加的订单添加管理员评论。我想把它保存到ajax的订单表中。我正在尝试创建自定义模块,但没有成功。
我更改了管理模板文件以添加它(紧急评论,是紧急字段),但我无法使用 ajax 保存它。
最后我通过更改核心文件做到了。
我将以下代码添加到 info.phtml 文件
<form id="cus_com" >
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-payment-method"><?php echo Mage::helper('sales')->__('Urgent Comment') ?></h4>
</div>
<fieldset>
<span class="field-row">
<label class="normal" for="urgent_comment"><?php echo Mage::helper('sales')->__('User Note') ?></label>
<textarea name="urgentComment" rows="3" cols="5" style="height:6em; width:99%;" id="urgentComment" >
<?php echo $_order->getUserNote(); ?>
</textarea>
</span>
<input name="isUrgent" type="checkbox" id="isUrgent" value="<?php if ($_order->getUserNote() == 1) {
echo 'yes';
} ?>" />
<label> <?php echo Mage::helper('sales')->__('Is Urgent') ?></label><br />
<button type="button" align="right" title="<?php echo "Submit Comment" ?>" id="bb" onClick="handlerFunction()" ><span><span><?php echo "Submit Comment" ?></span></span></button>
<script type="text/javascript">
function handlerFunction(){
var params = {};
//var shipping = $('shipping-fields').serialize(true);
// params['shipping'] = Object.toJSON(shipping);
params['order_id'] = <?php echo $_order->getId() ?>;
params['urgentComment'] = $('urgentComment').value;
var n = $('isUrgent').value;
if(n=='yes'){
params['isUrgent']=1;
}else{
params['isUrgent']=0;
}
new Ajax.Request('<?php echo Mage::getModel('adminhtml/url')->getUrl('orderedit/order/saveCommnet') ?>', {
method: 'post',
parameters: params,
onSuccess: function(transport) {
$('urgentComment').innerHTML = transport.responseText;
}
});
}
</script>
</fieldset>
</div>
</form>
我将此添加到命令控制器公共功能 saveCommnetAction(){
$order = $this->_initOrder();
$comment= $this->getRequest()->getPost('urgentComment');
$is_urgent = $this->getRequest()->getPost('isUrgent');
$order->setUserNote($comment)
->setIsUrgent($is_urgent);
$order->save();
}
它的工作。谢谢
这是模板文件
app/design/adminhtml/default/default/template/sales/order/view/tab/info.phtml
这是控制器。它是另一个扩展 Mage_Adminhtml_Controller_Action 的自定义模块控制器类
app/code/local/mynamespace/OrderEdit/controllers/OrderController.php