鉴于实例中订单实体数据的规模不断扩大,我相信您会很好并且建议您这样做。我很好奇 Magento 的版本,因为 CE1.6+ 是第一个具有Mage_Sales_Model_Resource_Setup
[link]类的版本。在 CE1.6 之前,该课程是Mage_Sales_Model_Mysql4_Setup
[link]。这是一个重要的区别,因为这些类中的列定义方法不同,以适应 1.6+ 中与 DB 无关的方法
Mage_Sales_Model_Mysql4_Setup::_getAttributeColumnDefinition
[链接]:
protected function _getAttributeColumnDefinition($code, $data)
{
$columnDefinition = '';
$type = isset($data['type']) ? $data['type'] : 'varchar';
$req = isset($data['required']) ? $data['required'] : false;
switch ($type) {
case 'int':
$columnDefinition = 'int(10) unsigned';
break;
case 'decimal':
$columnDefinition = 'decimal(12,4)';
break;
case 'text':
$columnDefinition = 'text';
break;
case 'date':
$columnDefinition = 'datetime';
break;
default:
$columnDefinition = 'varchar(255)';
break;
}
if ($req) {
$columnDefinition.= ' NOT NULL';
}
return $columnDefinition;
}
和Mage_Sales_Model_Resource_Setup::_getAttributeColumnDefinition
[链接]:
protected function _getAttributeColumnDefinition($code, $data)
{
// Convert attribute type to column info
$data['type'] = isset($data['type']) ? $data['type'] : 'varchar';
$type = null;
$length = null;
switch ($data['type']) {
case 'timestamp':
$type = Varien_Db_Ddl_Table::TYPE_TIMESTAMP;
break;
case 'datetime':
$type = Varien_Db_Ddl_Table::TYPE_DATETIME;
break;
case 'decimal':
$type = Varien_Db_Ddl_Table::TYPE_DECIMAL;
$length = '12,4';
break;
case 'int':
$type = Varien_Db_Ddl_Table::TYPE_INTEGER;
break;
case 'text':
$type = Varien_Db_Ddl_Table::TYPE_TEXT;
$length = 65536;
break;
case 'char':
case 'varchar':
$type = Varien_Db_Ddl_Table::TYPE_TEXT;
$length = 255;
break;
}
if ($type !== null) {
$data['type'] = $type;
$data['length'] = $length;
}
$data['nullable'] = isset($data['required']) ? !$data['required'] : true;
$data['comment'] = isset($data['comment']) ? $data['comment'] : ucwords(str_replace('_', ' ', $code));
return $data;
}