Skip to content

Instantly share code, notes, and snippets.

@abuisman
Created September 12, 2012 13:54
Show Gist options
  • Save abuisman/3706756 to your computer and use it in GitHub Desktop.
Save abuisman/3706756 to your computer and use it in GitHub Desktop.
Some implementation of 'customers who bought this also bought'
// Source: http://www.ubercart.org/contrib/2972
<?php
function RiffTrax_uc_cart_view_form($form) {
drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css');
$output = '<div id="cart-form-products">'
. tapir_get_table('uc_cart_view_table', $form) .'</div>';
if ((
$page = variable_get('uc_continue_shopping_url', '')) != '<none>') {
if (variable_get('uc_continue_shopping_type', 'link') == 'link') {
$continue_shopping_link = l(variable_get('uc_continue_shopping_text', t('Continue shopping')), $page);
}
else {
$continue_shopping_link = drupal_render($form['continue_shopping']);
}
}
$output .= '<div id="cart-form-buttons"><div id="cart-button-shopping">'
. $continue_shopping_link .'</div>'
. drupal_render($form) .'</div>';
$output .= '<div style="padding:8px;" id="cart-related-items">Customers who purchased the items in your shopping cart also bought:<br /> ';
$cartitems = uc_cart_get_contents();
$random = mt_rand(0, count($cartitems));
$random_item = $cartitems[$random];
$result = db_query("SELECT that.nid, that.title, COUNT(that.nid) AS frequency
FROM {uc_order_products} AS that
LEFT JOIN {uc_order_products} AS this
USING (order_id)
WHERE this.nid = %d AND that.nid != %d
GROUP BY that.nid
ORDER BY frequency DESC
LIMIT 5", $random_item->nid, $random_item->nid);
while ($upsell = db_fetch_object($result)) {
$image = db_result(db_query("SELECT field_image_cache_title FROM {content_field_image_cache} WHERE nid = %d", $upsell->nid));
$output .= '<div id="cart-related-item" style="padding:5px; width:18%; float:left; position: relative; text-align:center;"><a href="/'.drupal_get_path_alias("node/".$upsell->nid) .'">
<img src="/files/imagecache/thumbnail/files/'.$image.'"><br />
'.$upsell->title.'</a><br />';
//<a href="cart/add/i'.$upsell->nid.'Up-p'.$upsell->nid.'_q1?destination=cart"><strong>(Add to cart)</strong></a></div>';
}
$output .= '</div>';
return $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment