You are here

function commerce_registration_mark_paid in Commerce Registration 7

Action callback.

Marks all registrations on a particular order as paid.

@todo Custom status definitions.

Parameters

$order: The Commerce Order object to mark all attached registrations as paid.

Related topics

1 string reference to 'commerce_registration_mark_paid'
commerce_registration_rules_action_info in ./commerce_registration.rules.inc
Implements hook_rules_action_info().

File

./commerce_registration.rules.inc, line 377
Commerce Registration rules file.

Code

function commerce_registration_mark_paid($order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
    $type = $line_item_wrapper->commerce_product->type
      ->value();
    $id = $line_item_wrapper->commerce_product->product_id
      ->value();
    $can_register = registration_entity_registration_status(array(
      'id' => $id,
      'type' => 'commerce_product',
      'bundle' => $type,
    ));
    if ($can_register == 1) {
      $product = $line_item_wrapper->commerce_product;
      $quantity = (int) $line_item_wrapper->quantity
        ->value();
      for ($i = 0; $i < $quantity; $i++) {
        $entity = $order->data['register_entities']['prod-' . $product->sku
          ->value()][$i];

        // we set status to confirm for PAID and save the entity
        $entity->status = 'confirm';
        entity_save('registration', $entity);
      }
    }
  }
}