This is done by combining your knowledge of observers and config.xml. Config.xml will manage the provision of a custom attribute definition on the quote item, and an observer will handle saving the product attribute to the quote when added to a quote.
From there, you use config.xml to call the fieldset definition, which will handle the conversion from quote_item
to order_item
.
Full disclosure: The below content is from Atwix. Link below the answer.
At first, you should add custom attribute to
sales->quote->item->product_attributes
node:
<sales>
<quote>
<item>
<product_attributes>
<custom_attribute />
</product_attributes>
</item>
</quote>
</sales>
This makes attribute accessible when we will be copying it from the
product to quote item – which is our next step. For this task the
observer is used, and the event will be called
sales_quote_item_set_product
:
<sales_quote_item_set_product>
<observers>
<yourmodule_customattribute>
<class>yourmodule_customattribute/observer</class>
<method>salesQuoteItemSetCustomAttribute</method>
</yourmodule_customattribute>
</observers>
</sales_quote_item_set_product>
Observer:
public function salesQuoteItemSetCustomAttribute($observer)
{
$quoteItem = $observer->getQuoteItem();
$product = $observer->getProduct();
$quoteItem->setCustomAttribute($product->getCustomAttribute());
}
The last thing we need to care about – it is converting attribute
from quote_item
to order_item
. And this can be done with XML:
<fieldsets>
<sales_convert_quote_item>
<custom_attribute>
<to_order_item>*</to_order_item>
</custom_attribute>
</sales_convert_quote_item>
<sales_convert_order_item>
<custom_attribute>
<to_quote_item>*</to_quote_item>
</custom_attribute>
</sales_convert_order_item>
</fieldsets>
Source: Atwix (who is full of win): http://www.atwix.com/magento/custom-product-attribute-quote-order-item/