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.
Comment | File | Size | Author |
---|---|---|---|
#27 | 1339910-popular-products-view.patch | 3.88 KB | longwave |
#23 | ubercart-views-popular-page.txt | 6.07 KB | ericwongcm |
#22 | ubercart-views-popular-block.txt | 3.61 KB | ericwongcm |
#18 | uc_order_products.sql_.gz | 1.13 KB | ericwongcm |
#13 | uc_popular_products.view_.txt | 5.82 KB | dvasquez |
Comments
Comment #1
daroz CreditAttribution: daroz commentedSimple example view attached.
Comment #2
longwaveI 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?
Comment #3
longwaveThis perhaps needs work to only include certain order statuses, as it will be unreliable if it includes "in checkout" orders.
Comment #4
daroz CreditAttribution: daroz commentedI'll test this out after I recover from my tryptophan hangover -- thanks!
Comment #5
daroz CreditAttribution: daroz commentedI'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.
Comment #6
daroz CreditAttribution: daroz commentedOk, 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.
Comment #7
longwaveComment #8
longwavePerhaps 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.
Comment #9
carl_adriano CreditAttribution: carl_adriano commentedhow can i add image to field views? btw good job on this page :)
Comment #10
Stealth CreditAttribution: Stealth commentedHow would you add images to popular products? Please advise.
Comment #11
stoan CreditAttribution: stoan commentedHi, I'm also looking to add an image field and a taxonomy field. Thanks
Comment #12
remkovdz CreditAttribution: remkovdz commentedAt the moment, is this the best way to build a "Most popular" block?
Comment #13
dvasquez CreditAttribution: dvasquez commentedHello 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.
Comment #14
dvasquez CreditAttribution: dvasquez commentedhttps://drupal.org/node/1339910#comment-7834479
Comment #15
ericwongcm CreditAttribution: ericwongcm commentedre: 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.
Comment #16
dvasquez CreditAttribution: dvasquez commentedLet 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.
Comment #17
ericwongcm CreditAttribution: ericwongcm commentedI 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.
Comment #18
ericwongcm CreditAttribution: ericwongcm commentedForgot to attach my uc_order_products table.
Here it is..
Comment #19
dvasquez CreditAttribution: dvasquez commentedOk, 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.
Comment #20
ericwongcm CreditAttribution: ericwongcm commentedEven 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.
Comment #21
dvasquez CreditAttribution: dvasquez commentedTry check in Query Options check Unic, not Pure Distinct, only for unic(s) and letme know.
Comment #22
ericwongcm CreditAttribution: ericwongcm commentedRe: 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.
Comment #23
ericwongcm CreditAttribution: ericwongcm commentedAttached 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.
Comment #24
dvasquez CreditAttribution: dvasquez commentedCongrats.
All is conected!
Comment #25
TR CreditAttribution: TR commented@hdmp4.com: Can you provide a patch?
Comment #26
ericwongcm CreditAttribution: ericwongcm commented#25, you just need to import the view. No patch needed.
Comment #27
longwaveI 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.
Comment #28
SilviuChingaru CreditAttribution: SilviuChingaru commentedI 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.
Comment #29
TR CreditAttribution: TR commented"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.
Comment #30
dvasquez CreditAttribution: dvasquez commentedAfter last ubercart update the view not runs... Any idea of the break?
Thanks!
Comment #31
TR CreditAttribution: TR commented27: 1339910-popular-products-view.patch queued for re-testing.
Comment #33
g089h515r806 CreditAttribution: g089h515r806 commentedI have imported the view, it works.
Comment #35
ghubika CreditAttribution: ghubika as a volunteer commentedHey! 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