Developer forum

Forum » Development » Check if user has ordered product

Check if user has ordered product

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

We have to build a functionality to allow posting product reviews only for users that have purchased the product.

What would be the most efficient way to check if the current user has a specific (current product) in his order history?

Thank you,
Adrian


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Adrian,

 

You can have a service page that uses the Macro of the Most Frequent or Most Bought products and that will give you the product Ids the user has purchased in the last 3 months.

 

Based on that you can show or hide the comments/reviews.

 

BTW, If your project is a Swift one, we have built 3 components to work with Products. New Comments, Comments list and Reviews, which you could then extend to adopt this logic.

 

Best Regards,

Nuno Aguiar

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nuno,

Thank you for the suggestions. The solution is an old Rapido with its fair share of customizations.

I was thinking more along the lines of the API rather than a front-end call.

I have found GetCustomerOrdersByType(Int32, String, OrderType, Int32, Boolean, String, DateTime, Boolean, Boolean) that could get me a list of POrders and I could eventually go over them and find the Products. But that seems like a complication. I was hoping there could be a better way to get all ordered products of a User or check if a product is in an order of a User.

On a separate note, I am interested to see your Swift components. It won't be very long until I will need something like that :)

Thank you,

Adrian

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Adrian,

 

Maybe you don't have a better workaround than that. What you can do is to store the distinct ProductIds in a session variable, so that you don't keep calling that method, which would be a performance concern (and then subscribe to an order complete notification to clear that session variable).

We've done similar things in the past (in Rapido) as well.

 

Regarding comments and ratings, I'm happy to show you. Because it's component based (and works with both Products and Articles), it does require a fair amount of files:

  • Update 5 files
    • Articles, Product Detail, Product Detail Component, Product List, Product List Component
  • 3 new Items/Components + their templates
    • Comment list
    • New Comment
    • Rating
  • Email notification templates
    • Reviewer email notification
    • Admin email notification
    • And maybe in the future we can convert to using System Emails - but this predates it
  • 1 css file
    • For Rate and rating related styles that do not ship in Swift
  • 2 js files
    • source + minified version
  • 2 svg files
    • Like + Dislike icons

 

So let me know when you want to see it and I'll show you. Or you can also reach out to Florin who had access to it in our SwiftRizzo dev environment.

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum