Hi
I have added this feature to the shop i am developing and I wanted to share it with you, maybe someone finds it useful
Ingredients
Drupal + Ubercart 
CRE module -> http://drupal.org/project/cre
VotingApi module -> http://www.drupal.org/project/votingapi
Workflow-NG module and UI activated -> http://drupal.org/project/workflow_ng
You will need to create a custom module (or use any "auxiliar" modules you have). The code uses workflow-ng & votingapi hooks. It creates an action and a block.
After creating and activating the module, you should create a new configuration from workflow-ng UI screen, with the event set to Customer completes checkout, with no condition and with the action defined by the module (for the example below 'Vote the items'), so whenever a customer completes the checkout, a custom vote is issued.
The block is restricted to show 5 elements by the db_query_range.
Then you activate the block in the block administer settings wherever you want it.
Here is the code
<?php
/**
* Implementation of hook_action_info().
*/
function customer_related_action_info(){
$actions = array();
$actions['customer_related_vote_item'] = array(
'#label' => t('Vote the items'),
'#arguments' => array(
'order' => array('#entity' => 'order', '#label' => t('Order')),
),
'#module' => t('Name of the module'),
);
return $actions;
}
function customer_related_vote_item ($order) {
$products = $order->products;
foreach ($products as $product) {
$votes->value = 1;
$votes->value_type = 'points';
$votes->tag = 'customer_related';
$test = votingapi_set_vote('product',$product->nid,$votes,$order->uid);
}
}
/**
* Hook block
*/
function customer_related_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Customers that bought this item also bought');
return $blocks;
case 'view':
$block['subject'] = t('Customers that bought this item also bought');
$block['content'] = _calculate_other_items();
break;
}
return $block;
}
function _calculate_other_items() {
$sql = "SELECT d.content_id1 as 'content_id',sum(d.sum+d.count*r.value)/sum(d.count) as 'score',n.title
FROM {cre_similarity_matrix} d,{votingapi_vote} r,{node} n
WHERE d.content_type1='product'
AND d.content_id1<>r.content_id
AND d.content_id2=r.content_id
AND n.nid=d.content_id1
AND r.tag = 'customer_related'
AND n.type = 'product'
AND n.nid<> %d
AND d.content_id2 = %d
GROUP BY d.content_id1 ORDER BY score DESC";
$result = db_query_range ($sql,arg(1),arg(1),0, 5);
$data_array = array();
while ($data = db_fetch_object($result)) {
$rows[] = array(l($data->title,'node/'.$data->content_id));
}
if (count($rows)) {
return theme('table', array(), $rows, array(), NULL);
}
else {
return NULL;
}
}Any comments or modifications are welcome!!!






Joined: 01/23/2008