How to add custom field to order in Magento?

后端 未结 1 447
陌清茗
陌清茗 2021-02-09 10:19

I want to add one new custom field to one page checkout in Magento. I have created a module with installer:

$installer = $this;
$installer->startSetup();
$set         


        
相关标签:
1条回答
  • 2021-02-09 11:16

    Add an observer :

    <events>
        <checkout_type_onepage_save_order>
            <observers>
                <Savefield_observer>
                    <type>singleton</type>
                    <class>mymodule/observer</class>
                    <method>Savefield</method>
                </Savefield_observer>
            </observers>
        </checkout_type_onepage_save_order>
    </events>
    

    And in the mymodule/savefield/model/obsever.php file add this:

    class Mymodule_Savefield_Model_Observer
    {
        public function Savefield($observer){
            //get event data
            $event = $observer->getEvent();
    
            //get order
            $order = $event->getOrder();
    
            //set the variable here
            $order->setMyField($fieldVal);
        }   
    }
    
    0 讨论(0)
提交回复
热议问题