You are here

function commerce_webform_get_webform_submission_from_lineitem in Commerce Webform 7

Same name and namespace in other branches
  1. 8 commerce_webform.module \commerce_webform_get_webform_submission_from_lineitem()
  2. 7.2 commerce_webform.module \commerce_webform_get_webform_submission_from_lineitem()

Given a commerce line item return the linked webform submission.

Parameters

commerce_line_item|int $line_item: The line item or line item id

Return value

webform_submission|FALSE Either the linked webform submission or FALSE if there isn't one.

1 call to commerce_webform_get_webform_submission_from_lineitem()
commerce_webform_mark_paid in ./commerce_webform.rules.inc
Rules action. Mark commerce webform submission as paid.

File

./commerce_webform.module, line 383
Commerce Webform module file

Code

function commerce_webform_get_webform_submission_from_lineitem($line_item) {
  if (is_numeric($line_item)) {
    $line_item = commerce_line_item_load($line_item);
  }
  if (!isset($line_item->type) || $line_item->type != 'commerce_webform') {

    // Not linked to a commerce webform.
    return FALSE;
  }
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $sid = $line_item_wrapper->commerce_webform_sid
    ->value();
  if ($sid > 0) {
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    $nid = $line_item_wrapper->commerce_webform_nid
      ->value();
    return webform_get_submission($nid, $sid);
  }
  return FALSE;
}