You are here

function commerce_webform_mark_paid in Commerce Webform 7.2

Same name and namespace in other branches
  1. 8 commerce_webform.rules.inc \commerce_webform_mark_paid()
  2. 7 commerce_webform.rules.inc \commerce_webform_mark_paid()

Rules action. Mark commerce webform submission as paid.

File

./commerce_webform.rules.inc, line 311
Rules extras supplied by the commerce webform module.

Code

function commerce_webform_mark_paid($order) {
  module_load_include('inc', 'webform', 'includes/webform.submissions');
  $loaded_order = commerce_order_load($order->order_id);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $loaded_order);
  $line_items = $order_wrapper->commerce_line_items
    ->value();

  // Update all submissions as paid.
  foreach ($line_items as $line_item) {
    if ($webform_submission = commerce_webform_get_webform_submission_from_lineitem($line_item)) {
      $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
      $product = $line_item_wrapper->commerce_product
        ->value();
      commerce_webform_update_webform_submission_productfield($webform_submission, $order->order_id, $line_item->line_item_id, $product->product_id, $line_item_wrapper->quantity
        ->value(), TRUE);
    }
  }

  // Send any emails.
  _commerce_webform_send_order_confirmation_emails($order);
}