Skip to content

Instantly share code, notes, and snippets.

@the-nerdery-dot-info
Created March 26, 2016 14:35
Show Gist options
  • Save the-nerdery-dot-info/ed9c590302dcc941a2ce to your computer and use it in GitHub Desktop.
Save the-nerdery-dot-info/ed9c590302dcc941a2ce to your computer and use it in GitHub Desktop.
Magento - adding custom attribute to order
<!--
add this to config.xml to have the attribute automatically
transferred to the order from the quote -> order conversion
Access the attirbute via magic getters/setters
$quote->getYourSpecialAttribute()
$order->getYourSpecialAttribute()
$quote->setYourSpecialAttribute()
-->
<global>
...
<fieldsets>
<sales_convert_quote>
<your_special_attribute>
<to_order>*</to_order>
</your_special_attribute>
</sales_convert_quote>
</fieldsets>
...
</global>
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' => 'int',
'backend_type' => 'text',
'frontend_input' => 'text',
'is_user_defined' => true,
'label' => 'My Label',
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => true,
'filterable' => true,
'comparable' => true,
'default' => 0
);
$installer->addAttribute('order', 'special_attribute', $attribute);
$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment