osC_Weight - Weight Conversion Class | Last Update: 7th April, 2005 Article ID: 10 |
- Introduction
- Examples
- Class API
Introduction
The weight class is used provide a structured way of handling products and shipping systems that use different units of weight.
This class allows a combination of any number of products having different units of weight. Once a shipping quote is required the weight is converted to that as required by the shipping module.
Examples
Displaying the products weight:
<?php
$osC_Weight = new osC_Weight;
$osC_Weight->display($products_weight, $products_weight_class);
?>
Converting between weight classes:
<?php
$osC_Weight = new osC_Weight;
$osC_Weight->convert($shipping_weight, $weight_unit_from, $weight_unit_to);
?>
Class API
- prepareRules()
- convert($value, $unit_from, $unit_to)
- display($value, $class)
prepareRules()
Loads all of the rules into cache.
convert($value, $unit_from, $unit_to)
Converts between weight units.
If the from and to units are the same no calculation is carried out.
display($value, $class)
Formats the weight for output to the browser.