How can I save data in an eav field?
I have successfully installed an EAV attribute by doing $installer->addAttribute('order', 'field', etc)
. I also successfully run an observer when the order is saved on the sales_order_save_before / sales_order_save_after event. Now I try to put data into my field on the observer
$observer->getOrder()->setMyField('someuniquestring');
I've tried doing this before save and after, in which case I add
$observer->getOrder()->getResource()->save($order);
After searching my entire database the unique string doesn't exist in any ta开发者_StackOverflowbles. Also if I use the getMyField() and echo it to the screen in the observer and die() it shows the value I set.
Any help on how to save this into the db?
I found the answer to my own question after quite a while debugging.
At some point in time magento changed the way that data fields should be added the the order model in the database. Previously EAV fields were used but now magento just modifies the flat table itself. So in my install script I just do
$installer->getConnection->addColumn($installer->getTable('sales_flat_order', 'site_license_id', 'int(1) ...');
Then in my observer before save I add $observer->getEvent()->getOrder()->setMyField($myval);
That's all there is too it.
精彩评论