If you create a paid event webform with an email component (e.g., creating an email field in the webform to use as an address to send a confirmation) that email is sent immediately upon adding the event to the cart. Wouldn't it be better to delay that email and wrap it in with until the conditional action that's fired to update the order status to paid? I dug around in webform but can't figure out where those emails are triggered and, even if I could find it, I'm not sure I would know how to delay the process or add it to the action. So, I figured a feature request was my best bet.

Thanks!

Comments

Saoirse1916’s picture

I've got a workaround solution to this which involves hacking webform.module, so if there comes a patch for UC Event Registration, I'm definitely in for that.

If anyone wants this feature in the meantime, here's the workaround:
At line 2202 of webform.module disable the default auto email submission for paidevent forms -- change this:

<?php
  // Check if this form is sending an email.
  if (!$is_draft && !$form_state['values']['details']['finished']) {
	$submission = webform_get_submission($node->nid, $sid, TRUE);
    webform_submission_send_mail($node, $submission);
	}
  >
?>

To this:

<?php
  // Check if this form is sending an email.
  if (!$is_draft && !$form_state['values']['details']['finished']) {
	//HACK- modified to check for paidevent, this prevents the form from auto-submitting before payment is confirmed
	if($form['#node']->type != 'paidevent') { 
	  $submission = webform_get_submission($node->nid, $sid, TRUE);
      webform_submission_send_mail($node, $submission);
	}
  >
?>

Then, in uc_event_registration.ca.inc you'll need to add in the proper actions to the conditional event. Change this (line 48):

<?php
    '#actions' => array(
      array(
        '#name' => 'uc_event_registration_mark_paid',
        '#title' => t('Mark Webform as Paid after Checkout'),
        '#argument_map' => array(
          'order' => 'order', 
        ),
      ),
?>

To this:

<?php
'#actions' => array(
      array(
        '#name' => 'uc_event_registration_mark_paid',
        '#title' => t('Mark Webform as Paid after Checkout'),
        '#argument_map' => array(
          'order' => 'order', 
        ),
	  ),
	  array(
        '#name' => 'uc_event_registration_send_confirmation',
        '#title' => t('Send confirmation email'),
        '#argument_map' => array(
          'order' => 'order', 
        ),
      ),
?>

Now you need to modify the hook_ca_action() function to include the new action that you just created. So in the same file change this:

<?php
function uc_event_registration_ca_action() {
  $order_arg = array(
    '#entity' => 'uc_order',
    '#title' => t('Order'),
  );

  $actions['uc_event_registration_mark_paid'] = array(
    '#title' => t('Mark Webform as Paid after Checkout'),
    '#category' => t('Event Registration'),
    '#callback' => 'uc_event_registration_mark_paid',
    '#arguments' => array(
      'order' => $order_arg,
    ),
  );
return $actions;
}
?>

To this:

<?php
function uc_event_registration_ca_action() {
  $order_arg = array(
    '#entity' => 'uc_order',
    '#title' => t('Order'),
  );

  $actions['uc_event_registration_mark_paid'] = array(
    '#title' => t('Mark Webform as Paid after Checkout'),
    '#category' => t('Event Registration'),
    '#callback' => 'uc_event_registration_mark_paid',
    '#arguments' => array(
      'order' => $order_arg,
    ),
  );
  
  $actions['uc_event_registration_send_confirmation'] = array(
    '#title' => t('Send confirmation email'),
    '#category' => t('Event Registration'),
    '#callback' => 'uc_event_registration_send_confirmation',
    '#arguments' => array(
      'order' => $order_arg,
    ),
  );
  return $actions;
}
?>

The last change is at the very end of the file, create the function to actually do the work:

<?php
// Send the confirmation email (interrupted in standard webform for membership products
function uc_event_registration_send_confirmation(&$order, $settings){
  // Include the webform submissions file which contains all email functions
  include_once drupal_get_path('module', 'webform') .'/includes/webform.submissions.inc'; 
  foreach ($order->products as $theproduct) {
	// load the node object which is used by the webform submission functions
	$node = node_load(array("nid" => $theproduct->nid));
	$sid = $theproduct->data['uc_event_registration']['sid'];
    $submission = webform_get_submission($theproduct->nid, $sid, TRUE);
	// now send the email
    webform_submission_send_mail($node, $submission);
  }
}
?>

Now, in /admin/store/ca you'll need to apply the new action to the existing predicate. Click edit next to the Mark Event Registrations as paid predicate, click the actions tab, find your new action in the Available actions drop down list, then click Add Action. That should do it.

Again, if there's a less hacky way to do this, I'm certainly game but this was fairly critical for my project as the client was using these email confirmations as temporary tickets which granted customers access to events. Sending them out before payment was processed would be a big problem in this case.

AndyF’s picture

What I did was just to not use the webform mailer if I didn't want an 'early' email, and instead used ca to send the email on checkout completion. Would that pose any problems in your situation? (The only example I can think of is if you needed to use webform component values in your email, or if you've opened up webform to the client but are keeping ca closed.)

Saoirse1916’s picture

@AndyF: I initially had it set up that way but my client definitely wanted all the webform fields in the email, so the customer now gets two emails, one from webform and one from ubercart. That's not ideal but not really a big concern as that happens a lot on e-commerce sites.

AndyF’s picture

I'm with you. So the appropriate 'nice' solution to your problem would be to expose the webform fields as tokens in ca? (But this wouldn't please people who wanted to let their clients create arbitrary email messages via webform and have it send only on payment.)

Saoirse1916’s picture

Yeah, exactly -- I spent a bit of time looking down that route but I like how customizable webform's email confirmations are. In my case I'm using this module not just for event registrations but for memberships and education programs as well. To the module the type doesn't matter of course but those are all distinct departments at the client and they want control over what the confirmations say. As a result, I couldn't rely on a single email coming from ca, though adding webform token support would probably work for a lot of people.

AndyF’s picture

Assigned: Unassigned » AndyF

Gotcha, it would be a nice feature. I think we could do it by storing the nid and eid of emails that need sending later, and modify #node on the webform load to remove those emails. Then just use a ca action to send the mails on checkout completion or whatever.

Saoirse1916’s picture

Makes sense, though I didn't know you could modify #node to prevent the auto-submission -- would that be through hook_form_alter or something else?

AndyF’s picture

Version: 6.x-1.3 » 6.x-1.x-dev
Status: Active » Fixed

I've added the feature to -dev: please test. If you edit a paidevent email you should see a new setting for sending either on webform submission or completing checkout. The email sending's done using your action, and by default it's done at the same time as the webform submission's marked as paid.

Note that currently if you have a paidevent configured with 'late' emails, and you then decide to reconfigure them to send on webform submission, then any customers who have already submitted the form for that product but who haven't completed checkout will never get those emails.

@Saoirse1916 Yeah, through form_alter as webform does the sending from its submit handler, which in turn pulls the node from $form['#node']. Thanks for the code!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

K.MacKenzie’s picture

Status: Closed (fixed) » Active

First off, thanks for this awesome module and very useful improvement to the dev version, really saved me a lot of time here.

Looking for this feature myself I stumbled upon this thread. After switching from the 1.3 to 1.x-dev version and trying out this new functionality it appeared to not work.

After re-reading this thread I noticed that you said "The email sending's done using your action".

I realized that the function uc_event_registration_send_webform_emails in my case was never being fired, because I had no conditional action to fire it. After digging throught he code I realize I just had to create the CA to fire it in ubercart... no problem.

A very nice and probably easy improvement would be to automatically create the "fire late emails" CA upon installation just like the "mark webform as paid" CA. Or at the very least put a note under the option on the emails form under the "on completed checkout" select to remind the user that the CA also has to be created in order for it to work.

Thanks again!

AndyF’s picture

@Vandrico Sorry for the delay, and yeah it looks like you're absolutely right! I'm very busy at the mo, but will see if I can't slip the fix in over the weekend as it is so small.

Thanks for reporting it.

AndyF’s picture

Status: Active » Fixed

Sorry, very long delay there! The predicate's now in dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.