Hi,

I noticed that Payment Method is not enabled for use as a filter.

I ended up just putting this into uc_views.views.inc at line 276. This just achieves a simple string filter.

I added the 'filter' key to the array.


  $data['uc_orders']['payment_method'] = array(
    'title' => t('Order Payment Method'),
    'help' => $order_schema['fields']['payment_method']['description'],
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
     'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
  );

What would be cool though is to call _payment_method_list($action = NULL) and have all the payments available for a subclass of 'views_handler_filter_in_operator'.

CommentFileSizeAuthor
#1 payment_method_filter.zip4.57 KBpsy

Comments

psy’s picture

StatusFileSize
new4.57 KB

Actually an even cooler solution is here.

Find attached 'views_handler_filter_payment_method.inc'. This adds a filter handler that simply gets an array of all payment methods that are registered in the uc_orders and provides them as a 'views_handler_filter_in_operator'

1. Place this file into the views folder
2. Update uc_views.views.inc near line 838 and add 'views_handler_filter_payment_method' => array('parent' => 'views_handler_filter_in_operator',), to the 'handlers' array in the function 'uc_views_views_handlers'
3. Add the filter key to payment_method field for the view. Near line 267 you need to add/change the filter key to
'filter' => array(
'handler' => 'views_handler_filter_payment_method',
),

Here some code for the file 'views_handler_filter_payment_method.inc'

<?php
// $Id: views_handler_filter_payment_method.inc,v 1.1 2009/03/09 09:36:12 madsph Exp $
/**
 * Filter by payment method 
 *
 */
class views_handler_filter_payment_method extends views_handler_filter_in_operator {
  function get_value_options() {
    if (!isset($this->value_options)) {
      $this->value_title = t('Payment Method');
      $this->value_options = _distinct_payment_methods(); // $method;
    }
  }
}

/*
	_distinct_payment_methods()
	returns an array of DISTINCT payment methods from the uc_oders table

*/

function _distinct_payment_methods() {
	
	$methods = array();
	
	$result = db_query("SELECT DISTINCT payment_method AS payment_methods FROM {uc_orders}");
	while($pm = db_fetch_object($result)) {
		
		$methods[$pm->payment_methods] = $pm->payment_methods;
	
	}
	
	return $methods;
	
}

Heres the code for the payment_method field

<?php

  $data['uc_orders']['payment_method'] = array(
    'title' => t('Order Payment Method'),
    'help' => $order_schema['fields']['payment_method']['description'],
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
     'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_payment_method',
    ),
  );

And here is the code for 'uc_views_views_handlers()'

<?php

function uc_views_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'uc_views') . '/views',
    ),
    'handlers' => array(
      // fields
      'uc_views_handler_field_order_id' => array( 'parent' => 'views_handler_field',),
      'uc_views_handler_field_cart_user' => array('parent' => 'views_handler_field',),
      'uc_views_handler_field_order_actions' => array( 'parent' => 'views_handler_field',),
      'uc_views_handler_field_country' => array( 'parent' => 'views_handler_field',),
      'uc_views_handler_field_zone' => array( 'parent' => 'views_handler_field',),
      'uc_views_handler_field_order_status' => array( 'parent' => 'views_handler_field',),
      'uc_views_handler_field_conditional_buyitnow' => array('parent' => 'views_handler_field',),
      'uc_views_handler_field_conditional_addtocart' => array('parent' => 'views_handler_field',),
      'uc_views_handler_field_money_amount' => array('parent' => 'views_handler_field',),
      //fiters
      'views_handler_filter_order_status' => array('parent' => 'views_handler_filter_in_operator',),

      //add this line
      'views_handler_filter_payment_method' => array('parent' => 'views_handler_filter_in_operator',),

      'uc_views_handler_filter_country' => array('parent' => 'views_handler_filter_in_operator',),
      'uc_views_handler_filter_zone' => array('parent' => 'views_handler_filter_in_operator',),
//      'uc_views_handler_filter_distinct' => array('parent' => 'views_handler_filter',),
    ),
  );
}

Or download the attachment and place these files into the 'views' directory under 'uc_views' module directory

madsph’s picture

Assigned: Unassigned » madsph

Thank you for the suggestion. This sounds cool indeed.

I will take a look at it and get back to you when I have tested and committed.

psy’s picture

Hi madsph,

I dont think that '_distinct_payment_methods()' is the most elegant solution. I just threw it together to get the job done. This is because the popup is populated using the machine name of the payment method both as the key (for the filter) and value (for the UI). However the payment method as displayed by the View field is that same machine name. It might be better to try and map the payment methods real name to machine name. This would be good for display of the field in the View as well, but whether its worth the trouble I am not sure.

All of this came about because our site uses multiple payment methods and we needed to filter those.

Your module is excellent BTW and has made our admin people very happy.

madsph’s picture

I have committed your patch to the dev branch.

I think you are right that it can be enhanced a little - but it works okay this way.

Thank you (again) for the great work!

psy’s picture

I just installed the dev version (3rd Nov).

Awesome work.

Im diving into the attributes as we speak.

This is a great module and i highly recommend it for any ubercart site!

Thank you very much for your efforts.

psy’s picture

Status: Active » Fixed

Setting this to fixed.

Status: Fixed » Closed (fixed)

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