Thanks for this cool module. I will like to display the number of people who have bought a product on the product page just like in http://www.groupon.com/houston/
. How do I do that?
Thanks
Bmanuel

Comments

cayenne’s picture

Status: Active » Closed (works as designed)

Yeah, that might be an interesting block to add. For now, I just use a standard block with some PHP code. Here is the code I use to show who is signed up with what boat in a given item. You can modify with a COUNT query easily.

<?php 
  $node = node_load(arg(1));
   $query = "SELECT uco.order_status, ucop.nid, ucop.order_id, uco.billing_last_name, ucop.data FROM {uc_order_products} ucop JOIN {uc_orders} uco ON ucop.order_id = uco.order_id WHERE  ucop.nid = %d AND uco.order_status NOT IN ('in_checkout', 'canceled') ORDER BY ucop.order_id DESC";
   $result =db_query($query, $node->nid);
   $playa = array();

   print '<ul>';
   while ($row = db_fetch_object($result)) {
     print '<li>';
     $entry = unserialize($row->data);
     $variable= $entry['attributes']['Boat Name'];
     if(is_array($variable) == true){
       $val =ucwords(implode($variable));
     } else {
       $val =ucwords($boat);
     }
     if(strlen($val)>0) $playa['b'] = t('<b>' . $val . '</b>');
   
     $variable= $entry['attributes']['Boat Type'];
     if(is_array($variable) == true){
       $val =ucwords(implode($variable));
     } else {
       $val =ucwords($variable);
     }
     if(strlen($val)>0) $playa['t'] = t($val);


     $variable= $entry['attributes']['One Design Class'];
     if(is_array($variable) == true){
       $val =ucwords(implode($variable));
     } else {
       $val =ucwords($variable);
     }
     if(strlen($val)>0) $playa['c'] = t($val);

     $variable= $entry['attributes']['Skipper Name'];
     if(is_array($variable) == true){
       $val =ucwords(implode($variable));
     } else {
       $val =ucwords($variable);
     }
     if(strlen($val)>0) 
      {$playa['s'] = t('<i>' . $val . '</i>');}
    else {
      {$playa['s'] = t('<i>' . $row->billing_last_name . '</i>');}
    }

    
    $mystr = implode($playa,' - ');
    if (strlen($mystr)>1) print $mystr;
  
   }


print '</ul>';
?>
cayenne’s picture

For your purposes. something like this:

<?php 
  $node = node_load(arg(1));
   $query = "SELECT SUM(ucop.quantity) as myCount FROM {uc_order_products} ucop JOIN {uc_orders} uco ON ucop.order_id = uco.order_id WHERE  ucop.nid = %d AND uco.order_status NOT IN ('in_checkout', 'canceled')";
   $result =db_query($query, $node->nid);
   $playa = array();

 $row = db_fetch_object($result);
 $buys = ($row->myCount;
 print $buys . " of these thingies sold."  ;
    
?>
kayusee’s picture

Thanks for the code. Please where does this code go in the module?

cayenne’s picture

Paste that into a block with the PHP option set as the input format.

BManuel’s picture

thanks guys :)

kayusee’s picture

Thank you for your response. I went into admin > Blocks > Add Block and created a new block and inserted the code in the PAGES field and checked "Show if the following PHP code returns TRUE (PHP-mode, experts only)". While the block showed on the front page, with block title and block body, nothing else shows up for number of buys on the block, after I made a test purchase on a product. Did I miss something? Please help.

ricesteam’s picture

Just tried the above two code snippets in a new block and like kayusee, it does not work.

Does not display anything.