uc_product_kit.install 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_product_kit module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function uc_product_kit_schema() {
  10. $schema['uc_product_kits'] = array(
  11. 'description' => 'Stores product kit information.',
  12. 'fields' => array(
  13. 'vid' => array(
  14. 'description' => 'The {node}.vid of the product kit.',
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. 'default' => 0,
  19. ),
  20. 'nid' => array(
  21. 'description' => 'The {node}.nid of the product kit.',
  22. 'type' => 'int',
  23. 'unsigned' => TRUE,
  24. 'not null' => TRUE,
  25. 'default' => 0,
  26. ),
  27. 'product_id' => array(
  28. 'description' => 'The {uc_products}.nid of a product contained in the kit.',
  29. 'type' => 'int',
  30. 'unsigned' => TRUE,
  31. 'not null' => TRUE,
  32. 'default' => 0,
  33. ),
  34. 'mutable' => array(
  35. 'description' => 'A flag indicating whether the contents of the kit can be changed by the customer. 1 => Mutable. 0 => Immutable.',
  36. 'type' => 'int',
  37. 'size' => 'tiny',
  38. 'not null' => TRUE,
  39. 'default' => 0,
  40. ),
  41. 'qty' => array(
  42. 'description' => 'The number of this product contained in the kit.',
  43. 'type' => 'int',
  44. 'size' => 'small',
  45. 'unsigned' => TRUE,
  46. 'not null' => TRUE,
  47. 'default' => 0,
  48. ),
  49. 'discount' => array(
  50. 'description' => 'The adjustment to the {uc_products}.sell_price of the product.',
  51. 'type' => 'float',
  52. 'not null' => TRUE,
  53. 'default' => 0.0,
  54. ),
  55. 'ordering' => array(
  56. 'description' => 'The weight of this product in relation to other products in the kit.',
  57. 'type' => 'int',
  58. 'size' => 'small',
  59. 'not null' => TRUE,
  60. 'default' => 0,
  61. ),
  62. 'synchronized' => array(
  63. 'description' => 'A flag indicating that changes to the sell price of this product will change the total price of the kit. 1 => Yes. 0 => No.',
  64. 'type' => 'int',
  65. 'size' => 'tiny',
  66. 'not null' => TRUE,
  67. 'default' => 0,
  68. ),
  69. ),
  70. 'primary key' => array('vid', 'product_id'),
  71. 'foreign keys' => array(
  72. 'node' => array(
  73. 'table' => 'node',
  74. 'columns' => array(
  75. 'nid' => 'nid',
  76. 'vid' => 'vid',
  77. ),
  78. ),
  79. 'uc_products' => array(
  80. 'table' => 'uc_products',
  81. 'columns' => array('product_id' => 'nid'),
  82. ),
  83. ),
  84. );
  85. return $schema;
  86. }
  87. /**
  88. * Implements hook_enable().
  89. */
  90. function uc_product_kit_enable() {
  91. // Hack the product kit node type into the catalog if this module is enabled
  92. // some time after uc_catalog.
  93. if (module_exists('uc_catalog') && $vid = variable_get('uc_catalog_vid', 0)) {
  94. $field = field_info_field('taxonomy_catalog');
  95. if (!isset($field['bundles']['node']['product_kit'])) {
  96. uc_catalog_add_node_type('product_kit');
  97. }
  98. }
  99. // Add the body field.
  100. node_types_rebuild();
  101. $types = node_type_get_types();
  102. node_add_body_field($types['product_kit'], t('Description'));
  103. uc_product_set_teaser_display('product_kit');
  104. // Add a default image field to product kits.
  105. uc_product_add_default_image_field('product_kit');
  106. }
  107. /**
  108. * Implements hook_uninstall().
  109. */
  110. function uc_product_kit_uninstall() {
  111. variable_del('uc_product_kit_mutable');
  112. }
  113. /**
  114. * Implements hook_update_last_removed().
  115. */
  116. function uc_product_kit_update_last_removed() {
  117. return 6003;
  118. }
  119. /**
  120. * Use actual node permissions for product kits.
  121. */
  122. function uc_product_kit_update_7000() {
  123. $node_perms = array_keys(node_list_permissions('product_kit'));
  124. foreach ($node_perms as $node_perm) {
  125. $product_perm = str_replace(array('any', 'product_kit content'), array('all', 'product kits'), $node_perm);
  126. foreach (user_roles(FALSE, $product_perm) as $rid => $role) {
  127. db_merge('role_permission')
  128. ->key(array(
  129. 'rid' => $rid,
  130. 'permission' => $node_perm,
  131. ))
  132. ->fields(array(
  133. 'module' => 'node',
  134. ))
  135. ->execute();
  136. }
  137. // Clean up.
  138. db_delete('role_permission')
  139. ->condition('permission', $product_perm)
  140. ->execute();
  141. }
  142. return t('Changed product node permissions to the actual node permissions.');
  143. }
  144. /**
  145. * Set default display settings for product kit teasers.
  146. */
  147. function uc_product_kit_update_7001() {
  148. uc_product_set_teaser_display('product_kit');
  149. return t('Set display settings for product kit teasers.');
  150. }