Hi,
I have one simple question: how to create a view, which shows most popular bought products?

I've tried many things, including looking at database fields and looks like this particular info is saved as a blob field type and might be not so easy to achieve this task...

Comments

rszrama’s picture

Status: Active » Fixed

Nope, you have product IDs stored in the field data for line items. The gist of it is going to require a View of Orders joined to Line Items via the "Commerce Line Items relationship" joined to the Products via the "Referenced product" relationship. You can filter by Order State to only see purchased products and then count the occurrence of each Product ID to get the most referenced products. The hardest part will be establishing a relationship from the Product ID to the product display, but I believe you can use the reverse relationship from the product ID to a node referencing it so long as you only have a single product display per product.

amfis’s picture

Thanks for directions, will try!

Status: Fixed » Closed (fixed)

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

brunorios1’s picture

"and then count the occurrence of each Product ID to get the most referenced products"

how can i do this?

thanks!

brunorios1’s picture

Status: Closed (fixed) » Active
rszrama’s picture

Status: Active » Closed (fixed)

Let's not reopen this old issue here. Your best bet would be to try a Views support channel, like #drupal-views in IRC. I don't actually know how you'd configure such a query through the UI, and it's a bit out of scope for the issue tracker for the Commerce project itself. I'm guessing you'll need some sort of a distinct query with some sort of computed field or aggregated count on the product ID, but that's really just a shot in the dark.

brunorios1’s picture

sorry for reopened the issue...

actually, there is another method to build a block of "bestsellers" or "popular products"? this is very necessary for an e-commerce project!

thanks!

rszrama’s picture

There may be a module doing it if you give it a search. You might also check drupalcommerce.org - there's a lot of discussion there about configuring Commerce sites and a directory of most available contribs.

Summit’s picture

Hi, this one is only on the node level I think: http://drupal.org/sandbox/anthonylindsay/1643068
But this one looks promissing by using radioactivity :) http://drupal.org/project/commerce_productpopularity.

Greetings, Martijn

tmsimont’s picture

here's a view export that show's product display title of most sold products... you might have to rework the machine names of the node display type and product type, but maybe this will help others.

$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['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'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Commerce Order: Referenced line item */
$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']['required'] = 1;
/* Relationship: Commerce Line item: Referenced product */
$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']['required'] = 1;
/* Relationship: Commerce Product: Node referencing products from field_product */
$handler->display->display_options['relationships']['field_product']['id'] = 'field_product';
$handler->display->display_options['relationships']['field_product']['table'] = 'commerce_product';
$handler->display->display_options['relationships']['field_product']['field'] = 'field_product';
$handler->display->display_options['relationships']['field_product']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['relationships']['field_product']['label'] = 'Node';
$handler->display->display_options['relationships']['field_product']['required'] = 0;
/* Field: Content: Title */
$handler->display->display_options['fields']['title_1']['id'] = 'title_1';
$handler->display->display_options['fields']['title_1']['table'] = 'node';
$handler->display->display_options['fields']['title_1']['field'] = 'title';
$handler->display->display_options['fields']['title_1']['relationship'] = 'field_product';
$handler->display->display_options['fields']['title_1']['label'] = '';
$handler->display->display_options['fields']['title_1']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['external'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title_1']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['title_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title_1']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['title_1']['empty_zero'] = 0;
$handler->display->display_options['fields']['title_1']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['title_1']['link_to_node'] = 0;
/* Field: Content: Link */
$handler->display->display_options['fields']['view_node']['id'] = 'view_node';
$handler->display->display_options['fields']['view_node']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['view_node']['field'] = 'view_node';
$handler->display->display_options['fields']['view_node']['relationship'] = 'field_product';
$handler->display->display_options['fields']['view_node']['label'] = '';
$handler->display->display_options['fields']['view_node']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['view_node']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['view_node']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['trim'] = 0;
$handler->display->display_options['fields']['view_node']['alter']['html'] = 0;
$handler->display->display_options['fields']['view_node']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['view_node']['element_default_classes'] = 1;
$handler->display->display_options['fields']['view_node']['hide_empty'] = 0;
$handler->display->display_options['fields']['view_node']['empty_zero'] = 0;
$handler->display->display_options['fields']['view_node']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['view_node']['text'] = 'view details';
/* Sort criterion: COUNT(Commerce Product: Title) */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'commerce_product';
$handler->display->display_options['sorts']['title']['field'] = 'title';
$handler->display->display_options['sorts']['title']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['sorts']['title']['group_type'] = 'count';
$handler->display->display_options['sorts']['title']['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',
);
Summit’s picture

Hi, thanks for showing your view. How could I show the ordertotal for the products?
greetings, Martijn

tmsimont’s picture

If you add in a field for product ID and set aggregation settings to "COUNT" that should show the number of products ordered.

Summit’s picture

Hi, I did exactly that..but the amounts shown are much to high....could it be that the view with product ID shows all products placed in basket, and not all ordered?
greetings, Martijn

tmsimont’s picture

Could be yes -- it's probably a filter you need to set on the order status

tmsimont’s picture

Issue summary: View changes

edit

yogeshchaugule8’s picture

#10 worked great, thanks.

Addition to it, we can add "content:nid is not empty". This will help removing products from result which were sold but currently doesn't has any reference.

Few additions:

  1. Content:nid is not empty
  2. Product:status is active
  3. Content:published is true
firstvoder’s picture

hello,

Thx for this useful view. I tried it, but didnt get it to work so far. I guess its because of the machine names as tmsimont wrote. I dont mind playing more around with it to get it work, but i have a question before i spend more time on this.

does this require that all customers can see all orders in the permission settings? the view that i have right now (modified version of the line items view that came with commerce) requires this permission setting so im looking for a securer alternative.

i only found this on "view any product" and the security implication, https://drupal.org/node/1303194.

thx for any info on this.

ItangSanjana’s picture

@firstvoder

does this require that all customers can see all orders in the permission settings?

Ya I think so
CMIIW

jenlampton’s picture

Issue summary: View changes

I also had some trouble with the view provided above. Not only because the product types and names didn't match my site, but also because the COUNT was happening on a non-unique field. I have many products with the same titles, but they all still have unique IDs and SKUs, so either of those fields would be fine to use instead. Here is another version of the same view, this time with the COUNT happening on the product ID (which is unique).

In order to make this work for your own site, you'll need to import the view, then click on both filter criteria and adjust them for your own commerce site.

$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',
);
ItangSanjana’s picture

@jenlampton
Awesome, thanks for the export!

alifspb’s picture

hi thanks for share code its working good. i create block for this and i put sidebar second but after sing out from my admin account i cant see this in my block section i mean for anonymous user what wrong please help me ? i set in view
Access: Permission | View published content
but its now showing :( please help me find out this problem
thanks Advance

mitrpaka’s picture

As already stated in #16 "view any product" permission is required. Additionally, in order to anonymous and logged users to see most popular products of all, "view any order" permission is required.

But please bare in mind possible security implications that may apply for above permissions, see https://drupal.org/node/1303194.

alifspb’s picture

#21
thanks for your kind reply its save my tonssss time thanks again :)

kscheirer’s picture

Thanks jenlampton #18 worked great for me too. Seems like there's enough interest for this to be included in commerce or a contrib module. The view is not trivial to build from scratch and its pretty useful.

kristofferrom’s picture

JenLampton's view works for me too.

But can anyone give me a tip to have each product title link to a Product Display of the same title?

nourheine’s picture

thanks for this awsome view #18, that works for me

thronedigital’s picture

Hate to reopen a closed topic, but how would one do this with product display instead of product. I have an access control on product display that is a requirement in this view.

So really just need a similar idea, but with product displays instead.

Thank you,

- Dane

denix’s picture

Status: Closed (fixed) » Active

Dear all, Thanks for the export, which works great.
On the other hand, this views is more for administrative use, and it is not suited to be showed to the public because of the requested permissions and the absence of a link with the product display.
This is why I am reopening it and I hope to find a solution :) Thanks again!

rszrama’s picture

Status: Active » Closed (fixed)

Sorry, we don't offer support for common configurations in this tracker. Your best bet is to post the question with your particular context at https://drupal.stackexchange.com.

denix’s picture

Ok, then this is the views block, working with no special permissions and showing images from the display_product, based on #1292104: Most popular products? .
You will have to edit something, but it should be a good base. EDITED taking into account this suggestion: #1276450: Views results empty for unprivileged user when using Relationship: Content: Referenced Product

$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['title'] = 'Bestsellers';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$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']['disable_sql_rewrite'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '4';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'views_bootstrap_grid_plugin_style';
$handler->display->display_options['style_options']['columns'] = '4';
$handler->display->display_options['row_plugin'] = 'fields';
/* 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;
/* Relationship: Commerce Product: Referencing Node */
$handler->display->display_options['relationships']['field_publication']['id'] = 'field_publication';
$handler->display->display_options['relationships']['field_publication']['table'] = 'commerce_product';
$handler->display->display_options['relationships']['field_publication']['field'] = 'field_publication';
$handler->display->display_options['relationships']['field_publication']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['relationships']['field_publication']['required'] = TRUE;
/* Field: Content: Product image */
$handler->display->display_options['fields']['field_prod_image']['id'] = 'field_prod_image';
$handler->display->display_options['fields']['field_prod_image']['table'] = 'field_data_field_prod_image';
$handler->display->display_options['fields']['field_prod_image']['field'] = 'field_prod_image';
$handler->display->display_options['fields']['field_prod_image']['relationship'] = 'field_publication';
$handler->display->display_options['fields']['field_prod_image']['label'] = '';
$handler->display->display_options['fields']['field_prod_image']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_prod_image']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_prod_image']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_prod_image']['type'] = 'file_rendered';
$handler->display->display_options['fields']['field_prod_image']['settings'] = array(
  'file_view_mode' => 'portrait_100x160',
  'field_formatter_class' => '',
);
$handler->display->display_options['fields']['field_prod_image']['group_column'] = 'entity_id';
/* Field: Content: Title */
$handler->display->display_options['fields']['title_1']['id'] = 'title_1';
$handler->display->display_options['fields']['title_1']['table'] = 'node';
$handler->display->display_options['fields']['title_1']['field'] = 'title';
$handler->display->display_options['fields']['title_1']['relationship'] = 'field_publication';
$handler->display->display_options['fields']['title_1']['label'] = '';
$handler->display->display_options['fields']['title_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['title_1']['element_label_colon'] = FALSE;
/* 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']['label'] = '';
$handler->display->display_options['fields']['sku']['exclude'] = TRUE;
$handler->display->display_options['fields']['sku']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['sku']['link_to_product'] = 0;
/* 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'] = '';
$handler->display->display_options['fields']['product_id']['exclude'] = TRUE;
$handler->display->display_options['fields']['product_id']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['product_id']['separator'] = '';
/* Field: Commerce Product: Price */
$handler->display->display_options['fields']['commerce_price']['id'] = 'commerce_price';
$handler->display->display_options['fields']['commerce_price']['table'] = 'field_data_commerce_price';
$handler->display->display_options['fields']['commerce_price']['field'] = 'commerce_price';
$handler->display->display_options['fields']['commerce_price']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['fields']['commerce_price']['label'] = '';
$handler->display->display_options['fields']['commerce_price']['exclude'] = TRUE;
$handler->display->display_options['fields']['commerce_price']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['commerce_price']['click_sort_column'] = 'amount';
$handler->display->display_options['fields']['commerce_price']['settings'] = array(
  'calculation' => '0',
  'field_formatter_class' => '',
);
$handler->display->display_options['fields']['commerce_price']['group_column'] = 'entity_id';
/* Field: Content: Publication */
$handler->display->display_options['fields']['field_publication']['id'] = 'field_publication';
$handler->display->display_options['fields']['field_publication']['table'] = 'field_data_field_publication';
$handler->display->display_options['fields']['field_publication']['field'] = 'field_publication';
$handler->display->display_options['fields']['field_publication']['relationship'] = 'field_publication';
$handler->display->display_options['fields']['field_publication']['label'] = '';
$handler->display->display_options['fields']['field_publication']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_publication']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_publication']['settings'] = array(
  'show_quantity' => 0,
  'default_quantity' => '1',
  'combine' => 1,
  'show_single_product_attributes' => 0,
  'line_item_type' => 'product',
  'field_formatter_class' => '',
);
$handler->display->display_options['fields']['field_publication']['delta_offset'] = '0';
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = '';
$handler->display->display_options['fields']['nothing']['alter']['text'] = '<div class="thumbnail">
     [field_prod_image]
      <div class="caption">
        <h4>[title_1]</h4>
        <div class="form-inline">
            <h4 class="form-group">[commerce_price]</h4>
            <div class="form-group">[field_publication]</div>
         </div>
      </div>
    </div>';
$handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
/* 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(
  'all' => 'all',
  'commerce_discount' => 'commerce_discount',
  'product_discount' => 'product_discount',
  '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(
  'all' => 'all',
  'product' => 'product',
  'publication' => 'publication',
);

/* Display: Bestsellers */
$handler = $view->new_display('block', 'Bestsellers', 'bestsellers');

PS: I output a bootstrap thumbnail format.