// update tax rules PHP => SQL
This commit is contained in:
@@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
function update_tax_rules()
|
|
||||||
{
|
|
||||||
// Add new columns
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
ALTER TABLE `'._DB_PREFIX_.'tax_rule`
|
|
||||||
ADD `zipcode_from` INT NOT NULL AFTER `id_state` ,
|
|
||||||
ADD `zipcode_to` INT NOT NULL AFTER `zipcode_from` ,
|
|
||||||
ADD `behavior` INT NOT NULL AFTER `zipcode_to`,
|
|
||||||
ADD `description` VARCHAR( 100 ) NOT NULL AFTER `id_tax`;
|
|
||||||
');
|
|
||||||
|
|
||||||
// Drop integrity constraint
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
ALTER TABLE `'._DB_PREFIX_.'tax_rule` DROP INDEX tax_rule
|
|
||||||
');
|
|
||||||
|
|
||||||
// Create new format rules
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
INSERT INTO `'._DB_PREFIX_.'tax_rule` (`id_tax_rules_group`, `id_country`, `id_state`, `id_tax`, `behavior`, `zipcode_from`, `zipcode_to`)
|
|
||||||
SELECT r.`id_tax_rules_group`, r.`id_country`, r.`id_state`, r.`id_tax`, 0, z.`from_zip_code`, z.`to_zip_code`
|
|
||||||
FROM `'._DB_PREFIX_.'tax_rule` r INNER JOIN `'._DB_PREFIX_.'county_zip_code` z ON (z.`id_county` = r.`id_county`)
|
|
||||||
');
|
|
||||||
|
|
||||||
// update behavior
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'tax_rule` SET `behavior` = GREATEST(`state_behavior`, `county_behavior`);
|
|
||||||
');
|
|
||||||
|
|
||||||
|
|
||||||
// Clean old entries
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
DELETE FROM `'._DB_PREFIX_.'tax_rule`
|
|
||||||
WHERE `id_county` != 0
|
|
||||||
AND `zipcode_from` = 0
|
|
||||||
');
|
|
||||||
|
|
||||||
// Remove old columns
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
ALTER TABLE `'._DB_PREFIX_.'tax_rule`
|
|
||||||
DROP `id_county`,
|
|
||||||
DROP `state_behavior`,
|
|
||||||
DROP `county_behavior`
|
|
||||||
');
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -33,7 +33,28 @@ INSERT INTO `PREFIX_hook` (
|
|||||||
)
|
)
|
||||||
VALUES ('taxmanager', 'taxmanager', NULL , '1', '0');
|
VALUES ('taxmanager', 'taxmanager', NULL , '1', '0');
|
||||||
|
|
||||||
/* PHP:update_tax_rules(); */;
|
ALTER TABLE `PREFIX_tax_rule`
|
||||||
|
ADD `zipcode_from` INT NOT NULL AFTER `id_state` ,
|
||||||
|
ADD `zipcode_to` INT NOT NULL AFTER `zipcode_from` ,
|
||||||
|
ADD `behavior` INT NOT NULL AFTER `zipcode_to`,
|
||||||
|
ADD `description` VARCHAR( 100 ) NOT NULL AFTER `id_tax`;
|
||||||
|
|
||||||
|
ALTER TABLE `PREFIX_tax_rule` DROP INDEX tax_rule;
|
||||||
|
|
||||||
|
INSERT INTO `PREFIX_tax_rule` (`id_tax_rules_group`, `id_country`, `id_state`, `id_tax`, `behavior`, `zipcode_from`, `zipcode_to`)
|
||||||
|
SELECT r.`id_tax_rules_group`, r.`id_country`, r.`id_state`, r.`id_tax`, 0, z.`from_zip_code`, z.`to_zip_code`
|
||||||
|
FROM `PREFIX_tax_rule` r INNER JOIN `PREFIX_county_zip_code` z ON (z.`id_county` = r.`id_county`);
|
||||||
|
|
||||||
|
UPDATE `PREFIX_tax_rule` SET `behavior` = GREATEST(`state_behavior`, `county_behavior`);
|
||||||
|
|
||||||
|
DELETE FROM `PREFIX_tax_rule`
|
||||||
|
WHERE `id_county` != 0
|
||||||
|
AND `zipcode_from` = 0;
|
||||||
|
|
||||||
|
ALTER TABLE `PREFIX_tax_rule`
|
||||||
|
DROP `id_county`,
|
||||||
|
DROP `state_behavior`,
|
||||||
|
DROP `county_behavior`;
|
||||||
|
|
||||||
/* PHP:remove_tab(AdminCounty); */;
|
/* PHP:remove_tab(AdminCounty); */;
|
||||||
DROP TABLE `PREFIX_county_zip_code`;
|
DROP TABLE `PREFIX_county_zip_code`;
|
||||||
|
|||||||
@@ -133,8 +133,6 @@ require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'create_multistore.php');
|
|||||||
|
|
||||||
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'add_order_state.php');
|
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'add_order_state.php');
|
||||||
|
|
||||||
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'update_tax_rules.php');
|
|
||||||
|
|
||||||
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'remove_tab.php');
|
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'remove_tab.php');
|
||||||
|
|
||||||
//old version detection
|
//old version detection
|
||||||
|
|||||||
Reference in New Issue
Block a user