CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Conditional pricing options and price set templates?
Pages: [1] 2

Author Topic: Conditional pricing options and price set templates?  (Read 5364 times)

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Conditional pricing options and price set templates?
October 05, 2010, 01:41:33 pm
I'm working on a CiviCRM/Drupal installation for an organization that puts on workshops with many signup options, including length, since people sometimes attend partial workshops.  Many other options' prices, in turn, need to depend on the length field - for example, housing option pricing needs to be adjusted based on length of attendance selected, since a private room for a weekend would not cost nearly as much as a private room for a full week.  Registrants would select their workshop length, and the rest of the options would either already be on the page with values based on a default length option, and prices would adjust accordingly, or there would be a new page presenting the rest of the options.  The entire fee structure would look conceptually more like a two dimensional grid than a flat list (actual prices are hypothetical):

Code: [Select]
Length of Attendance      Full Week | Thursday-Sunday | Weekend only

Workshop fee            
  Track A                 700         500               300
  Track B                 700         500               300
  Track C                 900         700               400

Housing options
  Shared dorm             340         120               70
  Private room            600         300               200
  Camping                 210         100               60

Meal options
  Normal                  250         100               50
  High-protein            300         120               60

Also, CiviCRM's way of handling price sets - as available for all events - isn't quite right for this organization's needs - they'd need to have price sets perhaps as starting templates, but allow the specifics, like the costs of various options, and perhaps even the options themselves, to vary event by event.  It doesn't make sense for us to accumulate as many global price sets as we have events.

There does not appear to be anything built-in that would allow for these two things.  Does anyone have any insight?  It seems that hook_civicrm_buildAmount is my friend here, although I don't know if there's an idiomatic way to do this that I haven't found yet.  Greatly appreciated.  Thank you!
« Last Edit: October 25, 2010, 11:58:16 am by jakecivi »

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 10, 2010, 01:04:01 pm
Our needs are actually more complex now than the previous post indicates, and the developers on the IRC channel suggested making a contribution to CiviCRM core, so I'm going for a more general solution.

Upon event creation, the creator will be able to define an arbitrary number of radio-button independent and dependent fields that affect event pricing.  In creating dependent fields, the creator will define dependencies by specifying which, if any, independent fields affect each dependent variable's pricing.  The creator will then specify, in extreme long-hand, every possible pricing attached to each dependent field's possible values, given the selected values for the independent fields it depends on.  The ui for this will be similar to the Discount Sets interface - it would present the creator with a series of tables to fill out based on the variable specifications.  It would be a somewhat lengthy creation process, but the promise of a robust signup process would make it worth the time.

The event creator would also specify a series of "attributes" for each event, for which each signup will be recorded with a boolean value.  They will have names like "Monday lunch," "Monday dorm stay," "Monday private room stay," "Monday workshop A," "Monday dinner."  The creator will specify which attributes will be selected by each possible field combination.  For example, for a combination of "Weekend only" selected for the "Attendence Length" independent field, and "Private dorm" selected for the "Housing" dependent field, the creator will specify that the "Friday private room stay" and "Saturday private room stay" attributes should be selected.  The creator will specify this for every possible combination.

The entire set of selected attributes gets recorded along with the event signup; this is to avoid confusion in case the event creator later edits the default set of selected attributes.

Administrators will later have the opportunity to override almost anything about an individual stored signup - including options, attributes, and pricing.  This will make for an extremely flexible system - for example, if someone signs up for the whole week but we later find out they can't make it as early Monday lunch, an admin can uncheck the Monday lunch box in their signup, so that the chef can get an up-to-date and thorough list of head counts for meals.  It will allow for extremely easy handling of special requests of any kind, pricing, meal or housing options, or otherwise.

I've attached a draft ERD.  I am still familiarizing myself with CiviCRM's architecure, so I welcome suggestions.  I included the id fields from civicrm_event and civicrm_contact as placeholders so I could show the relationships between them and the new tables.  The BLOB values are meant to store serialized PHP arrays containing the complicated n-dimensional pricing information.  This seems to make more sense than creating a table with enough foreign key fields to handle some finite number of dependencies.  For the pricing field in event_adv_field_options, it would be in the form $price['independent field 1']['i.f. 2']['i.f. 3'] = $xx .  For the components field, it would be $defaultComponents['i.f. 1']['i.f. 2']['i.f. 3'] = array([list of component id's]) .  Note also that the tables with signup in their names store information about individual contacts signing up for events.

Thanks for your time.[/list]

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional pricing options and price set templates?
November 11, 2010, 03:08:48 pm
Jake - Your use case is quite interesting and I suspect there are other current and prospective CiviEvent users who could benefit from a solution. I've spent some time trying to wrap my brain around your implementation proposal and ERD and have some initial thoughts:

1. Wondering if there's a way to extend the existing Price Set functionality to meet this use case (theoretically requiring quite a bit less effort). Possible direction for this:
- Create a filter attribute which can be defined at the Event or possibly Price Set level. For your example, filter values would be 'Full Week', 'Thursday-Sunday', 'Weekend Only'.
- When filter values are defined, admin can select a filter for any Price Set field. For your example, admin would create 3 Price Set fields for the Workshop Fees - with the corresponding prices for each Track. Same for the Housing and Meal selections. 
- At registration, user / staff selects a filter value (or it's passed in via GET param) first. Price set fields are included in the registration form based on the filter (price set fields which don't have filter value would always be included).

With this approach, the rest of the registration code would not need to change. Line items would be recorded with the appropriate data based on the submitted price set field selections etc.

RE your concern about creating a price set for each event - this could potentially be smoothed out in the UI (and I don't think the overall configuration effort would be substantively different between this approach and the one you described).

2. If the above doesn't strike a chord for you ...
- The ERD doesn't seem to fit the current CiviEvent data model. We use civicrm_participant to store event registrations, so you might consider linking to / extending that object with the additional signup data you need to record. Also check out civicrm_line_item which is the current data store for price set sign selections.
- Is there a way to simplify the model a bit, seems really complex :-(
- We've found that using serialized data in the DB can be sub-optimal especially when you're wanting to retrieve some parts of it. YMMV.
- Allowing admins to modify registration options after participant has paid has implications for payment processing / reconciliation. Your client will probably expect that an additional or reversing payment (contribution) record is recorded if the participant now owes more or less $ than what they've already paid. Note that we haven't taken this on yet (and hence don't allow changes to paid event registrations - admin has to delete and re-enter).
Protect your investment in CiviCRM by  becoming a Member!

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 11, 2010, 03:20:06 pm
Ah.  Thanks for the response.  Here's another piece of the puzzle: We give people the option of paying either a $75 deposit or the full fee upon registration.  In the case of someone paying a deposit only, changing options later wouldn't be an issue.  Still doesn't take care of the full fee people.  And we really do need to record changes that people make to their registration and account for our refunding them or getting more money from them.  Sometimes people show up to an event wanting to switch something and we want to document that in the system, including any refund or additional payment involved.

A question about your first proposal: it seems really nice and elegant; is there a way to address the "attribute" (just realize it's called "component" in the ERD) requirement in that scenario?

I also think it's important to store pricing and attribute information as they appeared at signup with each participant's record, plus have a way to override for each participant without destroying the original information - hence, in the ERD, the total fee and attributes plus override values stored in ...adv_signup, plus the breakdown of the total registration cost, plus overrides, in ...signup_opts.  Your first solution of filtering price set fields would eliminate the need to store serialized arrays since we'd be dealing with single lines instead of n-dimensional arrays.

Maybe a combination of the two approaches would work?  We could use filtered price sets but store the attribute and price/override information in new tables.
« Last Edit: November 11, 2010, 03:34:14 pm by jakecivi »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional pricing options and price set templates?
November 11, 2010, 04:08:13 pm
Partial payments (e.g. deposit + remaining later) is a kind of a separate issue / missing feature from CiviEvent, CiviMember etc. which some folks are now trying to design and implement a solution for. Check out this wki page - http://wiki.civicrm.org/confluence/display/CRM/Finance+and+Accounting- and the CiviAccounts thread on this forum - http://forum.civicrm.org/index.php/topic,12264.0.html

Not sure how to handle the "attributes" (which I see as basically a more granular record of each registrant's selected options - recorded for each line item). Adds a lot of complexity on configuration, registration processing, registration editing and reporting output - so might be worth considering holding off / implementing manual process for it ???

With regard to keeping track of registration changes - one approach which might make sense for both your case and in general might be to model editing participant records as a Copy/Insert + Cancel operation. So if admin goes to modify any aspect of an existing registration which has price impact - and the registration is already paid - the postProcess operation would be to cancel the existing participant and contribution records and insert a new copy of both with the updated registration options / pricing / line items. The cancelled records are easily viewable in the current UI and provide a log of prior states. (Not sure how the override mechanism in your model would handle multiple state changes - but this method would handle that.)
Protect your investment in CiviCRM by  becoming a Member!

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 11, 2010, 10:41:18 pm
Partial payments - interesting.  Added a section to that wiki page about the possibility of more rigid deposit-or-full (nowhere in between) payment choices upon signup.

Attributes:  Definitely needs to be in the CRM - they've specifically requested this so they can do things like have the chef easily pull up the meal counts and have the housing coordinator pull up room needs.  They want to be able to edit individual attributes per registrant at any time, working from a default set based on the line item choices, in order to handle and record special cases without being snagged by the software's limitations.  This sort of flexibility is important to the place, so, to me, it's worth building in attributes as well as all the necessary reporting output.

A question about the Copy/Insert + Cancel operation: If the registration is already paid, what would happen to the record of that payment, and how would it integrate with the Finance and Accounting changes and the deposit-only case?

Summary of best changes thus far: Price sets with filtered fields.  Recording and handling of attributes as described.  Ability to change initial signup options, implemented as Copy/Insert + Cancel, and override the accompanying attributes selected.  I'm not entirely convinced of this last one; does the method seem like a hack that would confuse users by conflating registration changes and real cancellations?
« Last Edit: November 11, 2010, 10:43:13 pm by jakecivi »

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 12, 2010, 10:52:20 am
Would it make sense, while Finance and Accounting is still in development, to write a Drupal module to route all CiviCRM payments through Ubercart as Ubercart orders, and then record the payment information back in CiviCRM once it's paid?  I'd still have to give some thought to recording the deposit-only case as a completed registration in Civi that still has an outstanding balance in Ubercart, but it would gain Ubercart's ability to track partial payments and invoices for relatively little coding.
« Last Edit: November 12, 2010, 10:57:53 am by jakecivi »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional pricing options and price set templates?
November 12, 2010, 11:08:45 am
Jake - You might want to do a blog post on CiviCRM.org with a distillation of requirements and your thoughts so far in order to hopefully get input from a larger set of folks. I do think the Cancel / Insert mechanism is a bit of a hack - could be improved a bit by creating another status - "Replaced" or ?? for less confusion - but then code which "counts" and "averages" completed contributions might need to be updated.

If your timeframe is short, integrating w/ UberCart might make sense. There are some integration module(s) around which might help.
Protect your investment in CiviCRM by  becoming a Member!

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 12, 2010, 12:07:14 pm
Okay.  It's possibly better to have them do those things manually until Finance and Accouting is ready in order to avoid migrating data from Ubercart to Civi later, but I still kinda want to just go for it.  In either case, I'll still need a way for the chosen payment system to ask only for the deposit.

Looks like the existing uc_civicrm module only provides syncing one-way, from Ubercart purchases, to CiviCRM contact information.  Doesn't look like it touches CiviEvent at all.

Will make a blog post.  Thanks.

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 17, 2010, 11:32:49 am
Here's the blog post:
http://civicrm.org/blogs/jakecivi/advanced-price-sets-event-attributes-deposit-payment-and-paymentinvoice-tracking

Thanks again.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional pricing options and price set templates?
November 20, 2010, 01:58:07 pm
Jake - You might want to add a bit more context to the blog post. Describe the type(s) of events your wanting to support and the problems you're trying to solve up front so that folks might "recognize" similar things they need to do. Then tweet the blog post (we'll retweet). Might drum up some more eyeballs and participation.
Protect your investment in CiviCRM by  becoming a Member!

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 22, 2010, 09:33:40 am
Okay.  I included some of the introduction from here and wrote a bit more description to introduce the blog post...

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional pricing options and price set templates?
November 22, 2010, 10:29:45 am
Cool - I had some thoughts over the weekend about implementation and added them as comments on the blog.
Protect your investment in CiviCRM by  becoming a Member!

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Conditional pricing options and price set templates?
November 30, 2010, 06:39:53 pm
Haven't heard much in a few days, so I'm thinking it's okay to start work on at least the filtered fields part since it seems like a pretty solid idea.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional pricing options and price set templates?
December 01, 2010, 11:15:12 am
Jake - Kudos for your efforts to explain the requirements and try and get collaboration etc! Hopefully the process was useful for you / your client. That said, based on the lack of input from the community (and the complexity of what you're trying to do) we think that the functionality you need should be implemented as a Drupal module which extends CiviCRM / CiviEvent. So two options IMO ...

1. Continue down the road your on extending CiviEvent by creating a custom Drupal module which uses hooks and auxiliary tables to inject the additional features. The core team is quite focused on maximizing this kind of extensibility - so if you hit some spots where a hook is not available we would work with you on that. If you're not yet familiar w/ extending Civi via hooks - check the Extending CiviCRM section of the online book: http://en.flossmanuals.net/CiviCRM/DevelopIntro

2. if you find that you're making too many compromises / hacks to get where you need to go extending CiviEvent, then it might make sense to just build out all the functionality using Drupal CCK, Form API etc. You could still integrate this with CiviCRM if the client needs other CRM features. You could inject Civi activity records, inject and update contact records, add custom reports and searches, and a tab in the contact summary to view event registrations ...
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Conditional pricing options and price set templates?

This forum was archived on 2017-11-26.