Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-14916

Implement automatically applied discounts for membership fees

    Details

    • Type: Task
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 4.5
    • Fix Version/s: 4.7
    • Component/s: CiviMember
    • Labels:
      None
    • Documentation Required?:
      None

      Description

      The v2.5 release of CiviDiscount (4.4 compatible) includes the ability to automatically assign discounts to membership fees based criteria (age, contact type, country ...). This functionality was not implemented in the 2.6 (4.5 compatible release) - but should be added for feature completeness as time allows.

      Here's some notes from Eileen as to where the functionality is implemented in 2.5 / 4.4:
      =================
      The application of discounts to memberships has been deliberately disabled disabled in the upstream version with these comments
      //since we cannot choose online contribution page as criteria for creating discount code so
      //we need to bypass the check for entity=membership

      I tried to check if there was some problem with mine but it seemed ok - see in the pic below the discount has been applied to 2 * membership types (but not lifetime) and not the non-membership item.

      But, maybe I'm missing something? I've updated my repo (https://github.com/eileenmcnaughton/org.civicrm.module.cividiscount) so that it works against 4.4 AND 4.5 (I sacrificed the 'disable' button in 4.4 ). So you can switch between the branches & compare the behaviour easily on your 4.5 version.

      I did a write up (at the bottom) of the discountCalculator flow - there are some differences in the 2 versions - but I guess now I'm wondering if I'm missing something that caused Monish to disable auto-memberships - as I say it seems to work here & my quick test on membership block page looked OK too.

      Basically in function __construct the list of discounts is loaded into $this->discounts

      https://github.com/eileenmcnaughton/org.civicrm.module.cividiscount/blob/4.4/CRM/CiviDiscount/DiscountCalculator.php#L79
      https://github.com/dlobo/org.civicrm.module.cividiscount/blob/master/CRM/CiviDiscount/DiscountCalculator.php#L55
      (note the big differences in line numbers are mostly due to phpdoc comments not length of code)

      In function getDiscounts further filters are applied & relevant discounts are returned - (the functions are not exactly the same in how they interact with the form variables.)
      https://github.com/eileenmcnaughton/org.civicrm.module.cividiscount/blob/4.4/CRM/CiviDiscount/DiscountCalculator.php#L98
      https://github.com/dlobo/org.civicrm.module.cividiscount/blob/master/CRM/CiviDiscount/DiscountCalculator.php#L72

      The key filter here is filterByContact which determines the autodiscounts.
      https://github.com/eileenmcnaughton/org.civicrm.module.cividiscount/blob/4.4/CRM/CiviDiscount/DiscountCalculator.php#L138
      https://github.com/dlobo/org.civicrm.module.cividiscount/blob/master/CRM/CiviDiscount/DiscountCalculator.php#L101

      This function has diverged somewhat. In mine I set $this->autodiscounts (array), $this->auto_discount_applies &

      $this->discount_unavailable_message

      The upstream version does seems to still set $this->autodiscounts but it does some special handling around memberships.

        Attachments

          Activity

            People

            • Assignee:
              monish.deb Monish Deb
              Reporter:
              dgg David Greenberg
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: