uc_nap.module

Tracking 6.x-1.x branch
  1. drupal
    1. 6 contributions/nap/modules/uc_nap/uc_nap.module

Functions & methods

NameDescription
uc_nap_ca_triggerImplementation of hook_ca_trigger().
uc_nap_disableImplementation of hook_disable().
uc_nap_enableImplementation of hook_enable().
uc_nap_nap_form_is_productImplementation of hook_nap_form_is_product().
uc_nap_nap_handlerImplementation of hook_nap_handler().
uc_nap_nap_save_purchaseImplementation of hook_nap_save_purchase().
uc_nap_orderImplementation of hook_order().

File

View source
  1. <?php
  2. /**
  3. * Implementation of hook_nap_handler().
  4. */
  5. function uc_nap_nap_handler() {
  6. return array(
  7. // The display name of this module.
  8. 'name' => 'Node Access Product for Ubercart',
  9. // The display name of what we're integrating.
  10. 'integration' => 'Ubercart',
  11. // The short name of the recurring module (FALSE for none).
  12. 'recurring module' => 'uc_recurring',
  13. // The parent path of the settings page.
  14. 'settings path' => 'admin/store/settings',
  15. // The parent path of the reports page.
  16. 'reports path' => 'admin/store',
  17. );
  18. }
  19. /**
  20. * Implementation of hook_enable().
  21. */
  22. function uc_nap_enable() {
  23. drupal_load('module', 'nap');
  24. nap_notify('enable', 'uc_nap');
  25. }
  26. /**
  27. * Implementation of hook_disable().
  28. */
  29. function uc_nap_disable() {
  30. drupal_load('module', 'nap');
  31. nap_notify('disable', 'uc_nap');
  32. }
  33. /**
  34. * Implementation of hook_order().
  35. */
  36. function uc_nap_order($op, $order, $status) {
  37. if ($op == 'update' && $status == 'payment_received') {
  38. if (module_exists("uc_recurring")) {
  39. // Get recurring dates.
  40. $dates = array();
  41. $fees = uc_recurring_get_fees($order, TRUE);
  42. foreach ($fees as $fee) {
  43. $dates[$fee->order_product_id][] = $fee->next_charge;
  44. }
  45. // Reduce to the earliest dates.
  46. foreach ($dates as $key => $value) {
  47. $dates[$key] = min($value);
  48. }
  49. }
  50. // Work out recurring dates.
  51. foreach ($order->products as $i => &$node) {
  52. if (isset($dates[$node->order_product_id])) {
  53. // There is a next charge date.
  54. $node->nap_recurring_date = strftime('%Y-%m-%d %H:%M:%S', $dates[$node->order_product_id]);
  55. }
  56. else {
  57. // No next charge date.
  58. $node->nap_recurring_date = 0;
  59. }
  60. }
  61. nap_save_purchase($order->order_id, $order->uid, $order->products);
  62. }
  63. }
  64. /**
  65. * Implementation of hook_nap_form_is_product().
  66. */
  67. function uc_nap_nap_form_is_product($form, $form_state, $form_id) {
  68. return uc_product_is_product($form['#node']);
  69. }
  70. /**
  71. * Implementation of hook_nap_save_purchase().
  72. */
  73. function uc_nap_nap_save_purchase($nap_purchases, $nap_transaction) {
  74. if (module_exists('ca')) {
  75. $order = uc_order_load($nap_transaction->txn_id);
  76. ca_pull_trigger('uc_nap_purchase', $order);
  77. }
  78. }
  79. /**
  80. * Implementation of hook_ca_trigger().
  81. */
  82. function uc_nap_ca_trigger() {
  83. $triggers = array();
  84. $triggers['uc_nap_purchase'] = array(
  85. '#title' => t('A user purchases a NAP product.'),
  86. '#category' => t('Node access product'),
  87. '#arguments' => array(
  88. 'product' => array(
  89. '#entity' => 'uc_order',
  90. '#title' => t('Order'),
  91. ),
  92. ),
  93. );
  94. return $triggers;
  95. }