Support Center

Drupal Commerce: Product Attributes & Variations

Last Updated: Apr 29, 2014 08:12PM EEST
Drupal Commerce https://drupal.org/project/commerce is used to build eCommerce websites and applications of all sizes based on Drupal.

The Pro and Enterprise releases of our Startup Growth, Mobile+, GenteelBest Brand, MarketSquare, Genteel and Top Hit products come bundled with Drupal Commerce providing you a turnkey e-commerce solution right after installation.

Product attributes are the descriptors we use to define kinds of products. For example, we could describe a t-shirt by the color and size. These attributes mean that in the real physical world your store may only carry one red shirt, but you have three sizes or three "variations." Drupal Commerce deals with product variations in a flexible way. Here's how Drupal Commerce abstracts it http://www.drupalcommerce.org/user-guide/product-attributes-variations.
 

Duplicated items when using Attributes & Variations

In many cases, when you create a view of products by adding a field for a referenced product (for example (Referenced Product) Commerce Product: Image or (Referenced Product) Commerce Product: Price), this view shows/results all the variations of each product display.

Regarding this behavior, check also these two articles https://drupal.org/node/1200536 and http://www.drupalcommerce.org/node/1028. There are many suggested solutions, especially this one with the Product reference field filter. In this case, please add a filter for the Product reference field and set the delta = 0. This will remove all the duplicated product displays.

The above solution will not work for you if you have in your installation a view which collects several content types, some of them may have not a field for a referenced product. You can use the hook_views_pre_execute() function in a custom module which adds a group by command to the SQL query which in turn eliminates all the duplicates based on the node ID. Please check the following module implementation:

Let’s name this module Commerce Views Grouping:

commerce_views_grouping.info
 
name = Commerce Views Grouping
description = Commerce Views Grouping
package = Commerce (contrib)
dependencies[] = views
dependencies[] = commerce
core = 7.x

commerce_views_grouping.module
 
<?php
function commerce_views_grouping_views_pre_execute(&$view) {
switch($view->name){
case
'YOURVIEWNAME':
$view->build_info['query']->groupBy('nid');
break;
}
}​
 

In case this article leaves any of your questions or concerns unanswered, please feel welcome to email us or post a public question.

​More than (just) Themes
http://www.morethanthemes.com/

Contact Us

[email protected]
http://assets3.desk.com/
false
morethanthemes
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete