cancel
Showing results for 
Search instead for 
Did you mean: 

INSERT VALUE INTO ´sales_flat_order´

SOLVED

INSERT VALUE INTO ´sales_flat_order´

Hello,

I created a new column (CHECK_CUSTOMER) in sales_flat_order table.

 

When i place an order from frontend, i need to insert into sales_flat_order (CHECK_CUSTOMER field) a value.

 

which files i should modify/add to insert a value in that table when i place an order on frontend? Also i use OPC (One Page Checkout) module.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: INSERT VALUE INTO ´sales_flat_order´

Magento has its own DB mapping aka ORM, when a model is loaded, every column value is mapped to a key of its protected var $_data, and accessable by setData/getData, and when you save the model, it will try to save the values in $_data back to  table.

setCheckCustomer($value)  is not defined in order model, but it will be translated to setData('check_customer', $value) automatically by magic method, and in this way, we changed 'check_customer' key value if $_data in order model, when magento finially save it, it will be pushed to table.

View solution in original post

3 REPLIES 3

Re: INSERT VALUE INTO ´sales_flat_order´

read through Mage_Sales_Model_Service_Quote, you will find severial events you can utilize.

the best one IMO is 'sales_convert_quote_address_to_order', you can create an observer to change order table data in one save.

public function addCheckCustomerToOrder($observer) {
    $observer->getOrder()->setCheckCustomer('xxx');
}

link about how to setup observer http://magento.stackexchange.com/questions/41277/how-to-create-an-new-observer-on-the-event-catalog-...

Re: INSERT VALUE INTO ´sales_flat_order´

I did this:

 

I added in config.xml of One Page Checkout:

 

   <frontend>

        <events>

            <sales_order_place_after>
                <observers>
                    <sales_order_place_after>
                        <class>opc/observer</class>
                        <method>addCheckCustomerToOrder</method>
                    </sales_order_place_after>
                </observers>
            </sales_order_place_after>

        </events>
    </frontend>

 

Then on Observer.php i added this:

 

    public function addCheckCustomerToOrder($observer){
        Mage::log('ok1', null, 'addCheckCustomerToOrder.log');
        
        $observer->getOrder()->setCheckCustomer('xxx');
        
        Mage::log('ok2', null, 'addCheckCustomerToOrder.log');
        Mage::log('goi'.$observer->getOrder()->getOrderId(), null, 'addCheckCustomerToOrder.log');
        Mage::log('gii'.$observer->getOrder()->getIncrementId(), null, 'addCheckCustomerToOrder.log');
    }

 

Logs reusult:

2015-08-12T08:13:52+00:00 DEBUG (7): ok1
2015-08-12T08:13:52+00:00 DEBUG (7): ok2
2015-08-12T08:13:52+00:00 DEBUG (7): goi
2015-08-12T08:13:52+00:00 DEBUG (7): gii100000170

 

My question is how do I know that this method  "$observer->getOrder()->setCheckCustomer('xxx');" it refers at CHECK_CUSTOMER column from sales_flat_order?

 

 

Re: INSERT VALUE INTO ´sales_flat_order´

Magento has its own DB mapping aka ORM, when a model is loaded, every column value is mapped to a key of its protected var $_data, and accessable by setData/getData, and when you save the model, it will try to save the values in $_data back to  table.

setCheckCustomer($value)  is not defined in order model, but it will be translated to setData('check_customer', $value) automatically by magic method, and in this way, we changed 'check_customer' key value if $_data in order model, when magento finially save it, it will be pushed to table.