Created
February 7, 2014 23:33
-
-
Save dng-dev/8874142 to your computer and use it in GitHub Desktop.
Magento Store Based EAV Entity Tables Setup Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Dng_Customeav_Model_Setup extends Mage_Eav_Model_Entity_Setup | |
{ | |
/** | |
* create store based eav entity tables | |
* | |
* @param string $baseName | |
* @param array $options | |
* - (bool) no-main don't create entity main table | |
* - (bool) no-default-types don't create default types | |
* - (array) types valid Types or custom types | |
* - 'datetime' => array(Varien_Db_Ddl_Table::TYPE_DATETIME, null), | |
* - 'decimal' => array(Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4'), | |
* - 'int' => array(Varien_Db_Ddl_Table::TYPE_INTEGER, null), | |
* - 'text' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '64k'), | |
* - 'varchar' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '255'), | |
* - 'char' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '255') | |
* | |
* @return Mage_Eav_Model_Entity_Setup | |
*/ | |
public function createStoreBasedEntityTables($baseTableName, array $options = array()) | |
{ | |
parent::createEntityTables($baseTableName, $options); | |
$isNoDefaultTypes = $this->_getValue($options, 'no-default-types', false); | |
$customTypes = $this->_getValue($options, 'types', array()); | |
$types = array(); | |
if (!$isNoDefaultTypes) { | |
$types = array( | |
'datetime' => array(Varien_Db_Ddl_Table::TYPE_DATETIME, null), | |
'decimal' => array(Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4'), | |
'int' => array(Varien_Db_Ddl_Table::TYPE_INTEGER, null), | |
'text' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '64k'), | |
'varchar' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '255'), | |
'char' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '255') | |
); | |
} | |
if (!empty($customTypes)) { | |
foreach ($customTypes as $type => $fieldType) { | |
$types[$type] = $fieldType; | |
} | |
} | |
foreach (array_keys($types) as $type) { | |
$this->getConnection()->addIndex( | |
$this->getTable(array($baseTableName, $type)), | |
$this->getIdxName( | |
array($baseTableName, $type), | |
array('entity_id', 'attribute_id', 'store_id'), | |
Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE | |
), | |
array('entity_id', 'attribute_id', 'store_id'), | |
Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE); | |
} | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment