You are here

function _commerce_line_item_update_rule_round_mode in Commerce Core 7

Given a Rule configuration, checks its element name to see if it is an action that requires a value for the new round_mode setting used in unit price manipulation actions.

2 calls to _commerce_line_item_update_rule_round_mode()
commerce_line_item_update_7000 in modules/line_item/commerce_line_item.install
Update Rules using unit price manipulation actions to set a default value for the rounding mode to use on the updated unit price amount.
_commerce_line_item_update_rule_container_round_mode in modules/line_item/commerce_line_item.install
Iterates over a container's children to recursively find non-container plugins whose settings should be updated.

File

modules/line_item/commerce_line_item.install, line 160

Code

function _commerce_line_item_update_rule_round_mode($rule) {

  // Build an array of all element names that require this new setting.
  $action_names = array(
    'commerce_line_item_unit_price_add',
    'commerce_line_item_unit_price_subtract',
    'commerce_line_item_unit_price_multiply',
    'commerce_line_item_unit_price_divide',
    'commerce_line_item_unit_price_amount',
  );

  // If the Rule passed in is one of these actions...
  if (in_array($rule
    ->getElementName(), $action_names)) {

    // Initialize its round_mode setting to match the previous behavior of not
    // rounding at all and save it.
    $rule->settings['round_mode'] = COMMERCE_ROUND_HALF_UP;
    $rule
      ->save();
  }
}