10 replies [Last post]
sprugman's picture
Offline
Joined: 11/26/2007
Juice: 202
Was this information Helpful?

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?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: views filter by price?

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.

sprugman's picture
Offline
Joined: 11/26/2007
Juice: 202
Re: Re: views filter by price?

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

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Re: views filter by price?

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

aswalla's picture
Offline
Getting busy with the Ubercode.Spreading the word - Ubercart for president.
Joined: 08/17/2007
Juice: 105
Re: Re: Re: views filter by price?

these two links off drupal.org may prove useful:

http://drupal.org/node/164471

&

http://drupal.org/node/150248

eugef@drupal.org's picture
Offline
Joined: 12/24/2007
Juice: 102
+ Subscribe I also need to

+ Subscribe

I also need to have price in view filters!

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

eugef@drupal.org's picture
Offline
Joined: 12/24/2007
Juice: 102
Re: + Subscribe I also need to

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

gagarine@drupal.org's picture
Offline
Joined: 01/23/2008
Juice: 27
Suscribe I don't understand

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

ulfk@drupal.org's picture
Offline
Joined: 08/08/2007
Juice: 72
Price fields in Views filters

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

woc_art's picture
Offline
Joined: 03/26/2008
Juice: 63
Re: Price fields in Views filters

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.

woc_art's picture
Offline
Joined: 03/26/2008
Juice: 63
Re: Re: Price fields in Views filters

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!