Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi,
I have one simple question: how to create a view, which shows most popular bought products?
I've tried many things, including looking at database fields and looks like this particular info is saved as a blob field type and might be not so easy to achieve this task...
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedNope, you have product IDs stored in the field data for line items. The gist of it is going to require a View of Orders joined to Line Items via the "Commerce Line Items relationship" joined to the Products via the "Referenced product" relationship. You can filter by Order State to only see purchased products and then count the occurrence of each Product ID to get the most referenced products. The hardest part will be establishing a relationship from the Product ID to the product display, but I believe you can use the reverse relationship from the product ID to a node referencing it so long as you only have a single product display per product.
Comment #2
amfis CreditAttribution: amfis commentedThanks for directions, will try!
Comment #4
brunorios1 CreditAttribution: brunorios1 commented"and then count the occurrence of each Product ID to get the most referenced products"
how can i do this?
thanks!
Comment #5
brunorios1 CreditAttribution: brunorios1 commentedComment #6
rszrama CreditAttribution: rszrama commentedLet's not reopen this old issue here. Your best bet would be to try a Views support channel, like #drupal-views in IRC. I don't actually know how you'd configure such a query through the UI, and it's a bit out of scope for the issue tracker for the Commerce project itself. I'm guessing you'll need some sort of a distinct query with some sort of computed field or aggregated count on the product ID, but that's really just a shot in the dark.
Comment #7
brunorios1 CreditAttribution: brunorios1 commentedsorry for reopened the issue...
actually, there is another method to build a block of "bestsellers" or "popular products"? this is very necessary for an e-commerce project!
thanks!
Comment #8
rszrama CreditAttribution: rszrama commentedThere may be a module doing it if you give it a search. You might also check drupalcommerce.org - there's a lot of discussion there about configuring Commerce sites and a directory of most available contribs.
Comment #9
Summit CreditAttribution: Summit commentedHi, this one is only on the node level I think: http://drupal.org/sandbox/anthonylindsay/1643068
But this one looks promissing by using radioactivity :) http://drupal.org/project/commerce_productpopularity.
Greetings, Martijn
Comment #10
tmsimont CreditAttribution: tmsimont commentedhere's a view export that show's product display title of most sold products... you might have to rework the machine names of the node display type and product type, but maybe this will help others.
Comment #11
Summit CreditAttribution: Summit commentedHi, thanks for showing your view. How could I show the ordertotal for the products?
greetings, Martijn
Comment #12
tmsimont CreditAttribution: tmsimont commentedIf you add in a field for product ID and set aggregation settings to "COUNT" that should show the number of products ordered.
Comment #13
Summit CreditAttribution: Summit commentedHi, I did exactly that..but the amounts shown are much to high....could it be that the view with product ID shows all products placed in basket, and not all ordered?
greetings, Martijn
Comment #14
tmsimont CreditAttribution: tmsimont commentedCould be yes -- it's probably a filter you need to set on the order status
Comment #14.0
tmsimont CreditAttribution: tmsimont commentededit
Comment #15
yogeshchaugule8 CreditAttribution: yogeshchaugule8 commented#10 worked great, thanks.
Addition to it, we can add "content:nid is not empty". This will help removing products from result which were sold but currently doesn't has any reference.
Few additions:
Comment #16
firstvoder CreditAttribution: firstvoder commentedhello,
Thx for this useful view. I tried it, but didnt get it to work so far. I guess its because of the machine names as tmsimont wrote. I dont mind playing more around with it to get it work, but i have a question before i spend more time on this.
does this require that all customers can see all orders in the permission settings? the view that i have right now (modified version of the line items view that came with commerce) requires this permission setting so im looking for a securer alternative.
i only found this on "view any product" and the security implication, https://drupal.org/node/1303194.
thx for any info on this.
Comment #17
ItangSanjana CreditAttribution: ItangSanjana commented@firstvoder
Ya I think so
CMIIW
Comment #18
jenlamptonI also had some trouble with the view provided above. Not only because the product types and names didn't match my site, but also because the COUNT was happening on a non-unique field. I have many products with the same titles, but they all still have unique IDs and SKUs, so either of those fields would be fine to use instead. Here is another version of the same view, this time with the COUNT happening on the product ID (which is unique).
In order to make this work for your own site, you'll need to import the view, then click on both filter criteria and adjust them for your own commerce site.
Comment #19
ItangSanjana CreditAttribution: ItangSanjana commented@jenlampton
Awesome, thanks for the export!
Comment #20
alifspb CreditAttribution: alifspb commentedhi thanks for share code its working good. i create block for this and i put sidebar second but after sing out from my admin account i cant see this in my block section i mean for anonymous user what wrong please help me ? i set in view
Access: Permission | View published content
but its now showing :( please help me find out this problem
thanks Advance
Comment #21
mitrpaka CreditAttribution: mitrpaka commentedAs already stated in #16 "view any product" permission is required. Additionally, in order to anonymous and logged users to see most popular products of all, "view any order" permission is required.
But please bare in mind possible security implications that may apply for above permissions, see https://drupal.org/node/1303194.
Comment #22
alifspb CreditAttribution: alifspb commented#21
thanks for your kind reply its save my tonssss time thanks again :)
Comment #23
kscheirerThanks jenlampton #18 worked great for me too. Seems like there's enough interest for this to be included in commerce or a contrib module. The view is not trivial to build from scratch and its pretty useful.
Comment #24
kristofferromJenLampton's view works for me too.
But can anyone give me a tip to have each product title link to a Product Display of the same title?
Comment #25
nourheine CreditAttribution: nourheine commentedthanks for this awsome view #18, that works for me
Comment #26
thronedigital CreditAttribution: thronedigital commentedHate to reopen a closed topic, but how would one do this with product display instead of product. I have an access control on product display that is a requirement in this view.
So really just need a similar idea, but with product displays instead.
Thank you,
- Dane
Comment #27
denix CreditAttribution: denix commentedDear all, Thanks for the export, which works great.
On the other hand, this views is more for administrative use, and it is not suited to be showed to the public because of the requested permissions and the absence of a link with the product display.
This is why I am reopening it and I hope to find a solution :) Thanks again!
Comment #28
rszrama CreditAttribution: rszrama at Centarro commentedSorry, we don't offer support for common configurations in this tracker. Your best bet is to post the question with your particular context at https://drupal.stackexchange.com.
Comment #29
denix CreditAttribution: denix commentedOk, then this is the views block, working with no special permissions and showing images from the display_product, based on #1292104: Most popular products? .
You will have to edit something, but it should be a good base. EDITED taking into account this suggestion: #1276450: Views results empty for unprivileged user when using Relationship: Content: Referenced Product
PS: I output a bootstrap thumbnail format.