Answers.Body: <p>My solution to this isn't elegant, but it gets the job done. I simply added a little code with hook_webform_submission_insert that takes the original webform submission data and resubmits the essential details to a second webform as many times as the user bought tickets. That second webform serves as the official list of tickets sold and sends an email for each submission to the buyer (so the buyer gets three emails with different ticket numbers if they bought three tickets). This works fine as long as your ticket numbers are sequential and increasing. You can add more tickets in a higher range by adding higher tickets numbers by changing the next submission value for the webform, but you can't add tickets with a lower number.</p>
  <pre><code>function wildsight_raffle_tickets_webform_submission_insert($node, $submission) {
    if ($submission-&gt;nid == 210) {
       
    $node_out = node_load('211');
    global $user;
  
    $data = array(
      'first_name' =&gt; $submission-&gt;data[3][0],
      'last_name' =&gt; $submission-&gt;data[4][0],
      'email' =&gt; $submission-&gt;data[14][0],
    );
    
    module_load_include('inc', 'webform', 'webform.module');
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    
    $number_of_tickets = $submission-&gt;data[24][0];
    
    // This methods will arrange $data in the right way
    $data_out = _webform_client_form_submit_flatten($node_out, $data);
    $data_out = webform_submission_data($node_out, $data_out);
    
    while ($number_of_tickets &gt; 0) {
  
    $submission_out = (object) array(
      'nid' =&gt; '211',
      'uid' =&gt; $user-&gt;uid,
      'sid' =&gt; NULL,
      'submitted' =&gt; REQUEST_TIME,
      'completed' =&gt; REQUEST_TIME,
      'remote_addr' =&gt; ip_address(),
      'is_draft' =&gt; FALSE,
      'data' =&gt; $data_out,
    );
  
      webform_submission_insert($node_out, $submission_out);
      webform_submission_send_mail($node_out, $submission_out);
      $number_of_tickets -= 1;
    }
  }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-25T02:12:26.067Z
Answers.Text: was this a D8/9 solution or D7? hoping the former :)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-10T18:26:39.407Z
Answers.LastActivityDate: 2021-04-10T18:26:39.407Z
Answers.UserDisplayName: Lars SG
Body: <p>We would like to sell numbered tickets for a raffle. According to the regulations we need to meet, we have to sell tickets that have unique numbers from a predetermined set (e.g. we have tickets numbered 1-500). How can we sell these tickets with email receipts that go to the buyer, including the ticket numbers?</p>
  <p>Ideally, it would be possible to sell more than one ticket in a transaction and send a receipt to a buyer saying that they bought tickets x, y and z or failing that three emails listing the ticket numbers.</p>
  <p>We've used a Drupal webform with the submission id as the ticket number in the past, but this only allows us to sell one ticket per transaction. It seems like we might be able use Civirules to send receipts with ticket numbers, but I'm not seeing a way to do that without custom code.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-05T15:57:15.827Z
Comments.Text: I can think of several approaches, but none that would allow multiple tickets per transaction without writing custom code.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-05T20:41:30.560Z
Comments.Text: Thanks Jon. Would there be a better way to sell tickets one by one from a pre-defined set of numbers than using webform submission id (which is a little painful, as it limits us to sequential numbers)?
Comments.UserDisplayName: Lars SG
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-06T20:04:40.247Z
Comments.Text: All the one-by-one approaches would be sequential number approaches.  Custom code-wise, the most "elegant" approach would probably be a "Raffle Ticket" entity, each record could have a contact_id to link it to a person.  A simpler approach would be a Setting called "next ticket #" that would update any time tickets are sold.  I think you're looking at code either way though.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-03-19T16:46:47.017Z
Comments.Text: What about just adding a bit of code that essentially adds the same info to the webform n-1 times on webform submission? That might be simpler than doing an entity. Then buyers would get one email for each ticket number, but that's not a big problem for our use case. Potential pitfalls?
Comments.UserDisplayName: Lars SG
Tags: <webform-civicrm><civirules>
Title: Is there a way to sell numbered tickets, e.g. for a raffle?
ThreadText: # Is there a way to sell numbered tickets, e.g. for a raffle?
  
  (Asked by: username_0 on 2020-11-04)
  
  We would like to sell numbered tickets for a raffle. According to the regulations we need to meet, we have to sell tickets that have unique numbers from a predetermined set (e.g. we have tickets numbered 1-500). How can we sell these tickets with email receipts that go to the buyer, including the ticket numbers?
  
  Ideally, it would be possible to sell more than one ticket in a transaction and send a receipt to a buyer saying that they bought tickets x, y and z or failing that three emails listing the ticket numbers.
  
  We've used a Drupal webform with the submission id as the ticket number in the past, but this only allows us to sell one ticket per transaction. It seems like we might be able use Civirules to send receipts with ticket numbers, but I'm not seeing a way to do that without custom code.
  
  **Tags:** webform-civicrm, civirules
  
  > **Comments:**
  > **username_1**: I can think of several approaches, but none that would allow multiple tickets per transaction without writing custom code.  
  > **username_0**: Thanks Jon. Would there be a better way to sell tickets one by one from a pre-defined set of numbers than using webform submission id (which is a little painful, as it limits us to sequential numbers)?  
  > **username_1**: All the one-by-one approaches would be sequential number approaches.  Custom code-wise, the most "elegant" approach would probably be a "Raffle Ticket" entity, each record could have a contact_id to link it to a person.  A simpler approach would be a Setting called "next ticket #" that would update any time tickets are sold.  I think you're looking at code either way though.  
  > **username_0**: What about just adding a bit of code that essentially adds the same info to the webform n-1 times on webform submission? That might be simpler than doing an entity. Then buyers would get one email for each ticket number, but that's not a big problem for our use case. Potential pitfalls?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-04-10. Score: 1
  
  My solution to this isn't elegant, but it gets the job done. I simply added a little code with hook\_webform\_submission\_insert that takes the original webform submission data and resubmits the essential details to a second webform as many times as the user bought tickets. That second webform serves as the official list of tickets sold and sends an email for each submission to the buyer (so the buyer gets three emails with different ticket numbers if they bought three tickets). This works fine as long as your ticket numbers are sequential and increasing. You can add more tickets in a higher range by adding higher tickets numbers by changing the next submission value for the webform, but you can't add tickets with a lower number.
  
  ```
  function wildsight_raffle_tickets_webform_submission_insert($node, $submission) {
    if ($submission->nid == 210) {
       
    $node_out = node_load('211');
    global $user;
  
    $data = array(
      'first_name' => $submission->data[3][0],
      'last_name' => $submission->data[4][0],
      'email' => $submission->data[14][0],
    );
    
    module_load_include('inc', 'webform', 'webform.module');
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    
    $number_of_tickets = $submission->data[24][0];
    
    // This methods will arrange $data in the right way
    $data_out = _webform_client_form_submit_flatten($node_out, $data);
    $data_out = webform_submission_data($node_out, $data_out);
    
    while ($number_of_tickets > 0) {
  
    $submission_out = (object) array(
      'nid' => '211',
      'uid' => $user->uid,
      'sid' => NULL,
      'submitted' => REQUEST_TIME,
      'completed' => REQUEST_TIME,
      'remote_addr' => ip_address(),
      'is_draft' => FALSE,
      'data' => $data_out,
    );
  
      webform_submission_insert($node_out, $submission_out);
      webform_submission_send_mail($node_out, $submission_out);
      $number_of_tickets -= 1;
    }
  }
  }
  
  ```
  
  > **Comments:**
  > **username_2**: was this a D8/9 solution or D7? hoping the former :)  
  
  ---
  
  