I have a semi-unique need, and a packaged solution I thought the authors might want to handle.
I have events that are both paid, and free. If I've understood how this module works, it just doesn't quite cut it. There's a default registration state option, which in my case needs to be set to completed for anonymous users' free registrations. But there's a separate workflow for users purchasing paid registrations. They need to pay before we can complete it. Right now, I didn't find a way to automatically change payment required events (defined by a price greater than 0 and registrations enabled) to mark them as pending. Exposing the form item state for them to set it as pending themselves is not going to work. I developed the following code that makes it work instead:
Custom.module
This file is used primarly as a routing file to custom/registration/registration.module.inc where logic stored.
/**
* Modifies the submit actions of the commerce form registration
* to change the registration's default state to pending if payment is required
* @see registration_commerce_form_registration_form_alter
*/
function custom_form_registration_form_alter(&$form, &$form_state){
module_load_include('module.inc', 'custom', 'registration/registration');
_custom_registration_form_registration_form_alter($form, $form_state);
}
/**
* Modifies the registration state for payment required registrations to pending
*/
function custom_form_registration_form_alter_validate(&$form, &$form_state){
module_load_include('module.inc', 'custom', 'registration/registration');
_custom_registration_form_registration_form_alter_validate($form, $form_state);
}
/**
* Provides a payment required message for pending registrations
*/
function custom_form_registration_form_alter_submit(&$form, &$form_state){
module_load_include('module.inc', 'custom', 'registration/registration');
_custom_registration_form_registration_form_alter_submit($form, $form_state);
}
registration.module.inc
/**
* Modifies the submit actions of the commerce form registration
* to change the registration's default state to pending if payment is required
* @see registration_commerce_form_registration_form_alter
*/
function _custom_registration_form_registration_form_alter(&$form, &$form_state){
$reg_type = registration_type_load($form['#bundle']);
$reg_settings = $reg_type->registration_commerce_settings;
if ($reg_settings['enable']) {
// Add our custom handlers
$form['#validate'][] = 'custom_form_registration_form_alter_validate';
$form['#submit'][] = 'custom_form_registration_form_alter_submit';
}
}
/**
* Basic validation hook for registrations
* This will change the state of the registration to pending if payment is required
*/
function _custom_registration_form_registration_form_alter_validate(&$form, &$form_state){
$reg_type = registration_type_load($form['#bundle']);
$reg_settings = $reg_type->registration_commerce_settings;
if ($reg_settings['enable']) {
// Pull the registration specific details to check the price
// This is a bit of custom. You could check $reg_settings['default_price']['amount'] instead
$entity = $form['#entity'];
$entity_settings = registration_entity_settings($entity->entity_type, $entity->entity_id);
// Since registration is enabled, if a price exists, force the status back to pending
if( !empty($entity_settings['settings']['price']['amount']) ){
$form_state['values']['state'] = 'pending';
}
}
}
/**
* Provides a payment required message for pending registrations
*/
function _custom_registration_form_registration_form_alter_submit(&$form, &$form_state){
if( $form_state['values']['state'] == 'pending' ){
drupal_set_message( t('Please submit payment now to complete your pending registration.') );
}
}
Comments
Comment #1
lance.gliser CreditAttribution: lance.gliser commentedComment #2
gcbYes, we've also done some default overriding to get different registration types on the same system working. This is probably a feature request for Registration, though, not Registration Commerce. It would allow you to set the default state by type instead of system-wide. It just belongs in Registration. I'm going to close this out: please submit as a feature request for the Registration module, or add to any existing feature request that matches.