0

We have the following view.

$view = new view();
$view->name = 'bestsellers';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'commerce_order';
$view->human_name = 'Bestsellers';
$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['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['columns'] = array(
  'title_1' => 'title_1',
  'view_node' => 'view_node',
  'title' => 'title',
  'product_id' => 'product_id',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title_1' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'view_node' => array(
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'product_id' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: Commerce Order: Referenced line items */
$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['id'] = 'commerce_line_items_line_item_id';
$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['table'] = 'field_data_commerce_line_items';
$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['field'] = 'commerce_line_items_line_item_id';
$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['label'] = 'line_items';
$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['required'] = TRUE;
/* Relationship: Commerce Line item: Referenced products */
$handler->display->display_options['relationships']['commerce_product_product_id']['id'] = 'commerce_product_product_id';
$handler->display->display_options['relationships']['commerce_product_product_id']['table'] = 'field_data_commerce_product';
$handler->display->display_options['relationships']['commerce_product_product_id']['field'] = 'commerce_product_product_id';
$handler->display->display_options['relationships']['commerce_product_product_id']['relationship'] = 'commerce_line_items_line_item_id';
$handler->display->display_options['relationships']['commerce_product_product_id']['label'] = 'products';
$handler->display->display_options['relationships']['commerce_product_product_id']['required'] = TRUE;
/* Field: Commerce Product: SKU */
$handler->display->display_options['fields']['sku']['id'] = 'sku';
$handler->display->display_options['fields']['sku']['table'] = 'commerce_product';
$handler->display->display_options['fields']['sku']['field'] = 'sku';
$handler->display->display_options['fields']['sku']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['fields']['sku']['link_to_product'] = 0;
/* Field: Commerce Product: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'commerce_product';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'commerce_product_product_id';
/* Field: COUNT(Commerce Product: Product ID) */
$handler->display->display_options['fields']['product_id']['id'] = 'product_id';
$handler->display->display_options['fields']['product_id']['table'] = 'commerce_product';
$handler->display->display_options['fields']['product_id']['field'] = 'product_id';
$handler->display->display_options['fields']['product_id']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['fields']['product_id']['group_type'] = 'count';
$handler->display->display_options['fields']['product_id']['label'] = 'Count';
$handler->display->display_options['fields']['product_id']['separator'] = '';
/* Sort criterion: COUNT(Commerce Product: Product ID) */
$handler->display->display_options['sorts']['product_id']['id'] = 'product_id';
$handler->display->display_options['sorts']['product_id']['table'] = 'commerce_product';
$handler->display->display_options['sorts']['product_id']['field'] = 'product_id';
$handler->display->display_options['sorts']['product_id']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['sorts']['product_id']['group_type'] = 'count';
$handler->display->display_options['sorts']['product_id']['order'] = 'DESC';
/* Filter criterion: Commerce Line Item: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'commerce_line_item';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['relationship'] = 'commerce_line_items_line_item_id';
$handler->display->display_options['filters']['type']['value'] = array(
  'product' => 'product',
);
/* Filter criterion: Commerce Product: Type */
$handler->display->display_options['filters']['type_1']['id'] = 'type_1';
$handler->display->display_options['filters']['type_1']['table'] = 'commerce_product';
$handler->display->display_options['filters']['type_1']['field'] = 'type';
$handler->display->display_options['filters']['type_1']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['filters']['type_1']['value'] = array(
  'product' => 'product',
);

It displays Bestsellers with buy counter, but it also displays the ones that are in shopping cart (wasn't even bought). Does anybody know how to delete shopping cart results from the counter, and display only the really bought product counter?

I want it to display 0 when there aren't bought products. I tried rewriting the view, but it didn't work. "No results" doesn't work. I verified there aren't hide empty fields anywhere. I tried to add the "No results" behavior for whole site, but it doesn't allow me as well. How should I do, to get a 0 shown when there aren't bought products?

2
  • If the base table is commerce_order can you not just filter by the order status?
    – Clive
    Commented May 3, 2014 at 12:11
  • I just added a filter with order status and now it shows perfectly the ones I want to be shown! Now the last thing is to display 0 value if there's nothing counted. Thank you mate!
    – Michael D
    Commented May 3, 2014 at 12:25

1 Answer 1

0

In Filter Criteria I have added Commerce Order: Order status field and specified which status do I want to be counted only.

To display 0 I needed to add No results behavior for whole display. I have added Global: Text area field. Unfortunately 0 didn't want to get displayed so I needed to display it with PHP.

$count = '<strong>0</strong>';
print $count; 

Actually I needed it to be strong so it wasn't an issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.