You are here

README.txt in Ubercart Discounts (Alternative) 7.2

Same filename and directory in other branches
  1. 6.2 README.txt
Drupal Ubercart Discounts Alternative
-------------------------------------
Authors - Ryan Groe ryan at groe dot org, jrust, davexoxide, ezra-g
License - GPL (see LICENSE)

Overview:
--------
The uc_discounts_alt module allows for coded and codeless discounts designed for 
use with Ubercart.


Installation:
------------
1. Place this module directory in your modules folder (this will usually be 
   "sites/all/modules/" or "sites/all/modules/ubercart").
2. Go to "Administration" -> "Modules" and enable the "Discounts" module under
   "Ubercart - core (optional)".

How to install the codeless_discounts_field:
** Codeless discounts module has not yet been ported to drupal 7 **
  Enable the module
  go to <site>/admin/content/node-type/product/fields and under "Add" "New Field" enter:
  Label: Codeless Discount
  Field name: field_codeless_discount
  Type of data: Codeless Discount
  Form element: Default Display

  Then you can reorder the fields as you like. You can also theme this
    field (see theme_codeless_discounts_field_get_codeless_discount_html_for_product).

How to install the product_price_alterer_field:
** Price alterer field module has not yet been ported to drupal 7 **
  Enable the module
  go to <site>/admin/content/node-type/product/fields and under "Add" "New Field" enter:
  Label: Discounted price (change label to your choosing)
  Field name: field_discounted_price
  Type of data: Discounted Price
  Form element: Default Display

  Suggested:
    go to <site>/admin/content/node-type/product/display and change the label for the field to "<Inline>"

  Then you can reorder the fields as you like. You can also theme this
    field (see theme_product_price_alterer_field_get_price_alterer_html_for_discounts).


Configuration:
-------------
1. Grant the "configure discounts" permission to the proper roles.
2. Create discounts from the menu item 
  "Store administration->Discounts->Add".

Conditional Actions:
--------------------
Two new conditional actions are implemented which allow an order to interact with discounts:
1. Check the order total after discounts have been applied
2. Check if a discount has been applied to the order


Hooks:
------
Allows you to hook into a discount to implement custom logic.

/**
 * hook_uc_discount() example
 *
 * Allows for a discount to be modified when it is being loaded/saved/delted
 *
 * @param $op The discount operation: load, save, or delete
 * @param $arg2 Optional argument.  Order object is passed in when discounts for an order are being calculated.
 */
function mymodule_uc_discount($op, &$discount, $arg2 = NULL) {
  switch($op) {
    case 'delete':
    case 'save':
      $product_ids = get_product_ids_for_discount_object($discount);
      foreach ($product_ids as $nid) {
        // do something with each affected node (expire cache, etc.)
      }
      break;
    case 'load':
      // Modify a discount to not be applied unless a condition passes
      if (!is_null($arg2) && $discount->discount_id == 1 && $order->billing_zone != 1) {
        $discount->is_active = FALSE;
      }
      break;
  }
}

/**
 * hook_uc_discounts_codes_alter() example
 *
 * Allows for the discount codes that a customer submits to be altered or for the order
 * to be altered based on the discount codes.
 *
 * @param $order Order object with uc_discounts_codes array set
 * @param $context Either 'js_calculate' or 'pane_submit'
 */
function mymodule_uc_discounts_codes_alter($order, $context) {
  // Do something if a certain code is entered
  foreach ($order->uc_discounts_codes as $code) {
    if (strtolower($code) == 'special_code') {
      // add another item to the cart, etc.
    }
  }
}

File

README.txt
View source
  1. Drupal Ubercart Discounts Alternative
  2. -------------------------------------
  3. Authors - Ryan Groe ryan at groe dot org, jrust, davexoxide, ezra-g
  4. License - GPL (see LICENSE)
  5. Overview:
  6. --------
  7. The uc_discounts_alt module allows for coded and codeless discounts designed for
  8. use with Ubercart.
  9. Installation:
  10. ------------
  11. 1. Place this module directory in your modules folder (this will usually be
  12. "sites/all/modules/" or "sites/all/modules/ubercart").
  13. 2. Go to "Administration" -> "Modules" and enable the "Discounts" module under
  14. "Ubercart - core (optional)".
  15. How to install the codeless_discounts_field:
  16. ** Codeless discounts module has not yet been ported to drupal 7 **
  17. Enable the module
  18. go to /admin/content/node-type/product/fields and under "Add" "New Field" enter:
  19. Label: Codeless Discount
  20. Field name: field_codeless_discount
  21. Type of data: Codeless Discount
  22. Form element: Default Display
  23. Then you can reorder the fields as you like. You can also theme this
  24. field (see theme_codeless_discounts_field_get_codeless_discount_html_for_product).
  25. How to install the product_price_alterer_field:
  26. ** Price alterer field module has not yet been ported to drupal 7 **
  27. Enable the module
  28. go to /admin/content/node-type/product/fields and under "Add" "New Field" enter:
  29. Label: Discounted price (change label to your choosing)
  30. Field name: field_discounted_price
  31. Type of data: Discounted Price
  32. Form element: Default Display
  33. Suggested:
  34. go to /admin/content/node-type/product/display and change the label for the field to ""
  35. Then you can reorder the fields as you like. You can also theme this
  36. field (see theme_product_price_alterer_field_get_price_alterer_html_for_discounts).
  37. Configuration:
  38. -------------
  39. 1. Grant the "configure discounts" permission to the proper roles.
  40. 2. Create discounts from the menu item
  41. "Store administration->Discounts->Add".
  42. Conditional Actions:
  43. --------------------
  44. Two new conditional actions are implemented which allow an order to interact with discounts:
  45. 1. Check the order total after discounts have been applied
  46. 2. Check if a discount has been applied to the order
  47. Hooks:
  48. ------
  49. Allows you to hook into a discount to implement custom logic.
  50. /**
  51. * hook_uc_discount() example
  52. *
  53. * Allows for a discount to be modified when it is being loaded/saved/delted
  54. *
  55. * @param $op The discount operation: load, save, or delete
  56. * @param $arg2 Optional argument. Order object is passed in when discounts for an order are being calculated.
  57. */
  58. function mymodule_uc_discount($op, &$discount, $arg2 = NULL) {
  59. switch($op) {
  60. case 'delete':
  61. case 'save':
  62. $product_ids = get_product_ids_for_discount_object($discount);
  63. foreach ($product_ids as $nid) {
  64. // do something with each affected node (expire cache, etc.)
  65. }
  66. break;
  67. case 'load':
  68. // Modify a discount to not be applied unless a condition passes
  69. if (!is_null($arg2) && $discount->discount_id == 1 && $order->billing_zone != 1) {
  70. $discount->is_active = FALSE;
  71. }
  72. break;
  73. }
  74. }
  75. /**
  76. * hook_uc_discounts_codes_alter() example
  77. *
  78. * Allows for the discount codes that a customer submits to be altered or for the order
  79. * to be altered based on the discount codes.
  80. *
  81. * @param $order Order object with uc_discounts_codes array set
  82. * @param $context Either 'js_calculate' or 'pane_submit'
  83. */
  84. function mymodule_uc_discounts_codes_alter($order, $context) {
  85. // Do something if a certain code is entered
  86. foreach ($order->uc_discounts_codes as $code) {
  87. if (strtolower($code) == 'special_code') {
  88. // add another item to the cart, etc.
  89. }
  90. }
  91. }