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->startSetup();
00031
00032 $installer->run("
00033 CREATE TABLE `{$installer->getTable('tax_calculation_rate')}` (
00034 `tax_calculation_rate_id` INT NOT NULL AUTO_INCREMENT ,
00035 `tax_country_id` CHAR( 2 ) NOT NULL ,
00036 `tax_region_id` MEDIUMINT NOT NULL ,
00037 `tax_postcode` VARCHAR( 12 ) NOT NULL ,
00038 `code` VARCHAR( 255 ) NOT NULL ,
00039 `rate` DECIMAL( 12, 4 ) NOT NULL ,
00040 PRIMARY KEY ( `tax_calculation_rate_id` ),
00041 KEY `IDX_TAX_CALCULATION_RATE` (`tax_country_id`, `tax_region_id`, `tax_postcode`),
00042 KEY `IDX_TAX_CALCULATION_RATE_CODE` (`code`)
00043 ) ENGINE = InnoDB;
00044
00045 CREATE TABLE `{$installer->getTable('tax_calculation_rate_title')}` (
00046 `tax_calculation_rate_title_id` INT NOT NULL AUTO_INCREMENT ,
00047 `tax_calculation_rate_id` INT NOT NULL ,
00048 `store_id` SMALLINT( 5 ) UNSIGNED NOT NULL ,
00049 `value` VARCHAR( 255 ) NOT NULL ,
00050 PRIMARY KEY ( `tax_calculation_rate_title_id` ),
00051 KEY `IDX_TAX_CALCULATION_RATE_TITLE` (`tax_calculation_rate_id`, `store_id`),
00052 KEY `FK_TAX_CALCULATION_RATE_TITLE_RATE` (`tax_calculation_rate_id`),
00053 KEY `FK_TAX_CALCULATION_RATE_TITLE_STORE` (`store_id`)
00054 ) ENGINE = InnoDB;
00055
00056 CREATE TABLE `{$installer->getTable('tax_calculation_rule')}` (
00057 `tax_calculation_rule_id` INT NOT NULL AUTO_INCREMENT ,
00058 `code` VARCHAR( 255 ) NOT NULL ,
00059 `priority` MEDIUMINT NOT NULL ,
00060 `position` MEDIUMINT NOT NULL ,
00061 PRIMARY KEY ( `tax_calculation_rule_id` ),
00062 KEY `IDX_TAX_CALCULATION_RULE` (`priority`, `position`, `tax_calculation_rule_id`),
00063 KEY `IDX_TAX_CALCULATION_RULE_CODE` (`code`)
00064 ) ENGINE = InnoDB;
00065
00066 CREATE TABLE `{$installer->getTable('tax_calculation')}` (
00067 `tax_calculation_rate_id` INT NOT NULL,
00068 `tax_calculation_rule_id` INT NOT NULL ,
00069 `customer_tax_class_id` SMALLINT( 6 ) NOT NULL ,
00070 `product_tax_class_id` SMALLINT( 6 ) NOT NULL ,
00071 KEY `FK_TAX_CALCULATION_RULE` (`tax_calculation_rule_id`),
00072 KEY `FK_TAX_CALCULATION_RATE` (`tax_calculation_rate_id`),
00073 KEY `FK_TAX_CALCULATION_CTC` (`customer_tax_class_id`),
00074 KEY `FK_TAX_CALCULATION_PTC` (`product_tax_class_id`),
00075 KEY `IDX_TAX_CALCULATION` (`tax_calculation_rate_id`, `customer_tax_class_id`, `product_tax_class_id`)
00076 ) ENGINE = InnoDB;
00077 ");
00078
00079
00080 $installer->getConnection()->addConstraint('FK_TAX_CALCULATION_RATE_TITLE_RATE', $installer->getTable('tax_calculation_rate_title'), 'tax_calculation_rate_id', $installer->getTable('tax_calculation_rate'), 'tax_calculation_rate_id');
00081 $installer->getConnection()->addConstraint('FK_TAX_CALCULATION_RATE_TITLE_STORE', $installer->getTable('tax_calculation_rate_title'), 'store_id', $installer->getTable('core_store'), 'store_id');
00082
00083 $installer->getConnection()->addConstraint('FK_TAX_CALCULATION_RULE', $installer->getTable('tax_calculation'), 'tax_calculation_rule_id', $installer->getTable('tax_calculation_rule'), 'tax_calculation_rule_id');
00084 $installer->getConnection()->addConstraint('FK_TAX_CALCULATION_RATE', $installer->getTable('tax_calculation'), 'tax_calculation_rate_id', $installer->getTable('tax_calculation_rate'), 'tax_calculation_rate_id');
00085 $installer->getConnection()->addConstraint('FK_TAX_CALCULATION_CTC', $installer->getTable('tax_calculation'), 'customer_tax_class_id', $installer->getTable('tax_class'), 'class_id');
00086 $installer->getConnection()->addConstraint('FK_TAX_CALCULATION_PTC', $installer->getTable('tax_calculation'), 'product_tax_class_id', $installer->getTable('tax_class'), 'class_id');
00087
00088
00089 $this->convertOldTaxData();
00090
00091
00092 $installer->run("
00093 DROP TABLE `{$installer->getTable('tax_rule')}`;
00094 DROP TABLE `{$installer->getTable('tax_rate_type')}`;
00095 DROP TABLE `{$installer->getTable('tax_rate_data')}`;
00096 DROP TABLE `{$installer->getTable('tax_rate')}`;
00097 ");
00098
00099
00100 $installer->endSetup();