Posted by psy on November 1, 2009 at 4:31am
| Project: | Ubercart Views |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | minor |
| Assigned: | madsph |
| Status: | closed (fixed) |
Issue Summary
Hi,
I added support for the physical Weight on uc_orders_products by inserting this near line 90 of 'uc_views.views.inc'
<?php
$data['uc_order_products']['weight'] = array(
'title' => t('Weight'),
'help' => $order_products['fields']['weight']['description'],
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_float',
),
);
However when i tried to change the [field][handler] from the default 'views_handler_field' to ubercart's (RC6) handler for weights 'uc_product_handler_field_weight' it turned ugly. I cant remember right now what happened.
I Will report more on this, but i feel it maybe related to the same issue #614032: Views with Order total field blank in UC2.0 here.
Comments
#1
The ugliness reported when the field handler is set to 'uc_product_handler_field_weight' was 'Fatal error: Cannot access empty property in /home/blah/public_html/sites/all/modules/ubercart/uc_product/views/uc_product_handler_field_weight.inc on line 14'.
#2
Here is a working solution
Add this to uc_views_views_handlers() handlers array near line 845 of 'uc_views.views.inc':
'uc_views_handler_field_weight' => array('parent' => 'views_handler_field',),
And put this file 'uc_views_handler_field_weight.inc' (attached and listed) to the views folder
<?php
// $Id: uc_views_handler_field_weight.inc,v 1.1.2.2 2008/11/07 21:13:28 islandusurper Exp $
/**
* @file
* Views handler: Orders Products physical weight field.
*/
/**
* Return a formatted weight value to display in the View.
*/
class uc_views_handler_field_weight extends views_handler_field {
function render($values) {
return uc_weight_format($values->value);
}
}
?>
Finally change the weight field element from above to use the new field_handler
<?php$data['uc_order_products']['weight'] = array(
'title' => t('Weight'),
'help' => $order_products['fields']['weight']['description'],
'field' => array(
'handler' => 'uc_views_handler_field_weight',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_float',
),
);
?>
This works for me
#3
Thanks.
I will take a look into this and then get back to you.
#4
I worked around the problem you had about using the default weight handler from uc_products by adding the weight unit as an additional field to the weight.
Your patch is committed to the dev branch. Thank you for the great work.
#5
@madsph
And thanks for yours!
#6
Automatically closed -- issue fixed for 2 weeks with no activity.