You are here

function commerce_recurring_rules_action_info in Commerce Recurring Framework 7.2

Same name and namespace in other branches
  1. 7 commerce_recurring.rules.inc \commerce_recurring_rules_action_info()

Implements hook_rules_action_info().

File

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

Code

function commerce_recurring_rules_action_info() {
  $actions = array();
  $actions['commerce_recurring_set_price'] = array(
    'label' => t('Replace listing price by the initial price for recurring'),
    'parameter' => array(
      'commerce_line_item' => array(
        'type' => 'commerce_line_item',
        'label' => t('Line item'),
      ),
      'listing_price' => array(
        'type' => 'commerce_price',
        'label' => t('Price used for listings'),
      ),
      'initial_price' => array(
        'type' => 'commerce_price',
        'label' => t('Price used for initial recurring'),
      ),
      'recurring_price' => array(
        'type' => 'commerce_price',
        'label' => t('Price used for consequent recurrings'),
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_set_price',
    ),
  );
  $actions['commerce_recurring_get_recurring_line_items'] = array(
    'label' => t('Get all the line items containing recurring products from an order'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order'),
      ),
    ),
    'provides' => array(
      'commerce_line_items' => array(
        'label' => t('Line items with recurring products'),
        'type' => 'list<commerce_line_item>',
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_get_recurring_line_items',
    ),
  );
  $actions['commerce_recurring_get_recurring_on_order'] = array(
    'label' => t('Get all the recurring entities on an order'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order'),
      ),
    ),
    'provides' => array(
      'commerce_recurring_entities' => array(
        'label' => t('Commerce recurring entities'),
        'type' => 'list<commerce_recurring>',
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_get_recurring_on_order',
    ),
  );

  // Provide a default way to copy customer profiles to the new order.
  $profiles = array();
  $profile_fields = commerce_info_fields('commerce_customer_profile_reference', 'commerce_order');
  foreach ($profile_fields as $name => $field) {

    // @TODO: The recurring order might be from a different order bundle.
    if ($instance = field_info_instance('commerce_order', $name, 'commerce_order')) {
      $profiles[$name] = array(
        'label' => $instance['label'],
        'type' => $field['type'],
      );
    }
  }
  $actions['commerce_recurring_get_due_items'] = array(
    'label' => t('Get the recurring entities about to due'),
    'parameter' => array(
      'number_items' => array(
        'type' => 'decimal',
        'label' => t('Number of items'),
        'description' => t('Restrict the number of items to retrieve'),
        'default value' => 0,
      ),
      'timestamp' => array(
        'type' => 'date',
        'label' => t('Due date'),
      ),
    ),
    'provides' => array(
      'commerce_recurring_entities' => array(
        'label' => t('Commerce recurring entities'),
        'type' => 'list<commerce_recurring>',
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_get_due_items',
    ),
  );
  $actions['commerce_recurring_provide_order_properties'] = array(
    'label' => t('Provide properties to generate the order from the recurring entity'),
    'description' => t('Add properties to the order generation form. Mainly for customer profile information'),
    'parameter' => array(
      'commerce_recurring' => array(
        'type' => 'commerce_recurring',
        'label' => t('Commerce recurring'),
      ),
    ),
    'provides' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Commerce Order'),
      ),
    ) + $profiles,
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_provide_order_properties',
    ),
  );
  $actions['commerce_recurring_generate_order_from_recurring'] = array(
    'label' => t('Generate the order associated to the recurring entity'),
    'description' => t('Use the order relationship from the recurring entity to generate the associated order'),
    'parameter' => array(
      'commerce_recurring' => array(
        'type' => 'commerce_recurring',
        'label' => t('Commerce recurring'),
      ),
      'timestamp' => array(
        'type' => 'date',
        'label' => t('Due date'),
      ),
    ) + $profiles,
    'provides' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Commerce Order'),
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_generate_order_from_recurring',
    ),
  );
  $actions['commerce_recurring_iterate_recurring_from_order'] = array(
    'label' => t('Update a recurring entity from a completed order'),
    'description' => t('Iterate through all recurring entities on the order and update'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order'),
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_iterate_recurring_from_order',
    ),
  );

  // @TODO Break the commerce product parameter in components for allowing to
  // set the initial dates, prices more granular.
  $actions['commerce_recurring_generate_recurring_product'] = array(
    'label' => t('Create / Update a recurring entity from product data'),
    'description' => t('Use the product fields information for creating / updating the recurring entity.'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order'),
      ),
      'commerce_line_item' => array(
        'type' => 'commerce_line_item',
        'label' => t('Commerce line item'),
      ),
      'fixed_price' => array(
        'type' => 'commerce_price',
        'label' => t('Fixed price for the recurring entity'),
      ),
      'quantity' => array(
        'type' => 'decimal',
        'label' => t('Quantity'),
      ),
    ),
    'provides' => array(
      'new_commerce_recurring' => array(
        'type' => 'commerce_recurring',
        'label' => t('Generated commerce_recurring entity'),
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_generate_recurring_product',
    ),
  );
  $actions['commerce_recurring_stop_recurring'] = array(
    'label' => t('Deactivate the recurring entity'),
    'description' => t('Cancel the recurring entity. You can cancel from any entity type, most common are cancelling the recurring entity from the order or from the same recurring entity.'),
    'parameter' => array(
      'data' => array(
        'type' => 'entity',
        'label' => t('Entity'),
        'description' => t('Specifies the entity to disable the recurring from.'),
        'restriction' => 'selector',
        'wrapped' => TRUE,
      ),
    ),
    'group' => t('Commerce recurring'),
    'callbacks' => array(
      'execute' => 'commerce_recurring_rules_stop_recurring',
    ),
  );
  return $actions;
}