function commerce_price_wrapper_value in Commerce Core 7
Returns the data array of a single value price field from a wrapped entity, using an optional default value if the entity does not have data in the field.
Parameters
$wrapper: An EntityMetadataWrapper for the entity whose price should be retrieved.
$field_name: The name of the field to retrieve data from in the wrapper.
$default: Boolean indicating whether or not to return a default price array if the entity does not have data in the specified price field.
Return value
The data array of the specified price field.
8 calls to commerce_price_wrapper_value()
- CommerceLineItemEntityController::save in modules/
line_item/ includes/ commerce_line_item.controller.inc - Saves a line item.
- 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_currency_code in modules/
line_item/ commerce_line_item.rules.inc - Rules action: set the unit price's currency code.
- commerce_line_item_unit_price_currency_convert in modules/
line_item/ commerce_line_item.rules.inc - Rules action: convert the unit price to a different currency.
File
- modules/
price/ commerce_price.module, line 849 - Defines the Price field with widgets and formatters used to add prices with currency codes to various Commerce entities.
Code
function commerce_price_wrapper_value($wrapper, $field_name, $default = FALSE) {
// Extract the price field's value array from the given entity.
$price = $wrapper->{$field_name}
->value();
// If the value is empty and we want to return a default value for the field,
// use the auto creation value defined for Entity API usage.
if (empty($price) && $default) {
$price = commerce_price_field_data_auto_creation();
}
return $price;
}