Discussions

Display Product with discount

Hi everyone,

My problem is simple, i want a view with all products that have a discount in my store but i can find a way to filter in that purpose.

Thanks in advance for your help.

Posted: Nov 25, 2013

Comments

DNZ Andy @ BlueFusion on November 25, 2013

Hi Franki,

I think the below is generic enough to work, but it does assume the discounts are handled through https://drupal.org/project/commerce_saleprice

If you are using the https://drupal.org/project/commerce_discount module then have a look through the list of views you should have a 'Discount' View at admin/structure/views/view/commerce_discount_overview . That should get you started.

Here's a view for the Sale Price module.

$view = new view();
$view->name = 'delete';
$view->description = 'All discounted products';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Discounted products';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Discounted Products';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
$handler->display->display_options['row_options']['links'] = FALSE;
/* Relationship: Field: Referenced products */
$handler->display->display_options['relationships']['field_product_product_id']['id'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['table'] = 'field_data_field_product';
$handler->display->display_options['relationships']['field_product_product_id']['field'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['required'] = TRUE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Commerce Product: Sale price (field_commerce_saleprice:amount) */
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['id'] = 'field_commerce_saleprice_amount';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['table'] = 'field_data_field_commerce_saleprice';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['field'] = 'field_commerce_saleprice_amount';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['relationship'] = 'field_product_product_id';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['operator'] = 'not empty';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'discounted-products';

DNZ Andy @ BlueFusion on November 25, 2013

Hi Franki,

I think the below is generic enough to work, but it does assume the discounts are handled through https://drupal.org/project/commerce_saleprice

If you are using the https://drupal.org/project/commerce_discount module then have a look through the list of views you should have a 'Discount' View at admin/structure/views/view/commerce_discount_overview . That should get you started.

Here's a view for the Sale Price module.

$view = new view();
$view->name = 'delete';
$view->description = 'All discounted products';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Discounted products';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Discounted Products';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
$handler->display->display_options['row_options']['links'] = FALSE;
/* Relationship: Field: Referenced products */
$handler->display->display_options['relationships']['field_product_product_id']['id'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['table'] = 'field_data_field_product';
$handler->display->display_options['relationships']['field_product_product_id']['field'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['required'] = TRUE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Commerce Product: Sale price (field_commerce_saleprice:amount) */
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['id'] = 'field_commerce_saleprice_amount';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['table'] = 'field_data_field_commerce_saleprice';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['field'] = 'field_commerce_saleprice_amount';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['relationship'] = 'field_product_product_id';
$handler->display->display_options['filters']['field_commerce_saleprice_amount']['operator'] = 'not empty';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'discounted-products';

FrankiAA on November 26, 2013

Hi, thanks for your answer.

I try sale price module with your view but i just get all products...
I search for a field to filter that but i still can't find a proper way.

I take a look to the view discount too but it's not a display products so i'm a bit lost with this one.

FrankiAA on November 28, 2013

Thanks for your answers but i tried with each solutions...and i still can't find a way to do that even with the saleprice module...
If anyone have done that before or have a way to do that...
Thanks.