function uc_weight_format in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_store/uc_store.module \uc_weight_format()
- 5 uc_store/uc_store.module \uc_weight_format()
- 6.2 uc_store/uc_store.module \uc_weight_format()
Formats a weight value for display.
Parameters
$value: Numerical weight value.
$unit: Weight unit. One of 'lb', 'oz', 'kg', or 'g', or NULL to use store default weight units.
Return value
String containing formattted weight, including weight units.
6 calls to uc_weight_format()
- theme_uc_product_weight in uc_product/
uc_product.theme.inc - Formats a product's weight.
- uc_order_handler_field_order_weight_total::render in uc_order/
views/ uc_order_handler_field_order_weight_total.inc - Overrides views_handler_field::render().
- uc_product_handler_field_weight::render in uc_product/
views/ uc_product_handler_field_weight.inc - Overrides views_handler_field::render().
- uc_product_tokens in uc_product/
uc_product.tokens.inc - Implements hook_tokens().
- uc_shipping_handler_field_package_weight::render in shipping/
uc_shipping/ views/ uc_shipping_handler_field_package_weight.inc - Overrides uc_product_handler_field_weight::render().
File
- uc_store/
uc_store.module, line 982 - Contains global Ubercart functions and store administration functionality.
Code
function uc_weight_format($value, $unit = NULL) {
$vars = array(
'!value' => $value,
);
if (is_null($unit)) {
$unit = variable_get('uc_weight_unit', 'lb');
}
$defaults = array(
'lb' => '!value lb.',
'oz' => '!value oz.',
'kg' => '!valuekg',
'g' => '!valueg',
);
$pattern = variable_get('uc_weight_format_' . $unit, $defaults[$unit]);
if (strpos($pattern, '!value') === FALSE) {
$pattern = $defaults[$unit];
}
$format = strtr($pattern, $vars);
return $format;
}