uc_attribute.install 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_attribute module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function uc_attribute_schema() {
  10. $schema = array();
  11. $schema['uc_attributes'] = array(
  12. 'description' => 'Attributes: the decisions that need to be made about products.',
  13. 'fields' => array(
  14. 'aid' => array(
  15. 'description' => 'Primary key: attribute ID.',
  16. 'type' => 'serial',
  17. 'unsigned' => TRUE,
  18. 'not null' => TRUE,
  19. ),
  20. 'name' => array(
  21. 'description' => 'Name of the attribute.',
  22. 'type' => 'varchar',
  23. 'length' => 255,
  24. 'not null' => TRUE,
  25. 'default' => '',
  26. ),
  27. 'label' => array(
  28. 'description' => 'Label to use when attribute is displayed.',
  29. 'type' => 'varchar',
  30. 'length' => 255,
  31. 'not null' => TRUE,
  32. 'default' => '',
  33. ),
  34. 'ordering' => array(
  35. 'description' => 'Determines the list position of attributes.',
  36. 'type' => 'int',
  37. 'size' => 'tiny',
  38. 'not null' => TRUE,
  39. 'default' => 0,
  40. ),
  41. 'required' => array(
  42. 'description' => 'Flag that, if set, requires a user response for attributes (disables default options).',
  43. 'type' => 'int',
  44. 'size' => 'tiny',
  45. 'unsigned' => TRUE,
  46. 'not null' => TRUE,
  47. 'default' => 0,
  48. ),
  49. 'display' => array(
  50. 'description' => 'Display type of the attribute options: 0 => text fields, 1 => select box (default), 2 => radio buttons.',
  51. 'type' => 'int',
  52. 'size' => 'tiny',
  53. 'unsigned' => TRUE,
  54. 'not null' => TRUE,
  55. 'default' => 1,
  56. ),
  57. 'description' => array(
  58. 'description' => 'Description of the attribute.',
  59. 'type' => 'varchar',
  60. 'length' => 255,
  61. 'not null' => TRUE,
  62. 'default' => '',
  63. ),
  64. ),
  65. 'primary key' => array('aid'),
  66. );
  67. $schema['uc_attribute_options'] = array(
  68. 'description' => 'The available choices for each attribute.',
  69. 'fields' => array(
  70. 'aid' => array(
  71. 'description' => 'The {uc_attributes}.aid.',
  72. 'type' => 'int',
  73. 'unsigned' => TRUE,
  74. 'not null' => TRUE,
  75. 'default' => 0,
  76. ),
  77. 'oid' => array(
  78. 'description' => 'Primary key: the option ID.',
  79. 'type' => 'serial',
  80. 'unsigned' => TRUE,
  81. 'not null' => TRUE,
  82. ),
  83. 'name' => array(
  84. 'description' => 'The name of the option.',
  85. 'type' => 'varchar',
  86. 'length' => 255,
  87. 'not null' => TRUE,
  88. 'default' => '',
  89. ),
  90. 'cost' => array(
  91. 'description' => "The adjustment to a product's cost with the chosen option.",
  92. 'type' => 'numeric',
  93. 'precision' => 16,
  94. 'scale' => 5,
  95. 'not null' => TRUE,
  96. 'default' => 0,
  97. ),
  98. 'price' => array(
  99. 'description' => "The adjustment to a product's price with the chosen option.",
  100. 'type' => 'numeric',
  101. 'precision' => 16,
  102. 'scale' => 5,
  103. 'not null' => TRUE,
  104. 'default' => 0,
  105. ),
  106. 'weight' => array(
  107. 'description' => "The adjustment to a product's physical weight with the chosen option.",
  108. 'type' => 'float',
  109. 'not null' => TRUE,
  110. 'default' => 0,
  111. ),
  112. 'ordering' => array(
  113. 'description' => 'Affects the list position of the options.',
  114. 'type' => 'int',
  115. 'size' => 'tiny',
  116. 'not null' => TRUE,
  117. 'default' => 0,
  118. ),
  119. ),
  120. 'primary key' => array('oid'),
  121. 'indexes' => array(
  122. 'aid' => array('aid'),
  123. ),
  124. 'foreign keys' => array(
  125. 'uc_attributes' => array(
  126. 'table' => 'uc_attributes',
  127. 'columns' => array('aid' => 'aid'),
  128. ),
  129. ),
  130. );
  131. $schema['uc_class_attributes'] = array(
  132. 'description' => 'Attributes copied to a product of a certain class when it is created.',
  133. 'fields' => array(
  134. 'pcid' => array(
  135. 'description' => 'Primary key: the product {node}.type.',
  136. 'type' => 'varchar',
  137. 'length' => 32,
  138. 'not null' => TRUE,
  139. 'default' => '',
  140. ),
  141. 'aid' => array(
  142. 'description' => 'The {uc_attributes}.aid.',
  143. 'type' => 'int',
  144. 'unsigned' => TRUE,
  145. 'not null' => TRUE,
  146. 'default' => 0,
  147. ),
  148. 'label' => array(
  149. 'description' => 'Label to use when attribute is displayed.',
  150. 'type' => 'varchar',
  151. 'length' => 255,
  152. 'not null' => TRUE,
  153. 'default' => '',
  154. ),
  155. 'ordering' => array(
  156. 'description' => 'Determines the list position of attributes.',
  157. 'type' => 'int',
  158. 'size' => 'tiny',
  159. 'not null' => TRUE,
  160. 'default' => 0,
  161. ),
  162. 'default_option' => array(
  163. 'description' => 'The default value of the attribute field on the add to cart form.',
  164. 'type' => 'int',
  165. 'unsigned' => TRUE,
  166. 'not null' => TRUE,
  167. 'default' => 0,
  168. ),
  169. 'required' => array(
  170. 'description' => "A flag indicating that, if set, requires a user response for attributes (disables default options).",
  171. 'type' => 'int',
  172. 'size' => 'tiny',
  173. 'unsigned' => TRUE,
  174. 'not null' => TRUE,
  175. 'default' => 0,
  176. ),
  177. 'display' => array(
  178. 'description' => 'Display type of the attribute options: 0 => text fields, 1 => select box (default), 2 => radio buttons',
  179. 'type' => 'int',
  180. 'size' => 'tiny',
  181. 'unsigned' => TRUE,
  182. 'not null' => TRUE,
  183. 'default' => 1,
  184. ),
  185. ),
  186. 'primary key' => array('pcid', 'aid'),
  187. 'foreign keys' => array(
  188. 'uc_product_classes' => array(
  189. 'table' => 'uc_product_classes',
  190. 'columns' => array('pcid' => 'pcid'),
  191. ),
  192. 'uc_attributes' => array(
  193. 'table' => 'uc_attributes',
  194. 'columns' => array('aid' => 'aid'),
  195. ),
  196. ),
  197. );
  198. $schema['uc_class_attribute_options'] = array(
  199. 'description' => 'The available choices for each attribute.',
  200. 'fields' => array(
  201. 'pcid' => array(
  202. 'description' => 'Primary key: the product {node}.type.',
  203. 'type' => 'varchar',
  204. 'length' => 32,
  205. 'not null' => TRUE,
  206. 'default' => '',
  207. ),
  208. 'oid' => array(
  209. 'description' => 'The {uc_attribute_options}.oid.',
  210. 'type' => 'int',
  211. 'unsigned' => TRUE,
  212. 'not null' => TRUE,
  213. 'default' => 0,
  214. ),
  215. 'cost' => array(
  216. 'description' => "The adjustment to a product's cost with the chosen option.",
  217. 'type' => 'numeric',
  218. 'precision' => 16,
  219. 'scale' => 5,
  220. 'not null' => TRUE,
  221. 'default' => 0,
  222. ),
  223. 'price' => array(
  224. 'description' => "The adjustment to a product's price with the chosen option.",
  225. 'type' => 'numeric',
  226. 'precision' => 16,
  227. 'scale' => 5,
  228. 'not null' => TRUE,
  229. 'default' => 0,
  230. ),
  231. 'weight' => array(
  232. 'description' => "The adjustment to a product's physical weight with the chosen option.",
  233. 'type' => 'float',
  234. 'not null' => TRUE,
  235. 'default' => 0,
  236. ),
  237. 'ordering' => array(
  238. 'description' => 'Affects the list position of the options.',
  239. 'type' => 'int',
  240. 'size' => 'tiny',
  241. 'not null' => TRUE,
  242. 'default' => 0,
  243. ),
  244. ),
  245. 'primary key' => array('pcid', 'oid'),
  246. 'foreign keys' => array(
  247. 'uc_product_classes' => array(
  248. 'table' => 'uc_product_classes',
  249. 'columns' => array('pcid' => 'pcid'),
  250. ),
  251. 'uc_attribute_options' => array(
  252. 'table' => 'uc_attribute_options',
  253. 'columns' => array('oid' => 'oid'),
  254. ),
  255. ),
  256. );
  257. $schema['uc_product_attributes'] = array(
  258. 'description' => 'Attributes copied to a product.',
  259. 'fields' => array(
  260. 'nid' => array(
  261. 'description' => 'The product {node}.nid.',
  262. 'type' => 'int',
  263. 'unsigned' => TRUE,
  264. 'not null' => TRUE,
  265. 'default' => 0,
  266. ),
  267. 'aid' => array(
  268. 'description' => 'The {uc_attributes}.aid.',
  269. 'type' => 'int',
  270. 'unsigned' => TRUE,
  271. 'not null' => TRUE,
  272. 'default' => 0,
  273. ),
  274. 'label' => array(
  275. 'description' => 'Label to use when attribute is displayed',
  276. 'type' => 'varchar',
  277. 'length' => 255,
  278. 'not null' => TRUE,
  279. 'default' => '',
  280. ),
  281. 'ordering' => array(
  282. 'description' => 'Determines the list position of attributes.',
  283. 'type' => 'int',
  284. 'size' => 'tiny',
  285. 'not null' => TRUE,
  286. 'default' => 0,
  287. ),
  288. 'default_option' => array(
  289. 'description' => 'The default value of the attribute field on the add to cart form.',
  290. 'type' => 'int',
  291. 'unsigned' => TRUE,
  292. 'not null' => TRUE,
  293. 'default' => 0,
  294. ),
  295. 'required' => array(
  296. 'description' => "Flag that, if set, requires a user response for attributes (disables default options).",
  297. 'type' => 'int',
  298. 'size' => 'tiny',
  299. 'unsigned' => TRUE,
  300. 'not null' => TRUE,
  301. 'default' => 0,
  302. ),
  303. 'display' => array(
  304. 'description' => 'Display type of the attribute options: 0 -- text fields, 1 -- select box (default), 2 -- radio buttons',
  305. 'type' => 'int',
  306. 'size' => 'tiny',
  307. 'unsigned' => TRUE,
  308. 'not null' => TRUE,
  309. 'default' => 1,
  310. ),
  311. ),
  312. 'primary key' => array('nid', 'aid'),
  313. 'foreign keys' => array(
  314. 'uc_products' => array(
  315. 'table' => 'uc_products',
  316. 'columns' => array('nid' => 'nid'),
  317. ),
  318. 'uc_attributes' => array(
  319. 'table' => 'uc_attributes',
  320. 'columns' => array('aid' => 'aid'),
  321. ),
  322. ),
  323. );
  324. $schema['uc_product_options'] = array(
  325. 'description' => 'The available choices for each attribute.',
  326. 'fields' => array(
  327. 'nid' => array(
  328. 'description' => 'The product {node}.nid.',
  329. 'type' => 'int',
  330. 'unsigned' => TRUE,
  331. 'not null' => TRUE,
  332. 'default' => 0,
  333. ),
  334. 'oid' => array(
  335. 'description' => 'The {uc_attribute_options}.oid.',
  336. 'type' => 'int',
  337. 'unsigned' => TRUE,
  338. 'not null' => TRUE,
  339. 'default' => 0,
  340. ),
  341. 'cost' => array(
  342. 'description' => "The adjustment to a product's cost with the chosen option.",
  343. 'type' => 'numeric',
  344. 'precision' => 16,
  345. 'scale' => 5,
  346. 'not null' => TRUE,
  347. 'default' => 0,
  348. ),
  349. 'price' => array(
  350. 'description' => "The adjustment to a product's price with the chosen option.",
  351. 'type' => 'numeric',
  352. 'precision' => 16,
  353. 'scale' => 5,
  354. 'not null' => TRUE,
  355. 'default' => 0,
  356. ),
  357. 'weight' => array(
  358. 'description' => "The adjustment to a product's physical weight with the chosen option.",
  359. 'type' => 'float',
  360. 'not null' => TRUE,
  361. 'default' => 0,
  362. ),
  363. 'ordering' => array(
  364. 'description' => 'Affects the list position of the options.',
  365. 'type' => 'int',
  366. 'size' => 'tiny',
  367. 'not null' => TRUE,
  368. 'default' => 0,
  369. ),
  370. ),
  371. 'primary key' => array('nid', 'oid'),
  372. 'foreign keys' => array(
  373. 'uc_products' => array(
  374. 'table' => 'uc_products',
  375. 'columns' => array('nid' => 'nid'),
  376. ),
  377. 'uc_attribute_options' => array(
  378. 'table' => 'uc_attribute_options',
  379. 'columns' => array('oid' => 'oid'),
  380. ),
  381. ),
  382. );
  383. $schema['uc_product_adjustments'] = array(
  384. 'description' => "Changes to a product's SKU based on the possible combination of chosen options.",
  385. 'fields' => array(
  386. 'nid' => array(
  387. 'description' => 'The product {node}.nid.',
  388. 'type' => 'int',
  389. 'unsigned' => TRUE,
  390. 'not null' => TRUE,
  391. 'default' => 0,
  392. ),
  393. 'combination' => array(
  394. 'description' => 'A serialized array whose keys are attribute IDs and values are option IDs.',
  395. 'type' => 'varchar',
  396. 'length' => 255,
  397. 'not null' => TRUE,
  398. 'default' => '',
  399. 'serialize' => TRUE,
  400. ),
  401. 'model' => array(
  402. 'description' => 'The SKU representing the product with the combination of options.',
  403. 'type' => 'varchar',
  404. 'length' => 255,
  405. 'not null' => TRUE,
  406. 'default' => '',
  407. ),
  408. ),
  409. 'indexes' => array(
  410. 'nid' => array('nid'),
  411. ),
  412. 'foreign keys' => array(
  413. 'uc_products' => array(
  414. 'table' => 'uc_products',
  415. 'columns' => array('nid' => 'nid'),
  416. ),
  417. ),
  418. );
  419. return $schema;
  420. }
  421. /**
  422. * Implements hook_uninstall().
  423. */
  424. function uc_attribute_uninstall() {
  425. variable_del('uc_attribute_option_price_format');
  426. }
  427. /**
  428. * Implements hook_update_dependencies().
  429. */
  430. function uc_attribute_update_dependencies() {
  431. $dependencies['uc_attribute'][7000] = array(
  432. 'filter' => 7005,
  433. );
  434. return $dependencies;
  435. }
  436. /**
  437. * Implements hook_update_last_removed().
  438. */
  439. function uc_attribute_update_last_removed() {
  440. return 6005;
  441. }
  442. /**
  443. * Add description format for attributes.
  444. */
  445. function uc_attribute_update_7000() {
  446. db_add_field('uc_attributes', 'format', array(
  447. 'description' => 'Format of the attribute description.',
  448. 'type' => 'int',
  449. 'not null' => TRUE,
  450. 'default' => 0,
  451. ));
  452. db_update('uc_attributes')
  453. ->fields(array('format' => 0))
  454. ->execute();
  455. }
  456. /**
  457. * Change default description format to NULL.
  458. */
  459. function uc_attribute_update_7001() {
  460. db_change_field('uc_attributes', 'format', 'format', array(
  461. 'description' => 'Format of the attribute description.',
  462. 'type' => 'int',
  463. 'not null' => FALSE,
  464. 'default' => NULL,
  465. ));
  466. db_update('uc_attributes')
  467. ->fields(array('format' => filter_fallback_format()))
  468. ->execute();
  469. }
  470. /**
  471. * Remove attribute description format..
  472. */
  473. function uc_attribute_update_7002() {
  474. db_drop_field('uc_attributes', 'format');
  475. }
  476. /**
  477. * Add index to attribute options table.
  478. */
  479. function uc_attribute_update_7003() {
  480. // Indexes may have been added in 6.x-2.x.
  481. if (!db_index_exists('uc_attribute_options', 'aid')) {
  482. db_add_index('uc_attribute_options', 'aid', array('aid'));
  483. }
  484. }