You are here

function commerce_registration_commerce_checkout_complete in Commerce Registration 7.2

Same name and namespace in other branches
  1. 7.3 commerce_registration.module \commerce_registration_commerce_checkout_complete()

Implements hook_commerce_checkout_complete().

File

./commerce_registration.module, line 692
Commerce Registration module code.

Code

function commerce_registration_commerce_checkout_complete($order) {
  if (!isset($order->data['register_entities'])) {
    return;
  }
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
    if (!in_array($line_item_wrapper->type
      ->value(), commerce_product_line_item_types())) {
      continue;
    }
    $id = $line_item_wrapper->commerce_product->product_id
      ->value();
    $line_item_id = $line_item_wrapper->line_item_id
      ->value();
    $product = $line_item_wrapper->commerce_product;
    if (!isset($order->data['register_entities'][$line_item_id . 'prod-' . $product->sku
      ->value()])) {

      // If we have no registration entities for this product in our order's
      // data array, we skip to the next.
      continue;
    }
    $quantity = (int) $line_item_wrapper->quantity
      ->value();
    for ($i = 0; $i < $quantity; $i++) {
      if (!isset($order->data['register_entities'][$line_item_id . 'prod-' . $product->sku
        ->value()][$i])) {

        // If this registration doesn't exist in our data array, skip to the
        // next entry.
        continue;
      }
      $entity = $order->data['register_entities'][$line_item_id . 'prod-' . $product->sku
        ->value()][$i];
      registration_save($entity);
    }
  }
}