Magento add product attribute to order item table and quote item table

#1 add attribute for entites in upgrade script:

<?php
$installer = new Mage_Sales_Model_Resource_Setup('core_setup');
/**
 * Add 'checkout_process' attribute for entities
*/
$entities = array(
		'quote_item',
		'order_item'
);
$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 add observer in config.xml

<global>
 <fieldsets>
        <sales_convert_quote_item>
            <checkout_process>
                <to_order_item>*</to_order_item>
            </checkout_process>
        </sales_convert_quote_item>
        <sales_convert_order_item>
	        <checkout_process>
	            <to_quote_item>*</to_quote_item>
	        </checkout_process>
    	</sales_convert_order_item>
    </fieldsets>
     <sales>
        <quote>
            <item>
                <product_attributes>
                    <checkout_process />
                </product_attributes>
            </item>
        </quote>
    </sales>
    <events>
        <sales_quote_item_set_product>
            <observers>
                <sales_quote_item_set_checkoutprocess_handler>
                    <class>mycheckout/observer</class>
                    <method>setCheckoutProcessAttribute</method>
                </sales_quote_item_set_checkoutprocess_handler>
            </observers>
        </sales_quote_item_set_product>
    </events>

 #3 observer function

   public function setCheckoutProcessAttribute(Varien_Event_Observer $observer) {
	   	$item = $observer->getQuoteItem();
	   	$product = $observer->getProduct();
	   	$item->setCheckoutProcess($product->getCheckoutProcess());
	   	return $this;
   }

 

你可能感兴趣的:(attribute)