uc_cart_links.module 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @file
  4. * Allows store owners to create links to add products to carts and send
  5. * customers on to checkout.
  6. */
  7. /**
  8. * Implements hook_help().
  9. */
  10. function uc_cart_links_help($section = 'admin/help#uc_cart_links', $arg = NULL) {
  11. switch ($section) {
  12. case 'admin/store/settings/cart-links':
  13. if (module_exists('help')) {
  14. return '<p>' . t('<a href="!url">View the help page</a> to learn how to create Cart Links.', array('!url' => url('admin/help/uc_cart_links'))) . '</p>';
  15. }
  16. break;
  17. case 'admin/help#uc_cart_links':
  18. case 'admin/help/cart-links':
  19. module_load_include('inc', 'uc_cart_links', 'uc_cart_links.admin');
  20. $build = uc_cart_links_creation_help();
  21. return drupal_render($build);
  22. }
  23. }
  24. /**
  25. * Implements hook_menu().
  26. */
  27. function uc_cart_links_menu() {
  28. $items['admin/store/settings/cart-links'] = array(
  29. 'title' => 'Cart links',
  30. 'description' => 'Configure and craft special links to add products directly to the cart.',
  31. 'page callback' => 'drupal_get_form',
  32. 'page arguments' => array('uc_cart_links_settings_form'),
  33. 'access arguments' => array('administer cart links'),
  34. 'file' => 'uc_cart_links.admin.inc',
  35. );
  36. $items['admin/store/reports/cart-links'] = array(
  37. 'title' => 'Cart links',
  38. 'description' => 'Track clicks through Cart Links.',
  39. 'page callback' => 'uc_cart_links_report',
  40. 'access arguments' => array('view cart links report'),
  41. 'file' => 'uc_cart_links.admin.inc',
  42. );
  43. $items['cart/add/%'] = array(
  44. 'title' => 'Add to cart',
  45. 'page callback' => 'drupal_get_form',
  46. 'page arguments' => array('uc_cart_links_form', 2),
  47. 'access arguments' => array('access content'),
  48. 'type' => MENU_CALLBACK,
  49. 'file' => 'uc_cart_links.pages.inc',
  50. );
  51. return $items;
  52. }
  53. /**
  54. * Implements hook_permission().
  55. */
  56. function uc_cart_links_permission() {
  57. return array(
  58. 'administer cart links' => array(
  59. 'title' => t('Administer cart links'),
  60. ),
  61. 'view cart links report' => array(
  62. 'title' => t('View cart links report'),
  63. ),
  64. );
  65. }
  66. /**
  67. * Implements hook_uc_add_to_cart().
  68. */
  69. function uc_cart_links_uc_add_to_cart($nid, $qty, $data) {
  70. if (user_access('administer cart links') &&
  71. variable_get('uc_cart_links_add_show', FALSE)) {
  72. $cart_link = 'p' . $nid . '_q' . $qty;
  73. if (!empty($data['attributes'])) {
  74. foreach ($data['attributes'] as $attribute => $option) {
  75. if (is_array($option)) {
  76. // Checkbox options are stored in an array.
  77. foreach ($option as $oid => $ovalue) {
  78. if ($ovalue != 0) {
  79. $cart_link .= '_a' . $attribute . 'o' . $oid;
  80. }
  81. }
  82. }
  83. else {
  84. // Textfield, Select, or Radio options.
  85. $cart_link .= '_a' . $attribute . 'o' . $option;
  86. }
  87. }
  88. }
  89. drupal_set_message(t('Cart Link product action: @cart_link', array('@cart_link' => $cart_link)));
  90. }
  91. }