You are here

function commerce_recurring_new in Commerce Recurring Framework 7.2

Returns an initialized Commerce Recurring entity.

Initializes all the properties defined plus the two entity reference fields.

  • product_id: Commerce product id, populates commerce_recurring_ref_product.
  • order_ids: Array of Commerce order ids, populates commerce_recurring_order.

See also

commerce_recurring_entity_property_info()

commerce_recurring_configure_recurring_entity_type()

2 calls to commerce_recurring_new()
CommerceRecurringTestCase::createRecurringEntity in tests/commerce_recurring.test
Creates a recurring entity to be used in other tests.
commerce_recurring_new_from_product in ./commerce_recurring.module
Generate a new recurring entity from a product. We set the price to the initial price from the line item if available. The start date for the recurring is the current date unless a set one is specified. Due date is start date + initial date. End date…

File

./commerce_recurring.module, line 327
Commerce recurring module file.

Code

function commerce_recurring_new(array $values = array()) {
  $values += array(
    'id' => NULL,
    'type' => isset($values['type']) ? $values['type'] : 'product',
    'status' => 1,
    'start_date' => '',
    'due_date' => '',
    'end_date' => '',
    'uid' => '',
    'quantity' => 1,
    'data' => array(),
  );

  // Retrieve the properties to get from fields.
  if (isset($values['product_id'])) {
    $values['commerce_recurring_ref_product'] = array(
      LANGUAGE_NONE => array(
        0 => array(
          'target_id' => $values['product_id'],
          'taget_type' => 'commerce_product',
        ),
      ),
    );
    unset($values['product_id']);
  }
  if (isset($values['order_ids']) && is_array($values['order_ids'])) {
    foreach ($values['order_ids'] as $delta => $order_id) {
      $values['commerce_recurring_order'] = array(
        LANGUAGE_NONE => array(
          $delta => array(
            'target_id' => $order_id,
            'taget_type' => 'commerce_order',
          ),
        ),
      );
    }
    unset($values['order_ids']);
  }
  return entity_create('commerce_recurring', $values);
}