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

Contents of /contributions/modules/ubercart/uc_attribute/uc_attribute.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:00 2008 UTC (16 months, 2 weeks ago) by islandusurper
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.9: +423 -136 lines
File MIME type: text/x-php
Begin the Ubercart 6.x-2.x branch.
1 <?php
2 // $Id$
3
4 function uc_attribute_schema() {
5 $schema = array();
6
7 $schema['uc_attributes'] = array(
8 'description' => t('Attributes: the decisions that need to be made about products.'),
9 'fields' => array(
10 'aid' => array(
11 'description' => t('Primary identifier for attributes.'),
12 'type' => 'serial',
13 'unsigned' => TRUE,
14 'not null' => TRUE,
15 ),
16 'name' => array(
17 'type' => 'varchar',
18 'length' => 255,
19 'not null' => TRUE,
20 'default' => '',
21 ),
22 'ordering' => array(
23 'description' => t('Determines the sort order of attributes.'),
24 'type' => 'int',
25 'size' => 'tiny',
26 'not null' => TRUE,
27 'default' => 0,
28 ),
29 'required' => array(
30 'description' => t("Flag that, if set, requires a user response for attributes (disables default options)."),
31 'type' => 'int',
32 'size' => 'tiny',
33 'unsigned' => TRUE,
34 'not null' => TRUE,
35 'default' => 0,
36 ),
37 'display' => array(
38 'description' => t('Display type of the attribute options: 0 -- text fields, 1 -- select box (default), 2 -- radio buttons'),
39 'type' => 'int',
40 'size' => 'tiny',
41 'unsigned' => TRUE,
42 'not null' => TRUE,
43 'default' => 1,
44 ),
45 'description' => array(
46 'description' => t('Description of the attribute.'),
47 'type' => 'varchar',
48 'length' => 255,
49 'not null' => TRUE,
50 'default' => '',
51 ),
52 ),
53 'primary key' => array('aid'),
54 );
55 $schema['uc_attribute_options'] = array(
56 'description' => t('The available choices for each attribute.'),
57 'fields' => array(
58 'aid' => array(
59 'description' => t('The attribute ID.'),
60 'type' => 'int',
61 'unsigned' => TRUE,
62 'not null' => TRUE,
63 'default' => 0,
64 ),
65 'oid' => array(
66 'description' => t('The option ID.'),
67 'type' => 'serial',
68 'unsigned' => TRUE,
69 'not null' => TRUE,
70 ),
71 'name' => array(
72 'description' => t('The name of the option.'),
73 'type' => 'varchar',
74 'length' => 255,
75 'not null' => TRUE,
76 'default' => '',
77 ),
78 'cost' => array(
79 'description' => t("The adjustment to a product's cost with the chosen option."),
80 'type' => 'numeric',
81 'precision' => 10,
82 'scale' => 2,
83 'not null' => TRUE,
84 'default' => 0,
85 ),
86 'price' => array(
87 'description' => t("The adjustment to a product's price with the chosen option."),
88 'type' => 'numeric',
89 'precision' => 10,
90 'scale' => 2,
91 'not null' => TRUE,
92 'default' => 0,
93 ),
94 'weight' => array(
95 'description' => t("The adjustment to a product's physical weight with the chosen option."),
96 'type' => 'float',
97 'not null' => TRUE,
98 'default' => 0,
99 ),
100 'ordering' => array(
101 'description' => t('Affects the sort order of the options.'),
102 'type' => 'int',
103 'size' => 'tiny',
104 'not null' => TRUE,
105 'default' => 0,
106 ),
107 ),
108 'primary key' => array('oid'),
109 );
110 $schema['uc_class_attributes'] = array(
111 'description' => t('Attributes copied to a product of a certain class when it is created.'),
112 'fields' => array(
113 'pcid' => array(
114 'description' => t('The product node type.'),
115 'type' => 'varchar',
116 'length' => 32,
117 'not null' => TRUE,
118 'default' => '',
119 ),
120 'aid' => array(
121 'description' => t('Primary identifier for attributes.'),
122 'type' => 'int',
123 'unsigned' => TRUE,
124 'not null' => TRUE,
125 'default' => 0,
126 ),
127 'ordering' => array(
128 'description' => t('Determines the sort order of attributes.'),
129 'type' => 'int',
130 'size' => 'tiny',
131 'not null' => TRUE,
132 'default' => 0,
133 ),
134 'default_option' => array(
135 'description' => t('The default value of the attribute field on the add to cart form.'),
136 'type' => 'int',
137 'unsigned' => TRUE,
138 'not null' => TRUE,
139 'default' => 0,
140 ),
141 'required' => array(
142 'description' => t("Flag that, if set, requires a user response for attributes (disables default options)."),
143 'type' => 'int',
144 'size' => 'tiny',
145 'unsigned' => TRUE,
146 'not null' => TRUE,
147 'default' => 0,
148 ),
149 'display' => array(
150 'description' => t('Display type of the attribute options: 0 -- text fields, 1 -- select box (default), 2 -- radio buttons'),
151 'type' => 'int',
152 'size' => 'tiny',
153 'unsigned' => TRUE,
154 'not null' => TRUE,
155 'default' => 1,
156 ),
157 ),
158 'primary key' => array('pcid', 'aid'),
159 );
160 $schema['uc_class_attribute_options'] = array(
161 'description' => t('The available choices for each attribute.'),
162 'fields' => array(
163 'pcid' => array(
164 'description' => t('The product node type.'),
165 'type' => 'varchar',
166 'length' => 32,
167 'not null' => TRUE,
168 'default' => '',
169 ),
170 'oid' => array(
171 'description' => t('The option ID.'),
172 'type' => 'int',
173 'unsigned' => TRUE,
174 'not null' => TRUE,
175 'default' => 0,
176 ),
177 'cost' => array(
178 'description' => t("The adjustment to a product's cost with the chosen option."),
179 'type' => 'numeric',
180 'precision' => 10,
181 'scale' => 2,
182 'not null' => TRUE,
183 'default' => 0,
184 ),
185 'price' => array(
186 'description' => t("The adjustment to a product's price with the chosen option."),
187 'type' => 'numeric',
188 'precision' => 10,
189 'scale' => 2,
190 'not null' => TRUE,
191 'default' => 0,
192 ),
193 'weight' => array(
194 'description' => t("The adjustment to a product's physical weight with the chosen option."),
195 'type' => 'float',
196 'not null' => TRUE,
197 'default' => 0,
198 ),
199 'ordering' => array(
200 'description' => t('Affects the sort order of the options.'),
201 'type' => 'int',
202 'size' => 'tiny',
203 'not null' => TRUE,
204 'default' => 0,
205 ),
206 ),
207 'primary key' => array('pcid', 'oid'),
208 );
209 $schema['uc_product_attributes'] = array(
210 'description' => t('Attributes copied to a product.'),
211 'fields' => array(
212 'nid' => array(
213 'description' => t('The product node ID.'),
214 'type' => 'int',
215 'not null' => TRUE,
216 'default' => 0,
217 ),
218 'aid' => array(
219 'description' => t('Primary identifier for attributes.'),
220 'type' => 'int',
221 'unsigned' => TRUE,
222 'not null' => TRUE,
223 ),
224 'ordering' => array(
225 'description' => t('Determines the sort order of attributes.'),
226 'type' => 'int',
227 'size' => 'tiny',
228 'not null' => TRUE,
229 'default' => 0,
230 ),
231 'default_option' => array(
232 'description' => t('The default value of the attribute field on the add to cart form.'),
233 'type' => 'int',
234 'unsigned' => TRUE,
235 'not null' => TRUE,
236 'default' => 0,
237 ),
238 'required' => array(
239 'description' => t("Flag that, if set, requires a user response for attributes (disables default options)."),
240 'type' => 'int',
241 'size' => 'tiny',
242 'unsigned' => TRUE,
243 'not null' => TRUE,
244 'default' => 0,
245 ),
246 'display' => array(
247 'description' => t('Display type of the attribute options: 0 -- text fields, 1 -- select box (default), 2 -- radio buttons'),
248 'type' => 'int',
249 'size' => 'tiny',
250 'unsigned' => TRUE,
251 'not null' => TRUE,
252 'default' => 1,
253 ),
254 ),
255 'primary key' => array('nid', 'aid'),
256 );
257 $schema['uc_product_options'] = array(
258 'description' => t('The available choices for each attribute.'),
259 'fields' => array(
260 'nid' => array(
261 'description' => t('The product node ID.'),
262 'type' => 'int',
263 'not null' => TRUE,
264 'default' => 0,
265 ),
266 'oid' => array(
267 'description' => t('The option ID.'),
268 'type' => 'int',
269 'unsigned' => TRUE,
270 'not null' => TRUE,
271 ),
272 'cost' => array(
273 'description' => t("The adjustment to a product's cost with the chosen option."),
274 'type' => 'numeric',
275 'precision' => 10,
276 'scale' => 2,
277 'not null' => TRUE,
278 'default' => 0,
279 ),
280 'price' => array(
281 'description' => t("The adjustment to a product's price with the chosen option."),
282 'type' => 'numeric',
283 'precision' => 10,
284 'scale' => 2,
285 'not null' => TRUE,
286 'default' => 0,
287 ),
288 'weight' => array(
289 'description' => t("The adjustment to a product's physical weight with the chosen option."),
290 'type' => 'float',
291 'not null' => TRUE,
292 'default' => 0,
293 ),
294 'ordering' => array(
295 'description' => t('Affects the sort order of the options.'),
296 'type' => 'int',
297 'size' => 'tiny',
298 'not null' => TRUE,
299 'default' => 0,
300 ),
301 ),
302 'primary key' => array('nid', 'oid'),
303 );
304 $schema['uc_product_adjustments'] = array(
305 'description' => t("Changes to a product's SKU based on the possible combination of chosen options."),
306 'fields' => array(
307 'nid' => array(
308 'description' => t('The product node ID.'),
309 'type' => 'int',
310 'unsigned' => TRUE,
311 'not null' => TRUE,
312 'default' => 0,
313 ),
314 'combination' => array(
315 'description' => t('A serialized array whose keys are attribute IDs and values are option IDs.'),
316 'type' => 'varchar',
317 'length' => 255,
318 'not null' => TRUE,
319 'default' => '',
320 ),
321 'model' => array(
322 'description' => t('The SKU representing the product with the combination of options.'),
323 'type' => 'varchar',
324 'length' => 255,
325 'not null' => TRUE,
326 'default' => '',
327 ),
328 ),
329 'indexes' => array(
330 'uc_product_adjustments_nid' => array('nid'),
331 ),
332 );
333
334 return $schema;
335 }
336
337 function uc_attribute_install() {
338 drupal_install_schema('uc_attribute');
339 }
340
341 function uc_attribute_uninstall() {
342 drupal_uninstall_schema('uc_attribute');
343
344 variable_del('uc_attribute_option_price_format');
345 }
346
347 function uc_attribute_update_1() {
348 $ret = array();
349 switch ($GLOBALS['db_type']) {
350 case 'mysql':
351 case 'mysqli':
352 $ret[] = update_sql("ALTER TABLE {uc_attributes} CHANGE name name varchar(255) NOT NULL");
353 $ret[] = update_sql("ALTER TABLE {uc_attributes_options} CHANGE name name varchar(255) NOT NULL");
354 $ret[] = update_sql("RENAME TABLE {uc_attributes_options} TO {uc_attribute_options}");
355 $ret[] = update_sql("ALTER TABLE {uc_product_adjustments} CHANGE model model varchar(255) NOT NULL");
356 $ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attributes} (
357 `pcid` mediumint(9) NOT NULL,
358 `aid` mediumint(9) NOT NULL,
359 `default_option` mediumint(9) NOT NULL default '0',
360 PRIMARY KEY (`pcid`, `aid`)
361 );");
362 $ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attribute_options} (
363 `pcid` mediumint(9) NOT NULL,
364 `oid` mediumint(9) NOT NULL,
365 `price` decimal(10,2) NOT NULL,
366 `weight` float NOT NULL,
367 PRIMARY KEY (`pcid`,`oid`)
368 );");
369 break;
370 case 'pgsql':
371 db_change_column($ret, 'uc_attributes', 'name', 'name', 'varchar(255)', array('not null' => true, 'default' => ''));
372 db_change_column($ret, 'uc_attributes_options', 'name', 'name', 'varchar(255)', array('not null' => true, 'default' => ''));
373 $ret[] = update_sql("ALTER TABLE {uc_attributes_options} RENAME TO {uc_attribute_options}");
374 db_change_column($ret, 'uc_product_adjustments', 'model', 'model', 'varchar(255)', array('not null' => true, 'default' => ''));
375 $ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attributes} (
376 pcid integer NOT NULL default '0',
377 aid integer NOT NULL '0',
378 default_option integer NOT NULL default '0',
379 PRIMARY KEY (pcid, aid)
380 );");
381 $ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attribute_options} (
382 pcid integer NOT NULL default '0',
383 oid integer NOT NULL default '0',
384 price decimal(10,2) NOT NULL,
385 weight float NOT NULL,
386 PRIMARY KEY (pcid,oid)
387 );");
388 break;
389 }
390
391 return $ret;
392 }
393
394 function uc_attribute_update_2() {
395 $ret = array();
396 switch ($GLOBALS['db_type']) {
397 case 'mysql':
398 case 'mysqli':
399 $ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER name");
400 $ret[] = update_sql("ALTER TABLE {uc_attribute_options} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER weight");
401 $ret[] = update_sql("ALTER TABLE {uc_class_attributes} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER aid");
402 $ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER weight");
403 $ret[] = update_sql("ALTER TABLE {uc_product_attributes} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER aid");
404 $ret[] = update_sql("ALTER TABLE {uc_product_options} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER weight");
405 break;
406 case 'pgsql':
407 db_add_column($ret, 'uc_attributes', 'ordering', 'smallint', array('not null' => true, 'default' => 0));
408 db_add_column($ret, 'uc_attribute_options', 'ordering', 'smallint', array('not null' => true, 'default' => 0));
409 db_add_column($ret, 'uc_class_attributes', 'ordering', 'smallint', array('not null' => true, 'default' => 0));
410 db_add_column($ret, 'uc_class_attribute_options', 'ordering', 'smallint', array('not null' => true, 'default' => 0));
411 db_add_column($ret, 'uc_product_attributes', 'ordering', 'smallint', array('not null' => true, 'default' => 0));
412 db_add_column($ret, 'uc_product_options', 'ordering', 'smallint', array('not null' => true, 'default' => 0));
413 }
414 return $ret;
415 }
416
417 function uc_attribute_update_3() {
418 $ret = array();
419 switch ($GLOBALS['db_type']) {
420 case 'mysql':
421 case 'mysqli':
422 $ret[] = update_sql("ALTER TABLE {uc_class_attributes} CHANGE pcid pcid varchar(32) NOT NULL");
423 $ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} CHANGE pcid pcid varchar(32) NOT NULL");
424 break;
425 case 'pgsql':
426 db_change_column($ret, 'uc_class_attributes', 'pcid', 'pcid', 'varchar(32)', array('not null' => true, 'default' => ''));
427 db_change_column($ret, 'uc_class_attribute_options', 'pcid', 'pcid', 'varchar(32)', array('not null' => true, 'default' => ''));
428 break;
429 }
430 return $ret;
431 }
432
433 function uc_attribute_update_4() {
434 $ret = array();
435 switch ($GLOBALS['db_type']) {
436 case 'mysql':
437 case 'mysqli':
438 $ret[] = update_sql("ALTER TABLE {uc_product_adjustments} CHANGE combination combination varchar(255) NOT NULL");
439 $ret[] = update_sql("ALTER TABLE {uc_product_adjustments} ADD PRIMARY KEY (`nid`, `combination`)");
440 break;
441 case 'pgsql':
442 db_change_column($ret, 'uc_product_adjustments', 'combination', 'combination', 'varchar(255)', array('not null' => true, 'default' => ''));
443 $ret[] = update_sql("ALTER TABLE {uc_product_adjustments} ADD PRIMARY KEY (nid, combiination)");
444 }
445 return $ret;
446 }
447
448 function uc_attribute_update_5() {
449 $ret = array();
450 switch ($GLOBALS['db_type']) {
451 case 'mysql':
452 case 'mysqli':
453 $ret[] = update_sql("ALTER TABLE {uc_attribute_options} ADD COLUMN cost decimal(10,2) NOT NULL AFTER name");
454 $ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} ADD COLUMN cost decimal(10,2) NOT NULL AFTER oid");
455 $ret[] = update_sql("ALTER TABLE {uc_product_options} ADD COLUMN cost decimal(10,2) NOT NULL AFTER oid");
456 break;
457 case 'pgsql':
458 db_add_column($ret, 'uc_attribute_options', 'cost', 'decimal(10,2)', array('not null' => true, 'default' => 0.0));
459 db_add_column($ret, 'uc_class_attribute_options', 'cost', 'decimal(10,2)', array('not null' => true, 'default' => 0.0));
460 db_add_column($ret, 'uc_product_options', 'cost', 'decimal(10,2)', array('not null' => true, 'default' => 0.0));
461 break;
462 }
463 return $ret;
464 }
465
466 function uc_attribute_update_6() {
467 $ret = array();
468 switch ($GLOBALS['db_type']) {
469 case 'mysql':
470 case 'mysqli':
471 $ret[] = update_sql("ALTER TABLE {uc_product_attributes} ADD COLUMN required tinyint(2) NOT NULL default 0 AFTER default_option");
472 break;
473 case 'pgsql':
474 db_add_column($ret, 'uc_product_attributes', 'required', 'smallint', array('not null' => true, 'default' => 0));
475 break;
476 }
477 return $ret;
478 }
479
480 function uc_attribute_update_7() {
481 $ret = array();
482 switch ($GLOBALS['db_type']) {
483 case 'mysql':
484 case 'mysqli':
485 $ret[] = update_sql("ALTER TABLE {uc_class_attributes} ADD COLUMN required tinyint(2) NOT NULL default 0 AFTER default_option");
486 break;
487 case 'pgsql':
488 db_add_column($ret, 'uc_class_attributes', 'required', 'smallint', array('not null' => true, 'default' => 0));
489 break;
490 }
491 return $ret;
492 }
493
494 function uc_attribute_update_8() {
495 $ret = array();
496 switch ($GLOBALS['db_type']) {
497 case 'pgsql':
498 $ret[] = update_sql("ALTER TABLE {uc_attribute_options} SET WITHOUT OIDS");
499 $ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} SET WITHOUT OIDS");
500 $ret[] = update_sql("ALTER TABLE {uc_product_options} SET WITHOUT OIDS");
501 break;
502 }
503 return $ret;
504 }
505
506 function uc_attribute_update_9() {
507 $ret = array();
508 switch ($GLOBALS['db_type']) {
509 case 'mysql':
510 case 'mysqli':
511 $ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN required tinyint(2) NOT NULL default 1");
512 $ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN display tinyint(2) NOT NULL default 1");
513 $ret[] = update_sql("ALTER TABLE {uc_class_attributes} ADD COLUMN display tinyint(2) NOT NULL default 1");
514 $ret[] = update_sql("ALTER TABLE {uc_product_attributes} ADD COLUMN display tinyint(2) NOT NULL default 1");
515 break;
516 case 'pgsql':
517 db_add_column($ret, 'uc_attributes', 'required', 'smallint', array('not null' => true, 'default' => 1));
518 db_add_column($ret, 'uc_attributes', 'display', 'smallint', array('not null' => true, 'default' => 1));
519 db_add_column($ret, 'uc_class_attributes', 'display', 'smallint', array('not null' => true, 'default' => 1));
520 db_add_column($ret, 'uc_product_attributes', 'display', 'smallint', array('not null' => true, 'default' => 1));
521 break;
522 }
523 return $ret;
524 }
525
526 function uc_attribute_update_10() {
527 $ret = array();
528 switch ($GLOBALS['db_type']) {
529 case 'mysql':
530 case 'mysqli':
531 $ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN description varchar(255) NOT NULL");
532 break;
533 case 'pgsql':
534 db_add_column($ret, 'uc_attributes', 'description', 'varchar(255)', array('not null' => true, 'default' => ''));
535 break;
536 }
537 return $ret;
538 }

  ViewVC Help
Powered by ViewVC 1.1.2