You are here

function commerce_pricelist_rules_action_info in Commerce Pricelist 7

Implements hook_rules_action_info().

File

./commerce_pricelist.rules.inc, line 15
Rules integration for line items.

Code

function commerce_pricelist_rules_action_info() {
  $actions = array();
  $actions['commerce_pricelist_rate_apply'] = array(
    'label' => t('Apply a pricelist rate to a line item'),
    'parameter' => array(
      'commerce_line_item' => array(
        'type' => 'commerce_line_item',
        'label' => t('Line item'),
        'getter callback' => 'entity_property_verbatim_get',
      ),
      'user' => array(
        'type' => 'user',
        'label' => t('User'),
      ),
    ),
    'provides' => array(
      'commerce_pricelist_price_array' => array(
        'type' => 'list<commerce_price>',
        'label' => t('Commerce Pricelist price'),
      ),
    ),
    'group' => t('Commerce pricelist'),
    'callbacks' => array(
      'execute' => 'commerce_pricelist_rate_rules_apply',
    ),
  );
  $action_types['commerce_pricelist_unit_price_amount'] = array(
    'label' => t('Set the price to a specific amount and apply inclusive taxes'),
    'amount description' => t('Specify the numeric amount to set the price component to.'),
  );

  // Define the action using a common set of parameters.
  foreach ($action_types as $key => $value) {
    $actions[$key] = array(
      'label' => $value['label'],
      'parameter' => array(
        'commerce_line_item' => array(
          'type' => 'commerce_line_item',
          'label' => t('Line item'),
        ),
        'amount' => array(
          'type' => 'decimal',
          'label' => t('Amount'),
          'description' => $value['amount description'],
        ),
        'component_name' => array(
          'type' => 'text',
          'label' => t('Price component type'),
          'description' => t('Price components track changes to prices made during the price calculation process, and they are carried over from the unit price to the total price of a line item. When an order total is calculated, it combines all the components of every line item on the order. When the unit price is altered by this action, the selected type of price component will be added to its data array and reflected in the order total display when it is formatted with components showing. Defaults to base price, which displays as the order Subtotal.'),
          'options list' => 'commerce_price_component_titles',
          'default value' => 'list_price',
        ),
        'round_mode' => array(
          'type' => 'integer',
          'label' => t('Price rounding mode'),
          'description' => t('Round the resulting price amount after performing this operation.'),
          'options list' => 'commerce_round_mode_options_list',
          'default value' => COMMERCE_ROUND_HALF_UP,
        ),
      ),
      'group' => t('Commerce pricelist'),
    );
  }
  return $actions;
}