class uc_views_handler_field_order_weight in Ubercart Views 6.3
Return the full name
Hierarchy
- class \uc_views_handler_field_order_weight extends \views_handler_field_numeric
Expanded class hierarchy of uc_views_handler_field_order_weight
1 string reference to 'uc_views_handler_field_order_weight'
- uc_views_views_data in views/
uc_views.views.inc - Implementation of hook_views_data().
File
- views/
uc_views_handler_field_order_weight.inc, line 11 - Views handler: Order total weight
View source
class uc_views_handler_field_order_weight extends views_handler_field_numeric {
function option_definition() {
$options = parent::option_definition();
$options['weight_units'] = array(
'default' => variable_get('uc_weight_unit', 'lb'),
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['weight_units'] = array(
'#type' => 'select',
'#title' => t('Unit of measurement'),
'#default_value' => $this->options['weight_units'],
'#options' => array(
'lb' => t('Pounds'),
'kg' => t('Kilograms'),
'oz' => t('Ounces'),
'g' => t('Grams'),
),
);
}
function query() {
$this
->ensure_my_table();
$this
->add_additional_fields();
}
function render($values) {
$oid = $values->{$this->aliases['order_id']};
$order = uc_order_load($oid);
$total = 0;
// TODO: Replace this for a mysql query like the cost field handler
foreach ($order->products as $product) {
$unit_conversion = uc_weight_conversion($product->weight_units, $this->options['weight_units']);
$total += $product->qty * $product->weight * $unit_conversion;
}
$this->field_alias = 'order_weight';
$values->{$this->field_alias} = $total;
return parent::render($values);
}
}