I am curious if there is a way to create a rule that will email the current user a unique registration code.

Thanks in advance for any help!

Comments

znerol’s picture

I'm not sure if I really got your idea. Could you please elaborate on what you really want to achieve? Perhaps a step by step description of what the user does and how the system should react.

mgladding’s picture

Just to clarify:

I am creating a site where a user pays for a registration. When the order is complete I would like the site to send the user a code via email that a limited number of other users can use to register on the site and be granted a role.

I've got the role granting aspect dialed, I just need to away to get the registration code to the original user once their order is complete.

Thanks!

znerol’s picture

I think you have to code a custom-module for that. You could do that like this: hook into your e-commerce module and generate a new registration key as soon as an order is paid. Then send a mail to the customer.

In the case of drupal-commerce that would probably look like this (disclaimer: I never did that, the code is incomplete and untested):

<?php
/**
 * Implements hook_commerce_payment_order_paid_in_full().
 */
function myregcodeintegrationmodule_commerce_payment_order_paid_in_full($transaction) {
  // regcode_generate($length, $output, $case);
  $regcode = regcode_generate(8, 'alpha', false);
  $code = (object) array(
    'code' => $regcode,
  );
  // regcode_save($code, $terms = array(), $action = REGCODE_MODE_REPLACE);
  regcode_save($code);

  $mailaddress = somehow_figure_out_email_address_via_transaction($transaction);
  drupal_mail(..., $mailadress, ..., $regcode, ...);
}
?>
mgladding’s picture

Thanks for the custom module idea, but alas, I am but a lowly designer. :(

I was thinking of using the Commerce Product Key module to "sell" a registration code. Then I would provide the same codes in the Registration Codes module and match up the codes with the role that can be assigned.

Does that make sense?

Anyway, if I get this working, I will provide an update in case anyone else needs to do the same thing.

aidanlis’s picture

Status: Active » Postponed
cjalden’s picture

+1 for this feature request (and thanks for the code).

tr’s picture

Version: 7.x-1.0-beta2 » 8.x-1.x-dev
Issue summary: View changes

Actually, let's use #1507710: Define a Rules Action for creating Registration Codes as the issue, since that is specifically about creating the missing feature of a RulesAction to generate a registration code.

tr’s picture

Status: Postponed » Closed (duplicate)