10 replies [Last post]
jorditr's picture
Offline
Getting busy with the Ubercode.
Joined: 10/31/2007
Juice: 256
Was this information Helpful?

Hi you all.

Is there any place where ubercart registers how many units have been sold of every product?

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Units sold of every product?

It is quite easy to do: have hook_order 'Update' && status == pendung and uc_balance($order)<=1 to ensure an order really is once stored. Then you you scan once again the products of the order and add each to by sql UPATE into the table uc_product_totals..

jorditr's picture
Offline
Getting busy with the Ubercode.
Joined: 10/31/2007
Juice: 256
It is not done?

Hi oslinux and thanks for your answer.

I don't have any uc_product_totals table on my database, what you answered me means that I should code that because it's not done? I mean, ubercart doesn't register anywhere how many units have been sold of every product to have a statistical control? I just ask that to be sure and doesn't repeat something which is already done Smiling

Shawn Conn's picture
Offline
Administrator
Joined: 08/07/2007
Juice: 916
hey jorditr, you'll be

hey jorditr,

you'll be happy to know that a reports module does exactly this. Not only does it keep track of how many of each product has sold, it also keeps track of how much have customers have purchased, and how much revenue your store has produced. You can get it from the latest bazaar update or you can get the separate contrib module if you're using a live site.

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

jorditr's picture
Offline
Getting busy with the Ubercode.
Joined: 10/31/2007
Juice: 256
Great module

Wow, I've installed it and it's really great Cool

I wanted to track some kind of sales results by product inside my customized Simple Stock Levels module, instead I've added the (customized) menus of the inventory managent to the Reports area on the Store Admin page. Please don't forget to keep your module updated Smiling

Thanks a lot.

jorditr's picture
Offline
Getting busy with the Ubercode.
Joined: 10/31/2007
Juice: 256
Easier way?

Hi oslinux for your answer. I installed the Shawn module and forgot to attend your proposal. I didn't understand it at first now I see you are saying to send that data to a new table still not created (uc_product_totals). Well, it's not a bad idea, but it's somewhat out of my scoop, since I just wanted to know if it was already registered somewhere to be able to read that data for a block of best sellers products I'm placing somewhere else. Uhmm, well, I'm trying to find another solution Smiling

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Easier way?

it is yet about 3 lines of php code like

<?php
global $user;

$result = db_query("SELECT * FROM uc_product_totals WHERE order_id_field_in_sql_table = %d", $arg1->order_id);
$rows = array();
$rows_max=count($result);

       while (

$row = db_fetch_object($result)) {
   
      
$the_total = $row->order_total;
      
// $row is the sql entry and -> field get you the field

       // if $row->uid is the user then you see if that user is maxed out already and
       // you stop the order by drupal_set_message("Sorry ". $user->name . "you have exceeded your 3 month limit, go home...", 'error');

     

} // end of while for each $row
       
?>

for sql table makeup uc_product_total

you need a field for the user_id, timestamp (when are 3 months over to delete it via cron), current_total.

<?php
function 3monthorsering_checker_order($op, $order, $status)  {

// when an order is submitted, see api hook order (better updated and pending and balance <=1) you try to update the uc_pridct table for this user, when no row affected, then you insert an new entry, else you update the current_total with the balance. Ok, if an order is canceld we need to reverse, but this is a different story

}
?>
jorditr's picture
Offline
Getting busy with the Ubercode.
Joined: 10/31/2007
Juice: 256
Re: Re: Easier way?

Hi oslinux and thanks for your proposal. Anyway, the only thing I dont't understand is that you insist on reading the table uc_product_totals which it's not present on my schema. Is it present on next release?

By now I'm working with that code:

      $sql2 = 'SELECT nd.nid, nd.title,
                  (SELECT SUM(op.qty)
                    FROM {uc_order_products} AS op
                    WHERE op.nid = nd.nid) AS sold
      FROM {node} AS nd
                WHERE nd.type IN ("'. implode('","', $product_types) .'")
                ORDER BY sold DESC
                  LIMIT '.$gridwidth;

which reads all the products inside orders and get the total quantity of each one. I've been thinking on considering if the orders where each one is completed or not but I'm not succeding on an internal join on the select sum, but maybe it's not important for a block which pretends to show the most sold products, we could consider the products inside orders still not completed as valid for such analysis.

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Re: Re: Easier way?

this toal table is made up ... I like to store results in case of crash or if an order does not fully go thru and all that ... If you manage it without, "great!" At least does it eventually work 4u now??

jorditr's picture
Offline
Getting busy with the Ubercode.
Joined: 10/31/2007
Juice: 256
Re: Re: Re: Re: Easier way?

Yes, it works thanks Smiling

firelion's picture
Offline
Joined: 12/02/2007
Juice: 2
oyun

bu oyunnu arkadaşım tavsiye etti