/[drupal]/contributions/modules/ubercart/uc_taxes/uc_taxes.install
ViewVC logotype

Contents of /contributions/modules/ubercart/uc_taxes/uc_taxes.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Thu Jul 10 12:41:07 2008 UTC (16 months, 2 weeks ago) by islandusurper
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.9: +68 -50 lines
File MIME type: text/x-php
Begin the Ubercart 6.x-2.x branch.
1 <?php
2 // $Id$
3
4 function uc_taxes_schema() {
5 $schema = array();
6
7 $schema['uc_taxes'] = array(
8 'fields' => array(
9 'id' => array(
10 'type' => 'serial',
11 'unsigned' => TRUE,
12 'not null' => TRUE,
13 ),
14 'name' => array(
15 'type' => 'varchar',
16 'length' => 255,
17 'not null' => TRUE,
18 'default' => '',
19 ),
20 'rate' => array(
21 'type' => 'float',
22 'unsigned' => TRUE,
23 'not null' => TRUE,
24 'default' => 0.0,
25 ),
26 'taxed_product_types' => array(
27 'description' => t('Serialized array of node types to be taxed.'),
28 'type' => 'text',
29 ),
30 'taxed_line_items' => array(
31 'description' => t('Serialized array of line item types to be taxed.'),
32 'type' => 'text',
33 ),
34 'weight' => array(
35 'type' => 'int',
36 'size' => 'tiny',
37 'not null' => TRUE,
38 'default' => 0,
39 ),
40 ),
41 'primary key' => array('id'),
42 );
43
44 return $schema;
45 }
46
47 function uc_taxes_install() {
48 drupal_install_schema('uc_taxes');
49 }
50
51 function uc_taxes_uninstall() {
52 drupal_uninstall_schema('uc_taxes');
53 }
54
55 function uc_taxes_update_1() {
56 $ret = array();
57 switch ($GLOBALS['db_type']) {
58 case 'mysql':
59 case 'mysqli':
60 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP INDEX taxes");
61 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP pcid");
62 $ret[] = update_sql("ALTER TABLE {uc_taxes} ADD COLUMN id mediumint(9) NOT NULL FIRST");
63 $ret[] = update_sql("ALTER TABLE {uc_taxes} ADD PRIMARY KEY id (id)");
64 $ret[] = update_sql("ALTER TABLE {uc_taxes} ADD COLUMN name varchar(255) NOT NULL AFTER id");
65 $ret[] = update_sql("ALTER TABLE {uc_taxes} CHANGE COLUMN area area varchar(255) NOT NULL");
66 $ret[] = update_sql("ALTER TABLE {uc_taxes} CHANGE COLUMN type type enum('code','zone','country') NOT NULL");
67 $ret[] = update_sql("ALTER TABLE {uc_taxes} CHANGE COLUMN standalone cumulative tinyint(1) NOT NULL default '0'");
68 $ret[] = update_sql("ALTER TABLE {uc_taxes} ADD COLUMN weight tinyint(2) NOT NULL default '0'");
69 break;
70 case 'pgsql':
71 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP CONSTRAINT {uc_taxes}_pcid_area_key");
72 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP pcid");
73 db_add_column($ret, 'uc_taxes', 'id', 'integer', array('not null' => true, 'default' => 0));
74 $ret[] = update_sql("ALTER TABLE {uc_taxes} ADD PRIMARY KEY (id)");
75 $ret[] = update_sql("CREATE INDEX {uc_taxes}_id ON {uc_taxes} (id)");
76 db_add_column($ret, 'uc_taxes', 'name', 'varchar(255)', array('not null' => true, 'default' => ''));
77 db_change_column($ret, 'uc_taxes', 'area', 'area', 'varchar(255)', array('not null' => true, 'default' => ''));
78 db_change_column($ret, 'uc_taxes', 'type', 'type', "enum('code','zone','country')", array('not null' => true, 'default' => 'code'));
79 db_change_column($ret, 'uc_taxes', 'standalone', 'cumulative', 'smallint', array('not null' => true, 'default' => 0));
80 db_add_column($ret, 'uc_taxes', 'weight', 'smallint', array('not null' => true, 'default' => 0));
81 break;
82 }
83 return $ret;
84 }
85
86 function uc_taxes_update_2() {
87 $ret = array();
88 switch ($GLOBALS['db_type']) {
89 case 'mysql':
90 case 'mysqli':
91 $ret[] = update_sql("ALTER TABLE {uc_taxes} CHANGE COLUMN shipping taxed_line_items text NOT NULL");
92 break;
93 case 'pgsql':
94 db_change_column($ret, 'uc_taxes', 'shipping', 'taxed_line_items', 'text', array('not null' => true, 'default' => ''));
95 break;
96 }
97 return $ret;
98 }
99
100 function uc_taxes_update_3() {
101 $ret = array();
102 switch ($GLOBALS['db_type']) {
103 case 'mysql':
104 case 'mysqli':
105 $ret[] = update_sql("ALTER TABLE {uc_taxes} ADD COLUMN conditions text NOT NULL");
106 break;
107 case 'pgsql':
108 db_add_column($ret, 'uc_taxes', 'conditions', 'text', array('not null' => true, 'default' => ''));
109 break;
110 }
111
112 return $ret;
113 }
114
115 function uc_taxes_update_4() {
116 $result = db_query("SELECT id, taxed_line_items FROM {uc_taxes} WHERE cumulative != 0");
117 while ($tax = db_fetch_object($result)) {
118 if ($taxed_line_items = unserialize($tax->taxed_line_items) && is_array($taxed_line_items)) {
119 $taxed_line_items['tax'] = 'tax';
120 db_query("UPDATE {uc_taxes} SET taxed_line_items = '%s' WHERE id = %d", serialize($taxed_line_items), $tax->id);
121 }
122 }
123
124 $ret = array();
125 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP cumulative");
126
127 return $ret;
128 }
129
130 function uc_taxes_update_5() {
131 $ret = array();
132
133 switch ($GLOBALS['db_type']) {
134 case 'mysql':
135 case 'mysqli':
136 $ret[] = update_sql("ALTER TABLE {uc_taxes} ADD COLUMN taxed_product_types text NOT NULL AFTER rate");
137 break;
138 case 'pgsql':
139 db_add_column($ret, 'uc_taxes', 'taxed_product_types', 'text', array('not null' => true, 'default' => ''));
140 break;
141 }
142
143 $types = array();
144 foreach (module_invoke_all('product_types') as $type) {
145 $types[$type] = $type;
146 }
147 db_query("UPDATE {uc_taxes} SET taxed_product_types = '%s'", serialize($types));
148
149 return $ret;
150 }
151
152 function uc_taxes_update_6() {
153 $ret = array();
154 if (module_exists('workflow_ng_ui')) {
155 $configurations = array();
156 $taxes = uc_taxes_get_rates();
157 foreach ($taxes as $tax) {
158 $configurations['uc_taxes_'. $tax->id] = array(
159 '#name' => 'uc_taxes_'. $tax->id,
160 '#label' => $tax->name,
161 '#event' => 'calculate_tax_'. $tax->id,
162 '#module' => 'uc_taxes',
163 '#active' => true,
164 );
165 $action = workflow_ng_use_action('uc_taxes_action_apply_tax', array(
166 '#label' => t('Apply @tax', array('@tax' => $tax->name)),
167 ));
168 switch ($tax->type) {
169 case 'code':
170 $area_condition = workflow_ng_use_condition('uc_order_condition_delivery_postal_code', array(
171 '#label' => t('Is in postal code area @code', array('@code' => $tax->area)),
172 '#settings' => array(
173 'pattern' => $tax->area,
174 ),
175 ));
176 break;
177 case 'zone':
178 $zone = uc_get_zone_code($tax->area);
179 $area_condition = workflow_ng_use_condition('uc_order_condition_delivery_zone', array(
180 '#label' => t('Is in @zone', array('@zone' => $zone)),
181 '#settings' => array(
182 'zones' => array($tax->area),
183 ),
184 ));
185 break;
186 case 'country':
187 $country = uc_get_country_data(array('country_id' => $tax->area));
188 $country_name = $country[0]['country_name'];
189 $area_condition = workflow_ng_use_condition('uc_order_condition_delivery_country', array(
190 '#label' => t('Is in @country', array('@country' => $country_name)),
191 '#settings' => array(
192 'countries' => array($tax->area),
193 ),
194 ));
195 break;
196 }
197 $configurations['uc_taxes_'. $tax->id] = workflow_ng_configure($configurations['uc_taxes_'. $tax->id], $action, $area_condition);
198 workflow_ng_ui_save_configuration($configurations['uc_taxes_'. $tax->id]);
199 }
200 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP area");
201 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP type");
202 $ret[] = update_sql("ALTER TABLE {uc_taxes} DROP conditions");
203 }
204 return $ret;
205 }

  ViewVC Help
Powered by ViewVC 1.1.2