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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

daroz’s picture

Simple example view attached.

longwave’s picture

Title: Some Product fields missing with Views when trying to create a "Popular Product" view » Add "Popular Products" view
Component: Products » Module integration
Category: support » feature
Status: Active » Needs review
FileSize
7.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?

longwave’s picture

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

daroz’s picture

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

daroz’s picture

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.

daroz’s picture

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.

longwave’s picture

Status: Needs review » Needs work
longwave’s picture

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.

carl_adriano’s picture

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

Stealth’s picture

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

stoan’s picture

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

remkovdz’s picture

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

dvasquez’s picture

Version: 7.x-3.x-dev » 7.x-3.4
Component: Module integration » Code
Status: Needs work » Needs review
FileSize
5.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.

dvasquez’s picture

ericwongcm’s picture

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.

dvasquez’s picture

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.

ericwongcm’s picture

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.

ericwongcm’s picture

FileSize
1.13 KB

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

dvasquez’s picture

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.

ericwongcm’s picture

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.

dvasquez’s picture

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

ericwongcm’s picture

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.

ericwongcm’s picture

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.

dvasquez’s picture

Congrats.
All is conected!

TR’s picture

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

@hdmp4.com: Can you provide a patch?

ericwongcm’s picture

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

longwave’s picture

Component: Code » Products
Status: Active » Needs review
FileSize
3.88 KB

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.

SilviuChingaru’s picture

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.

TR’s picture

"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.

dvasquez’s picture

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

TR’s picture

Status: Needs review » Needs work

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

g089h515r806’s picture

I have imported the view, it works.

Status: Needs work » Needs review
ghubika’s picture

Issue summary: View changes

Hey! Dunno, if anyone still looking at this thread, but I imported the block view, but it only displays one product for me, any idea why that could be?

Thnaks