Magento的定制"为了"属性/管理输入和显示 [英] Magento custom "order" attribute / admin input and display

查看:282
本文介绍了Magento的定制"为了"属性/管理输入和显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个自定义的属性添加到命令模式( dynamics_ord )。

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

这ATTR需要由管理人员来定义,订单已成功保存后,最好在系统管理员/ sales_order的/视图后,在主令块。

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.

一旦attr为到位,我想在 sales_order的/指数格来显示它。
(注=检查<一href=\"http://stackoverflow.com/questions/14695352/magento-add-custom-attribute-column-to-sales-order-index-grid\">this相关话题一个可行的解决方案。)

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的/查看/ 截图:

/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> <!-- 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安装-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();

模板/销售/订单/查看/ info.phtml

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

模板/销售/ 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)));

    }

}

一直四处寻找在这个问题上的一些信息,而这个SO螺纹似乎pretty接近我想做的事情。但目前还不清楚,我就可以通过这个流程来创建一个可编辑输入。

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.

我要指出,我对法师1.11 - 我已经收集了标准EAV模式不再用于顺序模式。

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 -

(注意是当前模块的内容。)

(note the "current" module contents.)


  • 领域已被添加到sales_flat_order结果

  • WACI_SalesExt_Block_Adminhtml_Sales_Dynamicsord块构造得到正确结果

  • 我有,这是获得正确地拉到位一些测试数据

在这一点上,我不认为我有我的路由器设置正确。在你的榜样,你叫&LT;?PHP的echo $这个 - &GT; getEditFormUrl(); ?&GT; 。我不知道这是应该输出格式化操作URL,但事实并非如此。我放弃了我自己的,但它仍然无法正常击球的路由器。

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/"

而刚刚击中一个找不到网页。至于我可以告诉大家,在路由器的的准确位置。我已经尝试了许多不同的组合;我似乎失去了一些东西在管理路由器的问题很重要。据我所知,键/ EE6 ...可能是跟我捣乱,但我不清楚如何处理它恰如其分。

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.

路由问题是简单的错误,我做不必要的复杂:我有一个误拼写目录名AdminHtml与Adminhtml - 导致路由器迷路

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.

呵呵... Magento的

Oh Magento...

感谢@ R,S。对德的帮助。

Thanks @R.S. for teh help.

推荐答案

您可以尝试添加编辑输入到帐户信息部分的订单详细信息页面。

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

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

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

添加

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

在你的格挡

<?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());
  }
  ...

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

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; ?>

在/app/$c$c/local/CWACI/SalesExt/controllers/Adminhtml/Sales/OrderController.php

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();

在你的config.xml

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>

......

.....

另请参阅<一个href=\"http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/admin/using_custom_admin_theme_templates\">Setting定制管理主题从模块以prevent作出修改,直接对核心模板。

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

这篇关于Magento的定制&QUOT;为了&QUOT;属性/管理输入和显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆