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 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料