After slamming my head into this for too many hours, I'm opening this as a support request, mainly because I'm not sure if it a) is a bug, or b) is with Views or Ubercart.

Short version: One should be able to create a view that lists the x most popular products (popular = most ordered in this case) in a store and be able to have access to all the fields (current price, image, etc). However, once you create the view (based on orders), add grouping, and the product relationship, there's no way to add the current product price or image into the view.

Either way, views problem, or Ubercart problem, this is a *very* common usage situation for any ecommerce site and there should be a way to do this.... I'm just not seeing it.

Comments

StatusFileSize
new5.42 KB

Simple example view attached.

Title:Some Product fields missing with Views when trying to create a "Popular Product" viewAdd "Popular Products" view
Component:Products» Module integration
Category:support» feature
Status:Active» Needs review
StatusFileSize
new7.63 KB

I added product fields to the view, and also added "ordered products" as a base table so you can use that instead of orders with a relationship. Commit: http://drupalcode.org/project/ubercart.git/commitdiff/1afc6ce

The attached view seems to work for me; perhaps we should add this as a default view to core, so people can show a "best sellers" block easily?

This perhaps needs work to only include certain order statuses, as it will be unreliable if it includes "in checkout" orders.

I'll test this out after I recover from my tryptophan hangover -- thanks!

I'm getting some errors thrown... I think it's a SQL or aggregation problem, still looking into it but...

It won't let me add any product images to the table.... Not sure if that's going to be a views aggregation problem, or a CCK field problem, or an ubercart problem.

Ok, I did track down some errors with the view.... If you have a popular product for whom the product node was deleted, the SQL query generated will return NULL values for the nid (due to the left join). Adding a filter to require Content:nid > 0 solves the errors.

Status:Needs review» Needs work

Perhaps the view should be of content (nodes), with a left join relationship to ordered products, which should avoid this. That might also be necessary for proper access control if some stores restrict access to certain products. This would hopefully also neatly solve the images problem.

how can i add image to field views? btw good job on this page :)

How would you add images to popular products? Please advise.

Hi, I'm also looking to add an image field and a taxonomy field. Thanks

At the moment, is this the best way to build a "Most popular" block?

Version:7.x-3.x-dev» 7.x-3.4
Component:Module integration» Code
Status:Needs work» Needs review
StatusFileSize
new5.82 KB

Hello Guys, this is my view, whit it i can view Ubercart images and sort the products asc or desc about how much has been purchased a product. Ovbiusly you can modify the filters about order status or other things.

If you can review it... i think it needs review.

re: 13, I tried your view but it seems to have some problems...
I have two product in my test site and only one of them is showing.

The product that is shown using your view have no purchases made against it whereas the missing product have purchases made.

The view by #2 shows both of my products.

Let me see tour uc_order_products table in your DB.
Review the field qty in your uc_order_product isn't empty. Remember, these are purchased products, if the product is not purchased the qty field is empty.

I'm ready for help.

I think this maybe related to other modules or settings I am also using.
I am using https://drupal.org/project/uc_product_minmax
And I have configured the product to make purchases in minimum of x number of item in multiples of x.

If I use your code directly, it shows both of my product but I see 4 rows, 3 of them are repeat of the same product.

After I remove the "field: Ordered product: Quantity"
It only shows one row (one product), the product that have no purchases made.

StatusFileSize
new1.13 KB

Forgot to attach my uc_order_products table.
Here it is..

Ok, you uc order products says you have purchased the product of nid = 3, 46 times, and the product of nid = 1 2 times. If you have only 2 products the view must display only 2 products. But, if you filter the view for orders status "complete", you'll get the correct result. May be your only complete orders are one or two.

Even if I remove the filter, I only see one product (the elephant) and it has not received any orders!! So, something is wrong with the code.

Try check in Query Options check Unic, not Pure Distinct, only for unic(s) and letme know.

StatusFileSize
new3.61 KB

Re: dvasquez
Found the problem, as you said it is related those advanced settings you configured.
Looking at your advanced settings, I finally know how you managed to add the image field as an one of the display fields.

I have modified the original view in #2 by adding "Ordered product: Node" relationship and it seems to work the way I need.

Attached is the block view.

StatusFileSize
new6.07 KB

Attached here is a page version of the same view.
I have to make them separately due to the different view format used in block and page.

Feel free to modify it to suit your needs.

Congrats.
All is conected!

Version:7.x-3.4» 7.x-3.x-dev
Status:Needs review» Active

@hdmp4.com: Can you provide a patch?

#25, you just need to import the view. No patch needed.

Component:Code» Products
Status:Active» Needs review
StatusFileSize
new3.88 KB
FAILED: [[SimpleTest]]: [MySQL] 2,944 pass(es), 1 fail(s), and 3 exception(s).
[ View ]

I imported and simplified #22. This patch adds a default block view of the top 5 product titles only, filtered for published products that are in "payment received" or "completed" orders only. This is a deliberately simple starting point, which avoids problems with the product image field where sites have modified or don't use the default - it's simple enough to re-add the image or any other fields.

I think it will not work with products with imagefield containing more than one image (it will display duplicates of the product for number of images - the same for any multivalue field). This should be tested before comitting.

"No patch needed."

Don't be ridiculous. Of course we need a patch if this is going to be put into Ubercart. That's why I asked for it.

Please test longwave's patch in #27 if you would like to see this feature added to Ubercart.

After last ubercart update the view not runs... Any idea of the break?
Thanks!

Status:Needs review» Needs work

The last submitted patch, 27: 1339910-popular-products-view.patch, failed testing.

I have imported the view, it works.