You are here

function commerce_price_component_add in Commerce Core 7

Adds a price component to a price's data array.

Parameters

$price: The price array the component should be added to.

$type: The machine-name of the component type to be added to the array.

$component_price: The price array for the component as defined by the price field.

$included: Boolean indicating whether or not the price component has already been included in the price the component is being added to.

$add_base_price: Boolean indicating whether or not to add the base price component if it is missing.

Return value

The updated data array.

11 calls to commerce_price_component_add()
commerce_line_item_rebase_unit_price in modules/line_item/commerce_line_item.module
Recalculates the price components of the given line item's unit price based on its current amount and currency code.
commerce_line_item_unit_price_add in modules/line_item/commerce_line_item.rules.inc
Rules action: add an amount to the unit price.
commerce_line_item_unit_price_amount in modules/line_item/commerce_line_item.rules.inc
Rules action: set the unit price to a specific amount.
commerce_line_item_unit_price_divide in modules/line_item/commerce_line_item.rules.inc
Rules action: divide the unit price by some amount.
commerce_line_item_unit_price_multiply in modules/line_item/commerce_line_item.rules.inc
Rules action: multiply the unit price by some amount.

... See full list

File

modules/price/commerce_price.module, line 959
Defines the Price field with widgets and formatters used to add prices with currency codes to various Commerce entities.

Code

function commerce_price_component_add($price, $type, $component_price, $included, $add_base_price = TRUE) {

  // If no price components have been added yet, add the base price first.
  if ($add_base_price && empty($price['data']['components']) && $type != 'base_price') {
    $price['data'] = commerce_price_component_add($price, 'base_price', $price, TRUE);
  }
  $price['data']['components'][] = array(
    'name' => $type,
    'price' => $component_price,
    'included' => $included,
  );
  return $price['data'];
}