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
00028 set_time_limit(0);
00029
00030 $installer = $this;
00031
00032 $installer->getConnection()->beginTransaction();
00033
00034 $installer->getConnection()->addColumn($this->getTable('sales/quote'), 'global_currency_code', 'varchar(255) NULL AFTER `store_to_quote_rate`');
00035 $installer->getConnection()->addColumn($this->getTable('sales/quote'), 'base_to_quote_rate', 'decimal(12,4) NULL AFTER `store_to_quote_rate`');
00036 $installer->getConnection()->addColumn($this->getTable('sales/quote'), 'base_to_global_rate', 'decimal(12,4) NULL AFTER `store_to_quote_rate`');
00037
00038 $installer->addAttribute('quote', 'global_currency_code', array('type'=>'static'));
00039 $installer->addAttribute('quote', 'base_to_global_rate', array('type'=>'static'));
00040 $installer->addAttribute('quote', 'base_to_quote_rate', array('type'=>'static'));
00041
00042 $installer->addAttribute('order', 'global_currency_code', array('type'=>'varchar'));
00043 $installer->addAttribute('order', 'base_to_global_rate', array('type'=>'decimal'));
00044 $installer->addAttribute('order', 'base_to_order_rate', array('type'=>'decimal'));
00045
00046 $installer->addAttribute('invoice', 'global_currency_code', array('type'=>'varchar'));
00047 $installer->addAttribute('invoice', 'base_to_global_rate', array('type'=>'decimal'));
00048 $installer->addAttribute('invoice', 'base_to_order_rate', array('type'=>'decimal'));
00049
00050 $installer->addAttribute('creditmemo', 'global_currency_code', array('type'=>'varchar'));
00051 $installer->addAttribute('creditmemo', 'base_to_global_rate', array('type'=>'decimal'));
00052 $installer->addAttribute('creditmemo', 'base_to_order_rate', array('type'=>'decimal'));
00053
00054
00055
00056
00057
00058 $orderEntityType = $installer->getEntityType('order');
00059 $invoiceEntityType = $installer->getEntityType('invoice');
00060 $creditmemoEntityType = $installer->getEntityType('creditmemo');
00061
00062 $entityTypes = array($orderEntityType['entity_type_id'] => $orderEntityType,
00063 $invoiceEntityType['entity_type_id'] => $invoiceEntityType,
00064 $creditmemoEntityType['entity_type_id'] => $creditmemoEntityType);
00065
00066 foreach ($entityTypes as $typeId => $entity) {
00067
00068 $globalCurrencyCode = $installer->getAttribute($typeId, 'global_currency_code');
00069 if ($globalCurrencyCode['backend_type'] == 'static') {
00070 $globalCurrencyCodeTable = $this->getTable($entity['entity_table']);
00071 } else {
00072 $globalCurrencyCodeTable = $this->getTable($entity['entity_table']) . '_' . $globalCurrencyCode['backend_type'];
00073 }
00074
00075 $baseCurrencyCode = $installer->getAttribute($typeId, 'base_currency_code');
00076 if ($baseCurrencyCode['backend_type'] == 'static') {
00077 $baseCurrencyCodeTable = $this->getTable($entity['entity_table']);
00078 } else {
00079 $baseCurrencyCodeTable = $this->getTable($entity['entity_table']) . '_' . $baseCurrencyCode['backend_type'];
00080 }
00081
00082 $storeCurrencyCode = $installer->getAttribute($typeId, 'store_currency_code');
00083 if ($storeCurrencyCode['backend_type'] == 'static') {
00084 $storeCurrencyCodeTable = $this->getTable($entity['entity_table']);
00085 } else {
00086 $storeCurrencyCodeTable = $this->getTable($entity['entity_table']) . '_' . $storeCurrencyCode['backend_type'];
00087 }
00088
00089 $baseToGlobalRate = $installer->getAttribute($typeId, 'base_to_global_rate');
00090 if ($baseToGlobalRate['backend_type'] == 'static') {
00091 $baseToGlobalRateTable = $this->getTable($entity['entity_table']);
00092 } else {
00093 $baseToGlobalRateTable = $this->getTable($entity['entity_table']) . '_' . $baseToGlobalRate['backend_type'];
00094 }
00095
00096 $storeToBaseRate = $installer->getAttribute($typeId, 'store_to_base_rate');
00097 if ($storeToBaseRate['backend_type'] == 'static') {
00098 $storeToBaseRateTable = $this->getTable($entity['entity_table']);
00099 } else {
00100 $storeToBaseRateTable = $this->getTable($entity['entity_table']) . '_' . $storeToBaseRate['backend_type'];
00101 }
00102
00103 $baseToOrderRate = $installer->getAttribute($typeId, 'base_to_order_rate');
00104 if ($baseToOrderRate['backend_type'] == 'static') {
00105 $baseToOrderRateTable = $this->getTable($entity['entity_table']);
00106 } else {
00107 $baseToOrderRateTable = $this->getTable($entity['entity_table']) . '_' . $baseToOrderRate['backend_type'];
00108 }
00109
00110 $storeToOrderRate = $installer->getAttribute($typeId, 'store_to_order_rate');
00111 if ($storeToOrderRate['backend_type'] == 'static') {
00112 $storeToOrderRateTable = $this->getTable($entity['entity_table']);
00113 } else {
00114 $storeToOrderRateTable = $this->getTable($entity['entity_table']) . '_' . $storeToOrderRate['backend_type'];
00115 }
00116
00117
00118
00119 $query = 'INSERT INTO `' . $globalCurrencyCodeTable .
00120 '` (`entity_type_id`, `attribute_id`, `entity_id`, `value`) SELECT `entity_type_id`, "' .
00121 $globalCurrencyCode['attribute_id'] . '" as `attribute_id`, `entity_id`, `value` FROM `' .
00122 $baseCurrencyCodeTable . '` WHERE `attribute_id` = ' . $baseCurrencyCode['attribute_id'] . ';';
00123
00124
00125 $installer->getConnection()->query($query);
00126
00127
00128 $query = 'DELETE FROM `' . $baseCurrencyCodeTable . '` WHERE `attribute_id` = ' . $baseCurrencyCode['attribute_id'] . ';';
00129
00130
00131 $installer->getConnection()->query($query);
00132
00133
00134 $query = 'INSERT INTO `' . $baseCurrencyCodeTable .
00135 '` (`entity_type_id`, `attribute_id`, `entity_id`, `value`) SELECT `entity_type_id`, "' .
00136 $baseCurrencyCode['attribute_id'] . '" as `attribute_id`, `entity_id`, `value` FROM `' .
00137 $storeCurrencyCodeTable . '` WHERE `attribute_id` = ' . $storeCurrencyCode['attribute_id'] . ';';
00138
00139
00140 $installer->getConnection()->query($query);
00141
00142
00143 $query = 'INSERT INTO `' . $baseToGlobalRateTable .
00144 '` (`entity_type_id`, `attribute_id`, `entity_id`, `value`) SELECT `entity_type_id`, "' .
00145 $baseToGlobalRate['attribute_id'] . '" as `attribute_id`, `entity_id`, `value` FROM `' .
00146 $storeToBaseRateTable . '` WHERE `attribute_id` = ' . $storeToBaseRate['attribute_id'] . ';';
00147
00148
00149 $installer->getConnection()->query($query);
00150
00151
00152 $query = 'INSERT INTO `' . $baseToOrderRateTable .
00153 '` (`entity_type_id`, `attribute_id`, `entity_id`, `value`) SELECT `entity_type_id`, "' .
00154 $baseToOrderRate['attribute_id'] . '" as `attribute_id`, `entity_id`, `value` FROM `' .
00155 $storeToOrderRateTable . '` WHERE `attribute_id` = ' . $storeToOrderRate['attribute_id'] . ';';
00156
00157
00158 $installer->getConnection()->query($query);
00159
00160 }
00161
00162 $installer->getConnection()->commit();