00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 $installer = $this;
00028
00029
00030 $installer->run("
00031 CREATE TABLE `{$installer->getTable('sales_flat_order_item')}` (
00032 `item_id` int(10) unsigned NOT NULL auto_increment,
00033 `order_id` int(10) unsigned NOT NULL default '0',
00034 `parent_item_id` int(10) unsigned default NULL,
00035 `quote_item_id` int(10) unsigned default NULL,
00036 `created_at` datetime NOT NULL default '0000-00-00 00:00:00',
00037 `updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
00038
00039 `product_id` int(10) unsigned default NULL,
00040 `product_type` varchar(255) default NULL,
00041 `product_options` text default NULL,
00042 `weight` decimal(12,4) default '0.0000',
00043 `is_virtual` tinyint(1) unsigned default NULL,
00044 `sku` varchar(255) NOT NULL default '',
00045 `name` varchar(255) default NULL,
00046 `description` text,
00047 `applied_rule_ids` text,
00048 `additional_data` text,
00049
00050 `free_shipping` tinyint(1) unsigned NOT NULL default '0',
00051 `is_qty_decimal` tinyint(1) unsigned default NULL,
00052 `no_discount` tinyint(1) unsigned default '0',
00053
00054 `qty_backordered` decimal(12,4) default '0.0000',
00055 `qty_canceled` decimal(12,4) default '0.0000',
00056 `qty_invoiced` decimal(12,4) default '0.0000',
00057 `qty_ordered` decimal(12,4) default '0.0000',
00058 `qty_refunded` decimal(12,4) default '0.0000',
00059 `qty_shipped` decimal(12,4) default '0.0000',
00060
00061 `cost` decimal(12,4) default '0.0000',
00062 `price` decimal(12,4) NOT NULL default '0.0000',
00063 `base_price` decimal(12,4) NOT NULL default '0.0000',
00064 `original_price` decimal(12,4) default NULL,
00065 `base_original_price` decimal(12,4) default NULL,
00066
00067 `tax_percent` decimal(12,4) default '0.0000',
00068 `tax_amount` decimal(12,4) default '0.0000',
00069 `base_tax_amount` decimal(12,4) default '0.0000',
00070 `tax_invoiced` decimal(12,4) default '0.0000',
00071 `base_tax_invoiced` decimal(12,4) default '0.0000',
00072
00073 `discount_percent` decimal(12,4) default '0.0000',
00074 `discount_amount` decimal(12,4) default '0.0000',
00075 `base_discount_amount` decimal(12,4) default '0.0000',
00076 `discount_invoiced` decimal(12,4) default '0.0000',
00077 `base_discount_invoiced` decimal(12,4) default '0.0000',
00078
00079 `amount_refunded` decimal(12,4) default '0.0000',
00080 `base_amount_refunded` decimal(12,4) default '0.0000',
00081
00082 `row_total` decimal(12,4) NOT NULL default '0.0000',
00083 `base_row_total` decimal(12,4) NOT NULL default '0.0000',
00084 `row_invoiced` decimal(12,4) NOT NULL default '0.0000',
00085 `base_row_invoiced` decimal(12,4) NOT NULL default '0.0000',
00086
00087 `row_weight` decimal(12,4) default '0.0000',
00088
00089 `gift_message_id` int(10) default NULL,
00090 `gift_message_available` int(10) default NULL,
00091
00092 PRIMARY KEY (`item_id`),
00093 KEY `IDX_ORDER` (`order_id`)
00094 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
00095 ");
00096
00097 $itemFields = $installer->getConnection()->describeTable($installer->getTable('sales_flat_order_item'));
00098 $itemEntityId = $installer->getEntityTypeId('order_item');
00099
00100 $itemAttributes = $installer->getConnection()->fetchPairs("SELECT attribute_id, attribute_code FROM {$installer->getTable('eav_attribute')} WHERE entity_type_id={$itemEntityId}");
00101
00102 $items = $installer->getConnection()->fetchAll("SELECT * FROM {$installer->getTable('sales_order_entity')} WHERE entity_type_id={$itemEntityId}");
00103
00104 foreach ($items as $itemData) {
00105 $itemId = $itemData['entity_id'];
00106 $sql = "
00107 SELECT
00108 attribute_id, value
00109 FROM {$installer->getTable('sales_order_entity_decimal')}
00110 WHERE
00111 entity_id={$itemId}
00112 AND entity_type_id={$itemEntityId}
00113
00114 UNION
00115 SELECT
00116 attribute_id, value
00117 FROM {$installer->getTable('sales_order_entity_datetime')}
00118 WHERE
00119 entity_id={$itemId}
00120 AND entity_type_id={$itemEntityId}
00121
00122 UNION
00123
00124 SELECT
00125 attribute_id, value
00126 FROM {$installer->getTable('sales_order_entity_int')}
00127 WHERE
00128 entity_id={$itemId}
00129 AND entity_type_id={$itemEntityId}
00130
00131 UNION
00132
00133 SELECT
00134 attribute_id, value
00135 FROM {$installer->getTable('sales_order_entity_text')}
00136 WHERE
00137 entity_id={$itemId}
00138 AND entity_type_id={$itemEntityId}
00139
00140 UNION
00141
00142 SELECT
00143 attribute_id, value
00144 FROM {$installer->getTable('sales_order_entity_varchar')}
00145 WHERE
00146 entity_id={$itemId}
00147 AND entity_type_id={$itemEntityId}
00148 ";
00149
00150 $data = $installer->getConnection()->fetchPairs($sql);
00151 foreach ($data as $attributeId => $attributeValue) {
00152 if (isset($itemAttributes[$attributeId])) {
00153 $itemData[$itemAttributes[$attributeId]] = $attributeValue;
00154 }
00155 }
00156
00157 $newItemData = array(
00158 'item_id' => $itemData['entity_id'],
00159 'order_id' => $itemData['parent_id'],
00160 );
00161
00162 foreach ($itemData as $key => $value) {
00163 if (isset($itemFields[$key])) {
00164 $newItemData[$key] = $value;
00165 }
00166 }
00167
00168 $installer->getConnection()->insert($installer->getTable('sales_flat_order_item'), $newItemData);
00169 }