Magento add Custom column to order and quote entity

1. in upgrade script:

<?php
$installer = new Mage_Sales_Model_Resource_Setup('core_setup');
/**
 * Add 'checkout_process' attribute for entities
*/
$entities = array(
		'quote',
		'order'
);
$options = array(
		'type'     => Varien_Db_Ddl_Table::TYPE_INTEGER,
		'visible'  => true,
		'required' => false
);
foreach ($entities as $entity) {
	$installer->addAttribute($entity, 'checkout_process', $options);
}
$installer->endSetup();

 2. in config.xml file:

 

  <global>
<fieldsets>
    	 <sales_convert_quote>                           
                <checkout_process><to_order>*</to_order></checkout_process>
            </sales_convert_quote>
            <sales_convert_order>                                              
                <checkout_process><to_quote>*</to_quote></checkout_process>
            </sales_convert_order>
<fieldsets>
<events>
        <checkout_type_onepage_save_order>
			<observers>
				<change_checkout_process_observer>
					<type>singleton</type>
					<class>mycheckout/observer</class>
					<method>saveCheckoutProcessToOrder</method>
				</change_checkout_process_observer>
			</observers>
		</checkout_type_onepage_save_order>
    </events>
</global>

 in Observer file:

   public function saveCheckoutProcessToOrder($observer) {
	   	$event = $observer->getEvent();
	   	$order = $event->getOrder();
	   	$quote = $event->getQuote();
	   	$ordered_items = $order->getAllItems();
	   	foreach ($ordered_items as $item) {
	   		$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku());
	   		$checkout_process= $product->getData('checkout_process');
	   		$order->setData('checkout_process', $checkout_process);
	   		$quote->setData('checkout_process', $checkout_process);
	   		return $this;
	   	}
   }

 

你可能感兴趣的:(entity)