Using Price Set Fields in Drupal with CiviCRM Entity

As of CiviCRM Entity 2.0-beta4 there has been a sub module available called CiviCRM Entity Price Set Field. CiviCRM Entity Price Set field provides a Drupal field type for the Event entity type.  In this article I’ll discuss the features of this submodule, how to configure it, and how to customize it.

civicrmentitypriceset-settings

Event Registration on the Event view page

When configured to display on the Event view pages, this field generates a registration form that supports:

  • Registering multiple Participants
  • Uses the event’s price set and all price fields of any type
  • Pay later or credit card transactions utilizing CiviCRM’s payment processing Profiles
  • Default values for the profile fields corresponding to the logged in user’s contact information
  • Customizable Ajax-fied confirmation and thank you panes
  • Utilizes the event’s settings such as “Is paid event?” etc..
  • Test or Live transactions

Field widget for the Event Edit Form

A “simple” field widget is provided by default for this module.  At the time of this writing, only the first price field can be edited via this widget.  Editing all properties and price field values of the price set and multiple fields is the end goal, and possible, although some assembly required. That’s a topic for a future blog article Hint: this field type works with Inline Entity Form widgets.

civicrmentitypriceset-example

Getting Started

CiviCRM Entity and CiviCRM Entity Profile are dependencies for CiviCRM Entity Price Set Field. Go to the Drupal module admin page and enable all three modules.

Once the modules are enabled, you can add an instance of the Price Set Field to the Event Entity Type.

  • Go to the Event Manage Fields form at /admin/structure/civicrm-entity/civicrm_event
  • Scroll to the “Add New Field” section, enter a Label, and select the ‘CiviCRM Entity Price Set’ field type, for this example select the “Simple -- one price field” widget
  • There’s no special field or field instance settings, so just click save until you’re back to the Manage Fields page
  • Now go to the Manage Display Full Content form at /admin/structure/civicrm-entity/civicrm_event/display/full
  • Set the new field to display
  • There is a field formatter setting to optionally submit test transactions
  • Pat yourself on the back, you’re setup to take registrations from the Drupal based Event view pages at /civicrm-event/[id]

Please note that the registration form takes into account the different settings on the CiviCRM Event.  For instance it will only enable CC transactions and render a billing block if the “Paid Event?” checkbox is checked. The form conforms to registration start and end dates, only renders if Online Registration is enabled.  The form checks to see if Max Participants has been reached, even when adding additional participants. Additional participants can only be added if “Allow Multiple Registrations” is enabled.

The registration form is ajaxified, so adding additional participants can be added or removed without a page refresh, and after the user enters their registration and payment information, a confirmation pane is shown, then a thank you pane, via ajax without a page refresh.  The information for these panes is taken from the event confirmation and thank you page text and footer fields. If javascript in the browser is disabled the form degrades seamlessly to non-ajax page refreshes.

The credit card transactions are done via the Contribution API ‘transact’ action.  Full standard accounting is created as if the user registered from the stock event registration page, including line items for each price field for each participant, and ParticipantPayment records.

The form will generate form elements for the profiles that are configured to display on the registration page.  Please note that due to CiviCRM API limitations, you cannot mix fields from different entities on one profile.  If you have participant custom fields, those should be on a separate profile from profiles with contact custom fields. Also note that at least one profile should have a contact email address field.

The registration form will try to use the payment processor that is configured for the event. It’s wired to work with Authorize.net, iATS, Paypal Pro, or Payflow out of the box, but it’s only been tested and used in production with Authorize.net and iATS.  It may need a tweak to work with the Paypal processors, but try it out and let us know. The “dummy” processor is also supported, and this also provides an opportunity to do some interesting customs. You can make that dummy processor “smart” and use it for non-monetary forms of payment.

Below are some screenshots of the registration form in action.  This is a fresh install of CiviCRM with demo content, CiviCRM Entity, and a CiviCRM Entity Price Set field added to the Event entity type.  The tabs seen at the top are field groups added to the “Manage Display” form.

Registration form using the event’s price set and the Your Registration Info profile:

 event-registration-confirmation-in-civicrm-entity

After entering values and clicking Register, the confirmation pane appears:

event-registration-in-civicrm-entity

This module has been made possible by Skvare’s clients who have specific needs.  There will be more features that people will want to fit their needs. Contact Skvare if you need customizations or wish to see improvements in the publicly available feature set.

Developed to support CiviCRM 4.6 LTS and above.

Developers, it’s customizable!

See civicrm_entity_price_set_field.api.php  in the module’s folder for documentation and example hook implementations.

  • Provides hooks for customizing the integration with the CiviCRM payment processor
  • Provides a hook to alter the price field value amounts (for applying custom discounts)
  • Provides a hook to allow custom access handlers for the registration form
  • Provides a hooks to alter the line items or totals for the contribution, post form submission, pre confirmation.
  • Customize the form with hook_form_alter()
  • Confirmation and thank you pages configurable via standard Drupal theme preprocess functions, or use your own theme function to render

In a future article I will discuss in more depth how to customize the registration form, confirmation and thank you panes, as well as discuss how to take advantage of other payment processors or even “custom” payment processors that accept user points or other non-monetary payment.

Share this post