<?php
/*Funçoes para trabalhar com unidades de medidas*/
class ftr_metrics
{   
    public static function cmToM($cm)
    {
        return $cm / 100;
    }    

    public static function getCubicValues($products, $cubic_factor=300){
        $data = array();
        $cubic_total = 0;
        $cubic_value = 0;
        foreach($products as $product){
            $cubic_value =  $product['quantity'] * (ftr_metrics::cmToM($product['width'])*ftr_metrics::cmToM($product['length'])*ftr_metrics::cmToM($product['height'])*$cubic_factor);
            $data['products'][] = array(
                "product_id"  => $product['product_id'],
                "cubic_value" => $cubic_value
            );
            $cubic_total += $cubic_value; 
        }
        $data['cubic_total'] = round($cubic_total,3);

        return $data;
    }
 
}
