Reputation: 3021
I want to add a new attribute to order_item
install-0.1.0.php
$installer->addAttribute('order_item', 'xxx', array('type'=>'text', 'visible' => true, 'required' => false, 'is_user_defined' => true, 'note' => 'Field comment'));
$installer->addAttribute('quote_item', 'xxx', array('type'=>'text', 'visible' => true, 'required' => false, 'is_user_defined' => true, 'note' => 'Field comment'));
I see 2 new rows in eav_attribute
Running this two times prints nothing:
$item = Mage::getModel('sales/order_item');
$item->load(91);
$item->setXxx("test");
$item->setData("xxx", "test");
print $item->getXxx();
$item->save();
How do I set and get a value in an order item for this attribute?
Upvotes: 0
Views: 2207
Reputation: 2334
Unfortunately sales/order
and sales/order_item
does not inherit or use the eav_attribute structure in Magento. This blog post explains it pretty well: http://www.krilion.net/blog/2012/08/adding-a-custom-attribute-to-a-magento-order/
The jist of it is that you'll need to create your installer script to create a new column in the flat table (sales_flat_order_item
) in order to save your new value. You should be able to save your xxx value as soon as there's an xxx column in the flat table. This means your installer script needs to extend Mage_Sales_Model_Mysql4_Setup
and not Mage_Eav_Model_Entity_Setup
.
Upvotes: 2