Add Custom Attribute with Order in Magento

custom-attributesorders

I need to set custom attribute along with order,

This attribute will have random values with each order, I need to show this value on the sales/order grid in admin.

Best Answer

Create a custom php file with this code, and put in your root folder of magento.

And run the file by url.

<?php require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute  = array(
        'type'          => 'text',
        'backend_type'  => 'text',
        'frontend_input' => 'text',
        'is_user_defined' => true,
        'label'         => 'Your attribute label',
        'visible'       => true,
        'required'      => false,
        'user_defined'  => false,   
        'searchable'    => false,
        'filterable'    => false,
        'comparable'    => false,
        'default'       => ''
);
$attribute2  = array(
        'type'          => 'text',
        'backend_type'  => 'text',
        'frontend_input' => 'text',
        'is_user_defined' => true,
        'label'         => 'Your attribute label',
        'visible'       => true,
        'required'      => false,
        'user_defined'  => false,   
        'searchable'    => false,
        'filterable'    => false,
        'comparable'    => false,
        'default'       => ''
);
$installer->addAttribute('order', 'placed_order_by', $attribute);
$installer->addAttribute('order', 'related_recurring', $attribute2);
$installer->endSetup();`enter code here`
Related Topic