function commerce_line_item_unit_price_currency_code in Commerce Core 7
Rules action: set the unit price's currency code.
File
- modules/
line_item/ commerce_line_item.rules.inc, line 283 - Rules integration for line items.
Code
function commerce_line_item_unit_price_currency_code($line_item, $currency_code) {
$wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
$unit_price = commerce_price_wrapper_value($wrapper, 'commerce_unit_price');
// Only set the currency on prices with non-NULL amounts.
if (empty($unit_price)) {
return;
}
$wrapper->commerce_unit_price->currency_code = $currency_code;
// Update the currency code of the price's components.
if (!empty($unit_price['data']['components'])) {
foreach ($unit_price['data']['components'] as $key => &$component) {
$component['price']['currency_code'] = $currency_code;
}
$wrapper->commerce_unit_price->data = $unit_price['data'];
}
}