doukundong9652 2010-11-12 17:38
浏览 99
已采纳

自定义Magento订单字段和Magento数据库

Alright, so I've successfully added a custom order field to my page layout in magento. I require a "dealer" from which the user has to select a "dealer state" and then I use ajaxt to pull in all the dealers from that specific state into another field called "dealerid". The value of this field is in fact the dealer id in my database. My question is kind of a full one.

First, I need to add a field to the "order table" that saves the dealer id for the specific order and secondly I need to actually have magento take this field from the form and insert it. How do I go about doing these things? Mainly, what table would magento store this dealerid and what files do I modify to actually have magento access and insert this field value?

Note: I am using the one page checkout method only.

  • 写回答

1条回答 默认 最新

  • dongxiang3648 2010-11-13 14:01
    关注

    First of all, familiarize yourself with magento SQL update mechanism (its diffrent when your dealing with EAV - like customer tables - and regular tables - like orders). Create a module which will have a sql-update script in /YourNamespace/YourModule/sql/yourmodule_setup/mysql4-install-1.0.0.php for instance. You should use something like:

    $installer = $this;
    $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'dealerid', 'decimal(12,4) NULL');
    

    and in your config.xml:

    <global>
    (...)
           <models>
           (...)
               <yourmodule>
                   <class>Mage_Sales_Model</class>
                   <resourceModel>yourmodule_mysql4</resourceModel>
               </yourmodule>
               <yourmodule_mysql4>
                   <class>YourNamespace_Yourmodule_Model_Mysql4</class>
                   <entities>
                       <order><table>sales_order</table></order>
                   </entities>
               (...)
               </yourmodule_mysql4>
           (...) 
           </models>
           <resources>
                <yourmodule_setup>
                    <setup>
                        <module>YourNamespace_YourModule</module>
                        <class>YourNamespace_YourModule_Model_Mysql4_Setup</class>
                    </setup>
                </yourmodule_setup>
            </resources>
    (...)
    </global>
    

    Remember to create your own classes: YourNamespace_YourModule_Model_Mysql4_Setup, YourNamespace_Yourmodule_Model_Mysql4. Check in app/code/core/Mage/Sales/ how they should look like (nothing special needed there, they just must inherit from proper core classes). Also check out the app/code/core/Mage/Sales/sql and app/code/core/Mage/Sales/etc/config.xml.

    If you want to get a field from the onepage checkout, you must do a couple of things... I don't know what you really need from the user (and in what part of checkout its going to be taken). Adding an input is done by the templates (edit proper files in app/design/frontend/yourskin/default/template/checkout).

    To capture the right data you must rewrite the checkout controller whit your own controller action (look at the app/code/core/Mage/Checkout/Controllers/OnepageController.php) to get the data from the form and store it in the checkout session. After that you must hook to the checkout_type_onepage_save_order_after event (its in the app/code/core/Mage/Checkou/Model/Type/Onepage.php), take the data from your session and put it in the Order model (and save it of course). Its kind of a standard procedure, so you shouldn't have a problem.

    Its possible that you will also have add a column to the sales_flat_order (the structure of order tables changed in 1.4.x.x, so I'm not sure of it - you will have to do some experimenting).

    If you want to see it in the adminhtml order view, you will have to override some Core/Adminhtml/Blocks/Sales/Order (and templates probably).

    Its kind of a complex procedure, so you'll have to figure out some things by yourself. This post is kind of a general idea how it should be done.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 阿里云python代码求解
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路