product attribute to quote item and order item
one way would be to use an observer and a converter.
the observer would be to get the attribute from the product to the quote (using an attribute called 'test'), and the converter gets the attribute from the quote to the order.
in your config:
<global>
<fieldsets>
<sales_convert_quote_item>
<test>
<to_order_item>*</to_order_item>
</test>
</sales_convert_quote_item>
</fieldsets>
<sales>
<quote>
<item>
<product_attributes>
<test />
</product_attributes>
</item>
</quote>
</sales>
<events>
<sales_quote_item_set_product>
<observers>
<YOUR_MODULE>
<class>YOUR_MODULE/observer</class>
<method>setTestAttribute</method>
</YOUR_MODULE>
</observers>
</sales_quote_item_set_product>
</events>
</global>
in your observer:
public function setTestAttribute(Varien_Event_Observer $observer) {
$item = $observer->getQuoteItem();
$product = $observer->getProduct();
$item->setTest($product->getTest());
return $this;
}
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
toorder_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/