_store_location_measure_convert

Definition

_store_location_measure_convert($value, $from, $to)
ecommerce-5--4/store/store.localization.inc, line 597

Description

Convert some measure units to another. All units are converted to a central unit and them converted again to the destination units.

All weight is converted to kilograms and then to the destination. All distance is converted to meters and then to the destination. All area is converted to square meters and then to the destination. All volume is converted to cubic meters and then to the destination.

Parameters

$value Number. The value in the old unit

$from String. The unit code that the value is origined

$to String. The unit code that the value should be converted to

Return value

Number. The converted value

Code

<?php
function _store_location_measure_convert($value, $from, $to) {
  if ($from == $to) {
    return $value;
  }
  $default = false;
  $measures = _store_location_measures();
  if (!isset($measures[$from]) || !isset($measures[$to]) || $measures[$from]['type'] != $measures[$to]['type']) {
    // Something is screwy.
    watchdog('store', 'e-Commerce failed to convert '. $measures[$from] .' to '. $measures[$to] .'.', WATCHDOG_ERROR);
    return false;
  }
  return $value * $measures[$from]['factor'] / $measures[$to]['factor'];
}
?>