Add custom attribute to sales_quote_address
Question
I would like to add a custom attribute to the Sales_Quote_Address
model in Magento. I searched on Google for a few hours now, and I can't find a way of doing so. Is it possible? Or do I have to set the attribute on the Sales_Order
itself and grab it from there afterwards?
Thank you
Solution
So, here's what I ended up doing:
$installer = $this;
$installer->startSetup();
/* @var $addressHelper Mage_Customer_Helper_Address */
$addressHelper = Mage::helper('customer/address');
$store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);
/* @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
// update customer address user defined attributes data
$attributes = array(
'attribute_name' => array(
'label' => 'Attribute label',
'backend_type' => 'int',
'frontend_input' => 'select',
'is_user_defined' => 0,
'is_system' => 0,
'is_visible' => 0,
'sort_order' => 140,
'is_required' => 0,
'multiline_count' => 0
),
);
foreach ($attributes as $attributeCode => $data) {
$attribute = $eavConfig->getAttribute('customer_address', $attributeCode);
$attribute->setWebsite($store->getWebsite());
$attribute->addData($data);
$usedInForms = array(
'adminhtml_customer_address',
'customer_address_edit',
'customer_register_address'
);
$attribute->setData('used_in_forms', $usedInForms);
$attribute->save();
}
$installer->run("
ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD COLUMN `column_name` TINYINT(4) DEFAULT NULL;
ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD COLUMN `column_name` TINYINT(4) DEFAULT NULL;
");
$installer->endSetup();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange