Ok, even though I barely know how Drupal works, I managed to throw together a module that accomplishes this task. There are still some kinks; however, this code is working pretty much as expected from my minimal testing. To use this, create a taxonomy with your colors or prints, then add the field to your product variation type. Once that is completed, go to Configuration-> Search API-> [your search index]-> Fields and make sure that your product variations >> print or color field is added to the index. Once that is completed, go to the facets tab and enable your product variations >> print or color. Once you have completed this, go and enable the block in whichever region you would like. To see this module's effect, add an image to each product variation and select the appropriate print or color from your print or color taxonomy field. You should now be ready to apply this very rough module.
<?php
function search_results_custom_theme() {
$theme = array();
$theme['node--product--type--product--list'] = array(
'render element' => 'node',
'template' => '/profiles/commerce_kickstart/modules/commerce_kickstart/commerce_kickstart_product_ui/theme',
);
return $theme;
}
function search_results_custom_preprocess_node(&$variables){
$searcher = <strong>'[email protected]_display';</strong> // your server id
$facetApiAdapter = facetapi_adapter_load($searcher);
$activeItems = $facetApiAdapter->getAllActiveItems();
$node_products=$variables['node']->field_product['und'];
if($activeItems){
foreach($node_products as $node_product){
$product_id=$node_product['product_id'];
$product=commerce_product_load($product_id);
if($product-><strong>field_print</strong>['und'][0]['tid']==reset($activeItems)['value']){
if($product-><strong>field_images</strong>['und'][0]['uri']){
$variables['content']['<strong>product:field_images</strong>'][0]['#item']['uri']=$product-><strong>field_images</strong>['und'][0]['uri'];
$variables['content']['product:field_images'][0]['#item']['filename']=$product-><strong>field_images<strong>['und'][0]['filename'];
}
}
}
}
}
?>
I have put emphasis on the specific field names that will need to be changed (to match the machine names of your fields) in order for this module to work.
"field_print" is the machine name of my print taxonomy that I use to tag each product variation.
"field_images" is the machine name of my image field on my variation types.
"[email protected]_display" is the machine name for my search server id (I found this in the database under that facetapi table).
To apply this, use ftp or some kind of file manager and go to the root directory, then navigate to sites->all->modules and create a directory (name it whatever you want). Then create a .module file with the above code in it and then another .info file with the following:
name = Search Results Custom
description = "Provides customized search results"
package = Search
core = 7.x
dependencies[] = facetapi
dependencies[] = search_api
dependencies[] = search_api_facetapi
version = "7.x-1.x-dev"
core = "7.x"
project = "Search Results Custom"
datestamp = "1380626876"
I know that this module is probably very inefficient and hackish, but I'm not really a programmer and this was the best I could come up with in a few days. Hopefully a similar feature can be added in to the drupal commerce search core.
Hope this helps somebody =)
Comments
Djames24, I am having the exact same issue. I would be very interested if you or someone else had a solution.
Thanks!