? apachesolr_ubercart.patch
Index: apachesolr_ubercart.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr_ubercart/apachesolr_ubercart.info,v
retrieving revision 1.1
diff -u -p -r1.1 apachesolr_ubercart.info
--- apachesolr_ubercart.info	1 Aug 2008 19:12:39 -0000	1.1
+++ apachesolr_ubercart.info	4 Jun 2009 11:50:14 -0000
@@ -1,5 +1,13 @@
-; $Id: apachesolr_ubercart.info,v 1.1 2008/08/01 19:12:39 mikejoconnor Exp $
+; $Id: apachesolr.info,v 1.1.2.1.2.7 2009/03/20 04:11:16 pwolanin Exp $
 name = ApacheSolr Ubercart integration
 description = Integrates the ApacheSolr and Ubercart
-dependencies = uc_cart apachesolr
-package = ApacheSolr
+package = Apache Solr
+core = "6.x"
+php = 5.1.4
+
+; Information added by drupal.org packaging script on 2009-05-15
+version = "6.x-1.0-beta10"
+core = "6.x"
+project = "apachesolr_ubercart"
+datestamp = "1242401413"
+
Index: apachesolr_ubercart.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr_ubercart/apachesolr_ubercart.module,v
retrieving revision 1.1
diff -u -p -r1.1 apachesolr_ubercart.module
--- apachesolr_ubercart.module	1 Aug 2008 19:12:39 -0000	1.1
+++ apachesolr_ubercart.module	4 Jun 2009 11:50:14 -0000
@@ -9,15 +9,216 @@
 
 function apachesolr_ubercart_apachesolr_update_index(&$document, $node) {
   if (in_array($node->type, module_invoke_all('product_types'))) {
+
     if(!empty($node->model)) {
-      $document->ssfield_ubercart_sku = $node->model;
+      $document->ss_uc_sku = $node->model;
     }
     if (!empty($node->list_price)) {
-      $document->ssfield_ubercart_list_price = $node->list_price;
+      $document->fs_uc_list_price = $node->list_price;
     }
     if (!empty($node->sell_price)) {
-      $document->ssfield_ubercart_sell_price = $node->sell_price;
+      $document->fs_uc_sell_price = $node->sell_price;
+    }
+    if(!empty($node->weight)) {
+      $document->fs_uc_weight = $node->weight;
+    }
+    if(!empty($node->lenght)) {
+      $document->fs_uc_length = $node->length;
     }
+    if(!empty($node->width)) {
+      $document->fs_uc_width = $node->width;
+    }
+    if(!empty($node->height)) {
+      $document->fs_uc_height = $node->height;
+    }
+  }
+}
+
+function apachesolr_ubercart_apachesolr_facets() {
+  $facets = array();
+  //ubercart list prices
+  $facets['fs_uc_sell_price'] = array(
+    'info' => t('Apache Solr Search: Filter by Price (Selling price)'),
+    'facet_field' => 'fs_uc_sell_price',
+    'dividable' => TRUE,
+  );
+  $facets['fs_uc_list_price'] = array(
+    'info' => t('Apache Solr Search: Filter by Price (Listed price)'),
+    'facet_field' => 'fs_uc_list_price',
+    'dividable' => TRUE,
+  );
+  $facets['ss_uc_sku'] = array(
+    'info' => t('Apache Solr Search: Filter by Model)'),
+    'facet_field' => 'ss_uc_sku',
+  );
+  $facets['fs_uc_weight'] = array(
+    'info' => t('Apache Solr Search: Filter by weight'),
+    'facet_field' => 'fs_uc_weight',
+    'dividable' => TRUE,
+  );
+  $facets['fs_uc_length'] = array(
+    'info' => t('Apache Solr Search: Filter by length'),
+    'facet_field' => 'fs_uc_length',
+    'dividable' => TRUE,
+  );
+  $facets['fs_uc_width'] = array(
+    'info' => t('Apache Solr Search: Filter by width'),
+    'facet_field' => 'fs_uc_width',
+    'dividable' => TRUE,
+  );
+  $facets['fs_uc_height'] = array(
+    'info' => t('Apache Solr Search: Filter by height'),
+    'facet_field' => 'fs_uc_height',
+    'dividable' => TRUE,
+  );
+  return $facets;
+}
+
+/**
+ * Implementation of hook_block().
+ */
+function apachesolr_ubercart_block($op = 'list', $delta = 0, $edit = array()) {
+
+  switch ($op) {
+    case 'list':
+      $enabled_facets = apachesolr_get_enabled_facets('apachesolr_ubercart');
+      $facets = apachesolr_ubercart_apachesolr_facets();
+      // Add the blocks
+      $blocks = array();
+      foreach ($enabled_facets as $delta => $facet_field) {
+        if (isset($facets[$delta])) {
+          $blocks[$delta] = $facets[$delta] + array('cache' => BLOCK_CACHE_PER_PAGE,);
+        }
+      }
+      return $blocks;
+    case 'configure':
+      $facets = apachesolr_ubercart_apachesolr_facets();
+      $form = array();
+      if(array_key_exists($delta,$facets)) {
+        if($facets[$delta]['dividable']) {
+         $form['apachesolr_ubercart_division'] = array(
+           '#type' => 'textfield',
+           '#title' => t('The division of the price block (split all our prices by 20 for example'),
+           '#default_value' => variable_get('apachesolr_ubercart_division_'.$delta,20),
+         );
+        }
+      }
+      return $form;
+    case 'save':
+      $facets = apachesolr_ubercart_apachesolr_facets();
+      if(array_key_exists($delta,$facets)) {
+        if($facets[$delta]['dividable']) {
+          variable_set('apachesolr_ubercart_division_'.$delta, (int) $edit['apachesolr_ubercart_division']);
+        }
+      }
+      break;
+    case 'view':
+      if (apachesolr_has_searched()) {
+        // Get the query and response. Without these no blocks make sense.
+        $response = apachesolr_static_response_cache();
+        if (empty($response)) {
+          return;
+        }
+        $query = apachesolr_current_query();
+        $facets = apachesolr_get_enabled_facets('apachesolr_ubercart');
+        if (empty($facets[$delta]) && ($delta != 'currentsearch')) {
+          return;
+        }
+
+        // Get information needed by the taxonomy blocks about limits.
+        $initial_limits = variable_get('apachesolr_facet_query_initial_limits', array());
+        $limit_default = variable_get('apachesolr_facet_query_initial_limit_default', 10);
+        $division = variable_get('apachesolr_apachesolr_ubercart_division_'.$delta, 20);        
+        switch ($delta) {
+          case 'fs_uc_sell_price':
+            return apachesolr_ubercart_price_facet_block($response, $query, 'apachesolr_ubercart', $delta, $delta, t('Filter by price'),$division);
+          case 'fs_uc_list_price':
+            return apachesolr_ubercart_price_facet_block($response, $query, 'apachesolr_ubercart', $delta, $delta, t('Filter by price'),$division);
+          case 'ss_uc_sku':
+            return apachesolr_facet_block($response, $query, 'apachesolr_ubercart', $delta, $delta, t('Filter by product ID'));
+          case 'fs_uc_weight':
+            return apachesolr_ubercart_price_facet_block($response, $query, 'apachesolr_ubercart', $delta, $delta, t('Filter by weight'),$division);
+          case 'fs_uc_length':
+            return apachesolr_ubercart_price_facet_block($response, $query, 'apachesolr_ubercart', $delta, $delta, t('Filter by length'),$division);
+          case 'fs_uc_width':
+            return apachesolr_ubercart_price_facet_block($response, $query, 'apachesolr_ubercart', $delta, $delta, t('Filter by width'),$division);
+          case 'fs_uc_height':
+            return apachesolr_ubercart_price_facet_block($response, $query, 'apachesolr_ubercart', $delta, $delta, t('Filter by height'),$division);
+        }
+        break;
+      }
+      break;
   }
 }
 
+
+/**
+ * Helper function for displaying a facet block based on prices.
+ */
+function apachesolr_ubercart_price_facet_block($response, $query, $module, $delta, $facet_field, $filter_by, $division, $facet_callback = FALSE) {
+
+  if (!empty($response->facet_counts->facet_fields->$facet_field)) {
+    
+    $contains_active = FALSE;
+    $items = array();
+
+    if(!empty($response->facet_counts->facet_fields->$delta)) {
+      $links = array();
+      foreach($response->facet_counts->facet_fields->$delta as $price => $count){
+        
+        //we use intval to filter on our divisions
+        $divide  = intval($price/$division);
+        $links[$divide] += $count ;
+      }
+    }
+    
+    foreach($links as $price_range => $count) {
+      $sortpre = 1000000 - $count;
+      $options = array();
+      $exclude = FALSE;
+      $from_price = $price_range*$division;
+      $to_price = ($price_range*$division)+$division;
+      $facet_text = t('from @price_from to @price_to',array('@price_from'=>$from_price,'@price_to'=>$to_price));
+      $facet = '['.$from_price.' TO '.$to_price.']';
+      $unclick_link = '';
+      $active = FALSE;
+      $new_query = clone $query;
+      if ($query->has_filter($facet_field, $facet)) {
+        $contains_active = $active = TRUE;
+        // '*' sorts before all numbers.
+        $sortpre = '*';
+        $new_query->remove_filter($facet_field, $facet);
+        $path = $new_query->get_path();
+        $querystring = $new_query->get_url_querystring();
+        $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
+      } else {
+        $new_query->add_filter($facet_field, $facet, $exclude);
+        $path = $new_query->get_path();
+        $querystring = $new_query->get_url_querystring();
+      }
+      $items[$sortpre . '*' . $facet_text] = theme('apachesolr_facet_item', $facet_text, $count, $path, $querystring, $active, $unclick_link, $response->response->numFound, $options);
+    }
+    // Unless a facet is active only display 2 or more.
+    if ($items && ($response->response->numFound > 1 || $contains_active)) {
+      ksort($items, SORT_STRING);
+      // Get information needed by the rest of the blocks about limits.
+      $initial_limits = variable_get('apachesolr_facet_query_initial_limits', array());
+      $limit = isset($initial_limits[$module][$delta]) ? $initial_limits[$module][$delta] : variable_get('apachesolr_facet_query_initial_limit_default', 10);
+      $output = theme('apachesolr_facet_list', $items, $limit);
+      return array('subject' => $filter_by, 'content' => $output);
+    }
+
+  }
+  return NULL;
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function apachesolr_ubercart_theme() {
+  return array(
+    'apachesolr_ubercart_breadcrumb_fs_uc_sell_price' => array(
+      'arguments' => array('type' => 'test'),
+  ),
+  );
+}
