spree-contrib / spree_reviews

Straightforward review/rating functionality.

Home Page:http://spreecommerce.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Visitors and (some) users see nothing after "Write your own review"

nathanael2020 opened this issue · comments

Really like this extension. I'm wondering how I can add an explanatory sentence after visitors who aren't authorized to create reviews for a product click on the link... Currently it looks like a mostly blank page for unlogged visitors and even for some users.

I assume that the authorization logic checks to see whether the user is an admin or has previously purchased the product to allow them to post a review, but I don't know this for sure.

Thanks!

@nathanael2020 I'm pretty sure the criteria is just that the user is logged in. Not that they have purchased the item. If your interested in updating this behavior we would welcome any pull requests for review, but if you have a particular idea in mind for how everything should behave definitely open the discussion up before working on it.

I think the appropriate behavior would be to ask these users to log in or register. I'm trying to figure out how to make that happen in the reviews controller now. Sorry, not that familiar with spree's api.

I would prefer to see a redirect back to the review or product after registration or login, but in a pinch, this is better than displaying a blank page when users are not logged in:

diff --git a/app/controllers/spree/reviews_controller.rb b/app/controllers/spree/reviews_controller.rb
index 4862398..bb3d2cd 100644
--- a/app/controllers/spree/reviews_controller.rb
+++ b/app/controllers/spree/reviews_controller.rb
@@ -9,6 +9,7 @@ class Spree::ReviewsController < Spree::StoreController

   def new
     @review = Spree::Review.new(:product => @product)
+    return redirect_to spree.login_path if !spree_user_signed_in?
     authorize! :create, @review
   end

Why would you put this after the @review variable and not before it? You can also call store_location to store the location to redirect back. Please submit a pull request for this change.

I think you're correct, it's not necessary to place the line after @review. I think it's just my convention to do things like this after I've initialized data.

Doing it before the initialization will cause it to return sooner, freeing up server resources faster.

I think this has been resolved as I'm properly being redirected to unauthorized page. If this is still an issue please provide steps to reproduce in a new issue.