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.

CommentFileSizeAuthor
#2 uc_views_handler_field_weight.inc_.zip820 bytespsy

Comments

psy’s picture

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'.

psy’s picture

StatusFileSize
new820 bytes

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

// $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


  $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

madsph’s picture

Thanks.

I will take a look into this and then get back to you.

madsph’s picture

Assigned: Unassigned » madsph
Status: Active » Fixed

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.

psy’s picture

@madsph

And thanks for yours!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.