You are here

function commerce_recurring_rules_generate_recurring_product in Commerce Recurring Framework 7.2

Generate the recurring entity using the product information.

1 string reference to 'commerce_recurring_rules_generate_recurring_product'
commerce_recurring_rules_action_info in ./commerce_recurring.rules.inc
Implements hook_rules_action_info().

File

./commerce_recurring.rules.inc, line 457
Rules integration for recurring entities.

Code

function commerce_recurring_rules_generate_recurring_product($order, $line_item, $fixed_price, $quantity) {
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $product_wrapper = $line_item_wrapper->commerce_product;
  $product = $product_wrapper
    ->value();

  // We need to check if there's already an order with that recurring entity.
  if (empty($order->data['recurring_entity'])) {
    $recurring_entity = commerce_recurring_new_from_product($order, $product, $fixed_price, $quantity);
  }
  else {
    $recurring_entity = entity_load_single('commerce_recurring', $order->data['recurring_entity']);
  }
  rules_invoke_event('commerce_recurring_paid_full', $order, $recurring_entity, count($recurring_entity->commerce_recurring_order[LANGUAGE_NONE]));
  return array(
    'new_commerce_recurring' => $recurring_entity,
  );
}