I'm having trouble getting and setting a custom attribute in the order.
I have the following SQL script:
<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$attribute = array(
'position' => 1,
'type' => 'text',
'input' => 'varchar',
'label' => 'My Order Field',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'unique' => 0,
'is_configurable' => 0,
'position' => 1,
);
$setup->addAttribute('order', 'my_order_field', $attribute);
$installer->endSetup();
I can see the attribute in the eav table after running this.
I've then setup a observer that runs when a new order has been saved which i've also confirmed is running (with die() statements).
I've now removed those die statements and changed the order save code to this:
$event = $observer->getEvent();
$order = $event->getOrder();
$order->setMyOrderField('Hello');
And in my admin backend section I've added a row to retrieve the data:
<tr>
<td class="label"><label><?php echo Mage::helper('sales')->__('My Order Field') ?></label></td>
<td class="value"><strong><?php echo $_order->getMyOrderField(); ?></strong></td>
</tr>
However when I put a fresh order through nothing appears, can anyone tell me what I'm doing wrong in terms of saving data to my custom attribute?
Thanks
and