Skip to content

Instantly share code, notes, and snippets.

@Vinai
Created November 8, 2011 20:35
Show Gist options
  • Save Vinai/1349110 to your computer and use it in GitHub Desktop.
Save Vinai/1349110 to your computer and use it in GitHub Desktop.
Example EAV setup script using createEntityTables(), installEntities() and addAttribute()
<?php
/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer = Mage::getModel('eav/entity_setup', 'default_setup');
$installer->startSetup();
// Example createEntityTables() call
$installer->createEntityTables('example_supplier');
// Example installEntities() call
$installer->installEntities(array(
'supplier' => array(
'table' => 'example_supplier',
'entity_model' => 'example/supplier',
'attributes' => array(
'name' => array(
'label' => 'Name',
'type' => 'varchar',
'required' => 1
),
'location_code' => array(
'label' => 'Location Code',
'type' => 'int',
'required' => 1
),
'valid_from' => array(
'label' => 'Valid From',
'type' => 'datetime',
'required' => 0
)
)
)
));
// Example addAttribute() call
$installer->addAttribute('supplier', 'priority', array(
'label' => 'Priority',
'type' => 'int',
'required' => 1,
'default' => '10'
));
$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment