uc_best_sellers

Contrib type: 
Module
Status: 
Initial upload
Moderation: 
Awaiting moderation

Downloads

Compatibility: 
Ubercart 2.x

uc_best_sellers keeps track of how many times a product has sold. This is primarily useful for providing a block to display best sellers (that's why I wrote it, anyway).

Order count is maintained in a separate table along with the nid of the associated product. It's not model-specific at this point, it's only useful for tracking the number of times a product's primary SKU has sold. It's integrated with a CA hook that fires when an order is finalized and submitted. The count sold is incremented for each line item in the order based on the quantity purchased.

The module provides a views field that you can use to sort products by "Sold Count". It's a regular views field, so I suppose you could use it for other things (products that have sold more than 100 times, or something), but I use it for just sorting out best sellers.

It also hooks in with nodeapi to add the sold_count field to product nodes, so you could display it in your template files if you want.

When you install the module it sums up the sold count for each product in the uc_order_product table, so it will calculate the correct number of times each product has sold in the past.

Comments are appreciated, and I hope this helps someone!

PreviewAttachmentSize
uc_best_sellers.zip6.08 KB
nickh's picture
Offline
Joined: 04/28/2010
Juice: 3
Adding a primary key

Hi,

I found that I had to add a primary key to the best sellers table when I had a large number of products.. I've attached a patch in case it is helpful for anyone else having performance issues..

Thanks
Nick.

AttachmentSize
add_primary_key_patch.txt 548 bytes
m4olivei's picture
Offline
Joined: 10/05/2010
Juice: 15
Found a couple other issues

Hey,

Thanks for the module and for the patch. I ran into another couple issues myself. First I found that the sold_count column was only ever being updated for existing products. What that meant was that if you added a product after installing uc_best_sellers, that products sold_count would never be recorded. I updated that to query to see if a row exists for the product sold, if so update, otherwise insert.

Also the query to set the sold_count for existing products on install was counting products that were not sold yet. You need to include the uc_orders table and filter by order_status = 'complete' to get the right numbers for products that were actually sold, so I ended up with a query like:

SELECT COUNT(nid) as sold_count, nid
FROM uc_order_products op
INNER JOIN uc_orders o ON op.order_id = o.order_id
WHERE order_status = 'completed' GROUP BY nid

Also, I updated the code formatting to fit Drupal standards. I've attached an updated zip package of the entire module which includes the above patch.

Thanks,
Matt

AttachmentSize
uc_best_sellers.zip 3.62 KB
ronnoc's picture
Offline
Joined: 04/13/2011
Juice: 19
Items shown are not correct

Hello. Thanks for the module and the patches. I installed the last attachment, and installed the view on my website (www.ccjdmotorsports.com). The issue is, none of the products shown are products that have sold much (comparatively). In fact, a few have never sold, and a few that have sold much are not shown at all. Any ideas on how I should go about tracking the reason down?

Thanks in advance for your responses, and again for this important module.

- James