views filter by price?

Posts: 68
Joined: 11/26/2007

I'm setting up a view to filter by price. Basically, I want to set up urls like:

products/price/300/500

I don't see price as one of the choices in the dropdown on the views admin page under filters. Is there something I'm missing? Is there some other way to accomplish this?

Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

I'm confident there is, but I don't know the Views API well enough yet to add it. If someone figures it out before I do, they can post it and I'll put it in.

Posts: 68
Joined: 11/26/2007

I think it's something to do with Argument Handling Code. I'll post when I get it figured out.

Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

It's that, plus adding in the filters and handlers for that data.

Posts: 50
Joined: 08/17/2007
Getting busy with the Ubercode.Spreading the word - Ubercart for president.

these two links off drupal.org may prove useful:

http://drupal.org/node/164471

&

http://drupal.org/node/150248

Posts: 45
Joined: 12/24/2007

+ Subscribe

I also need to have price in view filters!

So, Lyle, can you told me - wha code i must writу to do this?

Posts: 45
Joined: 12/24/2007

As a variant - i use http://drupal.org/project/computed_field to create new filed, which duplicates value of $node->sell_price.

This new filed i can use in views filter.

But this solution is ot good Sad

Posts: 13
Joined: 01/23/2008

Suscribe
I don't understand why the fields product price and other are in the "fields" of view and not in "filters"?

Posts: 28
Joined: 08/08/2007

Reviving this thread to find out how to use the price fields as Views (exposed) filters.

Posts: 28
Joined: 03/26/2008

I've acheived this but I can't remember how I did it. I think there was a thread that made the product price available as a filter.

Here's the exported views code I have:

  $view = new stdClass();
  $view->name = 'testprice';
  $view->description = 'Sort by price';
  $view->access = array (
  0 => '1',
  1 => '2',
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'bonus_grid';
  $view->url = 'Prices';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '12';
  $view->sort = array (
    array (
      'tablename' => 'uc_products',
      'field' => 'sell_price',
      'sortorder' => 'DESC',
      'options' => '',
    ),
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'sortable' => '1',
      'options' => 'link',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'model',
      'label' => '',
      'options' => 'nolink',
    ),
    array (
      'tablename' => 'node_data_field_image_cache',
      'field' => 'field_image_cache_fid',
      'label' => '',
      'handler' => 'content_views_field_handler_ungroup',
      'options' => 'product_list_linked',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'is_product',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'sell_price',
      'operator' => '<',
      'options' => '',
      'value' => '',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'sell_price',
      'operator' => '>',
      'options' => '',
      'value' => '',
    ),
    array (
      'tablename' => 'node',
      'field' => 'distinct',
      'operator' => '=',
      'options' => '',
      'value' => array (
  0 => 'distinct',
),
    ),
  );
  $view->exposed_filter = array (
    array (
      'tablename' => 'uc_products',
      'field' => 'sell_price',
      'label' => '',
      'optional' => '0',
      'is_default' => '0',
      'operator' => '0',
      'single' => '1',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'sell_price',
      'label' => '',
      'optional' => '0',
      'is_default' => '0',
      'operator' => '0',
      'single' => '1',
    ),
  );
  $view->requires = array(uc_products, node, node_data_field_image_cache);
  $views[$view->name] = $view;

If anyone knows what files I can post to help you find what you need to change then let me know and I will gladly post them. I think I changed a views .module file.

Posts: 28
Joined: 03/26/2008

I found the patch I used to make this work:

http://drupal.org/node/241561

By the way does anyone know if it's possible to force the exposed filter to only have one option? Right now I have the filter exposed and it allows me to choose from: Greater than, Less than or Equals to. Is it possible to force it to be Greater than and then expose another sell price filter with Less than?

THanks!