I wanted a views filter for sell price, so I made a patch for others. The same format could be used for 'cost', 'list_price', 'pkg_qty', or the various dimensions fields. I didn't need this stuff, so I didn't implement it, but I will if people need it.

CommentFileSizeAuthor
ubercart_sell_price_views_filter.patch717 byteskonsumer

Comments

rszrama’s picture

Status: Needs review » Fixed

Thanks for the patch! I tested this on the Livetest and extended it for the other prices and product weight.

woc_art’s picture

Hi there,

Thanks for this patch! It's just what I needed!

k8n’s picture

seems to me that this is geared towards Views v2. Below is the code that could be used as the handler for Views v1.

/**
 * Filter out nodes by price.
 */
function uc_product_views_handler_filter_price($op, $filter, $filterinfo, &$query) {
  switch ($op) {
    case 'handler':
      if ($filter['value'] && is_numeric($filter['value'])) {
        $money_value_sql = "cast('{$filter['value']}' as decimal(10,2))";
        switch ($filter['operator']) {
          case '=':
            $query->add_where("uc_products.sell_price = {$money_value_sql}");
            break;
          case '<':
            $query->add_where("uc_products.sell_price < {$money_value_sql}");
            break;
          case '>':
            $query->add_where("uc_products.sell_price > {$money_value_sql}");
            break;
        }
      }
    break;
  }
}
rszrama’s picture

Did you test out the original patch? It seemed to work fine for me on the Livetest. Is there something specific that you believe wouldn't work in it?

konsumer’s picture

Yeh, I was using views 1. Works fine for me.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Jurgen8en’s picture

Hi,

Can somebody help me, I added the code of this patch. But I didn´t see an extra filter in views.

Only the 'Product: Is Product' filter.

'views_handler_filter_numeric', I didn´t find in views.module

Now, I added this:

'sell_price'=>array(
        'name' => t('Product: Sell Price'),
        'operator' => array('=' => 'Equals'),
        'handler' => 'views_handler_operator_gtlt',
        'help' => t('Filter the node based on whether or not it matches sell price criteria.'),
      ),

Still see nothing