Reputation: 35734
What is the correct method of adding new attributes to the sales and/or quote tables in magento via an install script:
Mage_Sales_Model_Entity_Setup
Mage_Sales_Model_Resource_Setup
and then which of these methods to use:
addColumn()
addAttribute()
They all seem to allow new attributes to be added so i am wondering which is correct and why?
Upvotes: 0
Views: 1670
Reputation: 1535
Looking at the code the differences are:
addColumn which comes from a DB\Adapter that is returned from getConnection in Mage_Sales_Model_Entity_Setup does nothing more than add a column to a table.
addAttribute in Mage_Sales_Model_Resource_Setup is only there to add a column if flat entities are enabled otherwise it's simply calling addAttribute in Mage_Eav_Model_Entity_Setup which does a number of things including checking if the attribute already exists, validating the data, adding attribute options and inserting the attribute into the eav_attribute table.
To answer your question. Add column should probably only be used for adding columns to your own tables. You should probably be using attributes to extend the sales order and quote objects.
For an example of the correct way to add attributes search in Mage\Sales\sql\sales_setup for addAttribute.
Here's an example of one of mine:
$installer->addAttribute('order', 'your_attribute_name', array(
'group' => 'General', // Defaults to General
'type' => 'int',
'default' => 0,
'grid' => true,
'required' => false,
'visible' => true,
'backend' => '',
'frontend' => '',
'label' => 'My Attribute',
'note' => 'description goes here.',
'input' => 'select',
'class' => '',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => 0,
'searchable' => false,
'filterable' => true,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => 'simple,virtual,configurable,bundle',
));
Upvotes: 1