You are here

README.txt in Ubercart Discounts (Alternative) 6.2

Same filename and directory in other branches
  1. 7.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 
Ubercart 2.


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 "administer" -> "modules" and enable the module.

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