From 25c967e40a9e61e03e73401f3354244711a21149 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Thu, 20 May 2021 23:25:06 +0500 Subject: [PATCH 01/15] fix(review): remove admin aproval in average --- app/controllers/spree/reviews_controller.rb | 2 +- app/models/spree/product_decorator.rb | 6 ++++-- app/models/spree/review.rb | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/spree/reviews_controller.rb b/app/controllers/spree/reviews_controller.rb index 1ee8e2e3..e51b09ab 100644 --- a/app/controllers/spree/reviews_controller.rb +++ b/app/controllers/spree/reviews_controller.rb @@ -39,7 +39,7 @@ def load_product end def permitted_review_attributes - [:rating, :title, :review, :name, :show_identifier] + [:rating, :title, :review, :name, :show_identifier, :product_worth, :product_recommend, :vendor_recommend] end def review_params diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 0fb8a6ab..6ed0bdb2 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -9,10 +9,12 @@ def stars avg_rating.try(:round) || 0 end + + def recalculate_rating - self[:reviews_count] = reviews.reload.approved.count + self[:reviews_count] = reviews.count self[:avg_rating] = if reviews_count > 0 - reviews.approved.sum(:rating).to_f / reviews_count + reviews.sum(:rating).to_f / reviews_count else 0 end diff --git a/app/models/spree/review.rb b/app/models/spree/review.rb index 98398992..bb37e09c 100644 --- a/app/models/spree/review.rb +++ b/app/models/spree/review.rb @@ -3,7 +3,7 @@ class Spree::Review < ActiveRecord::Base belongs_to :user, class_name: Spree.user_class.to_s has_many :feedback_reviews - after_save :recalculate_product_rating, if: :approved? + after_save :recalculate_product_rating after_destroy :recalculate_product_rating validates :name, :review, presence: true @@ -13,7 +13,6 @@ class Spree::Review < ActiveRecord::Base less_than_or_equal_to: 5, message: Spree.t(:you_must_enter_value_for_rating) } - default_scope { order('spree_reviews.created_at DESC') } scope :localized, ->(lc) { where('spree_reviews.locale = ?', lc) } From 9bb4a94aa91069448f86b833eede3691356fd5fb Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 16:58:00 +0500 Subject: [PATCH 02/15] feat(reviews): add enums --- app/models/spree/review.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/spree/review.rb b/app/models/spree/review.rb index bb37e09c..dd2e5aa6 100644 --- a/app/models/spree/review.rb +++ b/app/models/spree/review.rb @@ -22,6 +22,15 @@ class Spree::Review < ActiveRecord::Base scope :approved, -> { where(approved: true) } scope :not_approved, -> { where(approved: false) } scope :default_approval_filter, -> { Spree::Reviews::Config[:include_unapproved_reviews] ? all : approved } + scope :raiting_five, -> { where(rating: '5').count } + scope :raiting_four, -> { where(rating: '4').count } + scope :raiting_three, -> { where(rating: '3').count } + scope :raiting_two, -> { where(rating: '2').count } + scope :raiting_one, -> { where(rating: '1').count } + + enum product_worth: %i[yes no dont_know], _prefix: :product_worth + enum product_recommend: %i[yes no dont_know], _prefix: :product_recommend + enum vendor_recommend: %i[yes no dont_know], _prefix: :vendor_recommend def feedback_stars return 0 if feedback_reviews.size <= 0 From 8962888288871f995b79639897fcef94faae863e Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 17:38:44 +0500 Subject: [PATCH 03/15] fix(design): add new review modala and update design --- app/views/spree/reviews/_form.html.erb | 77 ++++++++++++------- app/views/spree/reviews/index.html.erb | 6 +- .../shared/_product_added_modal.html.erb | 25 ++++++ app/views/spree/shared/_rating.html.erb | 69 ++++++++++++++--- app/views/spree/shared/_review.html.erb | 28 +++---- app/views/spree/shared/_reviews.html.erb | 17 ++-- config/locales/en.yml | 4 +- 7 files changed, 160 insertions(+), 66 deletions(-) create mode 100644 app/views/spree/shared/_product_added_modal.html.erb diff --git a/app/views/spree/reviews/_form.html.erb b/app/views/spree/reviews/_form.html.erb index a84e152e..6b1c0959 100644 --- a/app/views/spree/reviews/_form.html.erb +++ b/app/views/spree/reviews/_form.html.erb @@ -1,38 +1,59 @@ <%= form_for review, url: product_reviews_path(product), html: { method: :post } do |f| %> - <%= render 'spree/shared/error_messages', target: review %> + <%= render 'spree/shared/error_messages', target: review %> -
- <%= f.label :rating %> - <%= render 'spree/reviews/stars', stars: review.rating, edit_enabled: true %> -
+
+ <%= f.label :rating %> + <%= render 'spree/reviews/stars', stars: review.rating, edit_enabled: true %> +
+ +
+ <%= f.label :name %> + <%= f.text_field :name, maxlength: 255, size: 50, class: 'form-control', required: true %> +
+ +
+ <%= f.label :title %> + <%= f.text_field :title, maxlength: 255, size: 50, class: 'form-control' %> +
-
- <%= f.label :name %> - <%= f.text_field :name, maxlength: 255, size: 50, class: 'form-control', required: true %> +
+ <%= f.label :review %> + <%= f.text_area :review, wrap: 'virtual', rows: 4, cols: 50, class: 'form-control', required: true %> +
+ +
+

Is this product worth?

+ <%= f.radio_button :product_worth, "yes", style: "display:none" %> YES + <%= f.radio_button :product_worth, "no", style: "display:none" %> NO + <%= f.radio_button :product_worth, "dont_know", style: "display:none" %> Don't know
-
- <%= f.label :title %> - <%= f.text_field :title, maxlength: 255, size: 50, class: 'form-control' %> +
+

Do you recommend this product?

+ <%= f.radio_button :product_recommend, "yes", style: "display:none" %> YES + <%= f.radio_button :product_recommend, "no", style: "display:none" %> NO + <%= f.radio_button :product_recommend, "dont_know", style: "display:none" %> Don't know
-
- <%= f.label :review %> - <%= f.text_area :review, wrap: 'virtual', rows: 10, cols: 50, class: 'form-control', required: true %> +
+

Was the experience with the vendor good?

+ <%= f.radio_button :vendor_recommend, "yes", style: "display:none" %> YES + <%= f.radio_button :vendor_recommend, "no", style: "display:none" %> NO + <%= f.radio_button :vendor_recommend, "dont_know", style: "display:none" %> Don't know
- <% if Spree::Reviews::Config[:show_identifier] %> -
- <%= f.label :show_identifier do %> - <%= f.check_box :show_identifier, checked: true %> - <%= Spree::Review.human_attribute_name(:show_identifier) %> - <% end %> -
- <% end %> + <% if Spree::Reviews::Config[:show_identifier] %> +
+ <%= f.label :show_identifier do %> + <%= f.check_box :show_identifier, checked: true %> + <%= Spree::Review.human_attribute_name(:show_identifier) %> + <% end %> +
+ <% end %> -
- <%= f.submit Spree.t(:submit_your_review), class: 'btn btn-primary' %> - <%= Spree.t(:or) %> - <%= link_to Spree.t(:cancel), product_path(@product), class: 'btn btn-outline-primary', rel: 'nofollow' %> -
-<% end %> +
+ <%= f.submit Spree.t(:submit_your_review), class: 'btn btn-primary' %> + <%= Spree.t(:or) %> + <%= link_to Spree.t(:cancel), product_path(@product), class: 'btn btn-outline-primary', rel: 'nofollow' %> +
+ <% end %> \ No newline at end of file diff --git a/app/views/spree/reviews/index.html.erb b/app/views/spree/reviews/index.html.erb index ebc10a60..df2abfc1 100644 --- a/app/views/spree/reviews/index.html.erb +++ b/app/views/spree/reviews/index.html.erb @@ -1,7 +1,7 @@
-

<%= Spree.t(:reviews) %>

+

<%= Spree.t(:reviews) %>

<% if Spree::Reviews::Config[:include_unapproved_reviews] == false and @product.reviews.approved.count == 0 %>

<%= Spree.t(:no_reviews_available) %>

<% else %> @@ -15,11 +15,9 @@ <%= render 'spree/shared/review', review: review %> <% end %> <% end %> - <%= link_to Spree.t(:write_your_own_review), new_product_review_path(@product), class: 'btn btn-primary', rel: 'nofollow' %> <%= Spree.t(:or) %> <%= link_to Spree.t(:back_to) + " " +@product.name, product_path(@product), class: 'btn btn-outline-primary', rel: 'nofollow' %> - <% if Spree.version.to_f < 4.0 %> <% if @approved_reviews.respond_to?(:total_pages) %>
@@ -40,4 +38,4 @@ <% end %>
-
+
\ No newline at end of file diff --git a/app/views/spree/shared/_product_added_modal.html.erb b/app/views/spree/shared/_product_added_modal.html.erb new file mode 100644 index 00000000..fa0eca02 --- /dev/null +++ b/app/views/spree/shared/_product_added_modal.html.erb @@ -0,0 +1,25 @@ +<% @review = Spree::Review.new(product: @product) %> + diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index 619d1158..0a7b4ea6 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -1,15 +1,66 @@ -<% stars = product.stars %> -<% reviews_count = product.reviews_count %> +<% stars = @product.stars %> +<% reviews_count = product.reviews_count %> +<% raiting_five = product.reviews.raiting_five * 100 /reviews_count %> +<% raiting_four = product.reviews.raiting_four * 100 /reviews_count %> +<% raiting_three = product.reviews.raiting_three * 100 /reviews_count %> +<% raiting_two = product.reviews.raiting_two * 100 /reviews_count %> +<% raiting_one = product.reviews.raiting_one * 100 /reviews_count %>
-

<%= Spree.t(:average_customer_rating) %>:

-

- - <%= render 'spree/reviews/stars', stars: stars %> - +

+ Let us know your thoughts on a product or view reviews from our members, + independent experts and other websites.

-

(<%= Spree.t(:based_upon_review_count, count: reviews_count) %>)

+
+

+ <%= @product.stars %> + + <%= render 'spree/reviews/stars', stars: stars %> + +

+
+

<%= Spree.t(:based_upon_review_count, count: reviews_count) %>

+ +
+
+

5

+
+
+
+

<%= raiting_five %>%

+
+
+

4

+
+
+
+

<%= raiting_four %>%

+
+
+

3

+
+
+
+

<%= raiting_three %>%

+
+
+

2

+
+
+
+

<%= raiting_two %>%

+
+
+

1

+
+
+
+

<%= raiting_one %>%

+
+
+ +
-
+
\ No newline at end of file diff --git a/app/views/spree/shared/_review.html.erb b/app/views/spree/shared/_review.html.erb index 7350a620..c0fef422 100644 --- a/app/views/spree/shared/_review.html.erb +++ b/app/views/spree/shared/_review.html.erb @@ -1,11 +1,21 @@ -
+
<%= render 'spree/reviews/stars', stars: review.rating %> - <%= review.title %>
- <%= Spree.t(:submitted_on) %> - <%= l review.created_at.to_date %> + <%= review.title %> +
+
+

<%= review.review %>

+
+ <% if Spree::Reviews::Config[:feedback_rating] && (!Spree::Reviews::Config[:require_login] || spree_current_user) %> + + <% end %> + + <%#= Spree.t(:submitted_on) %> + <%= l review.created_at.to_date %> @@ -13,17 +23,9 @@ <% if Spree::Reviews::Config[:show_email] && review.user %> <% else %> - + <% end %> <% else %> <% end %> -
- <%= simple_format(review.review) %> -
- <% if Spree::Reviews::Config[:feedback_rating] && (!Spree::Reviews::Config[:require_login] || spree_current_user) %> - - <% end %>
diff --git a/app/views/spree/shared/_reviews.html.erb b/app/views/spree/shared/_reviews.html.erb index 7b1a22b3..3c2c3aa0 100644 --- a/app/views/spree/shared/_reviews.html.erb +++ b/app/views/spree/shared/_reviews.html.erb @@ -1,17 +1,14 @@
-

<%= Spree.t(:reviews) %>

- <% if Spree::Reviews::Config[:include_unapproved_reviews] == false and @product.reviews.approved.count == 0 %> -

<%= Spree.t(:no_reviews_available) %>

+

<%= Spree.t(:reviews) %>

+ <% if Spree::Reviews::Config[:include_unapproved_reviews] == false and @product.reviews.count == 0 %> +

<%= Spree.t(:no_reviews_available) %>

<% else %> <%= render 'spree/shared/rating', product: @product, review: 0 %> <% for review in (Spree::Reviews::Config[:track_locale] ? @product.reviews.localized(I18n.locale) : @product.reviews).default_approval_filter.preview %> <%= render 'spree/shared/review', review: review %> <% end %> <% end %> - <%= link_to Spree.t(:write_your_own_review), new_product_review_path(@product), class: 'btn btn-primary', rel: 'nofollow' %> - - <% unless Spree::Reviews::Config[:include_unapproved_reviews] == false and @product.reviews.approved.count == 0 %> - <%= Spree.t(:or) %> - <%= link_to Spree.t(:read_all_reviews), product_reviews_path(@product), class: 'btn btn-primary', rel: 'nofollow' %> - <% end %> -
+
+

<%= Spree.t(:write_your_own_review) %>

+
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 1b6869ca..67e60238 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -34,7 +34,7 @@ en: from: from info_approve_review: Review approved leave_us_a_review_for: "Please leave us a review and a rating for our '%{name}'" - no_reviews_available: "No reviews have been written for this product." + no_reviews_available: "Be the first to review this product" out_of_5: "out of 5" rating: rating reviews: Reviews @@ -64,6 +64,6 @@ en: one: "1 voice" other: "%{count} voices" was_this_review_helpful: "Was this review helpful to you?" - write_your_own_review: Write your own review + write_your_own_review: Post a review you_must_enter_value_for_rating: "You must enter a value for rating." anonymous: Anonymous From d5b79001a4e357b54430b8f66af0ff00f71f6cd0 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 18:09:05 +0500 Subject: [PATCH 04/15] fix(crash):add check on review count --- app/views/spree/shared/_rating.html.erb | 13 ++++++++----- config/locales/en.yml | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index 0a7b4ea6..977ae845 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -1,10 +1,13 @@ <% stars = @product.stars %> + <% reviews_count = product.reviews_count %> -<% raiting_five = product.reviews.raiting_five * 100 /reviews_count %> -<% raiting_four = product.reviews.raiting_four * 100 /reviews_count %> -<% raiting_three = product.reviews.raiting_three * 100 /reviews_count %> -<% raiting_two = product.reviews.raiting_two * 100 /reviews_count %> -<% raiting_one = product.reviews.raiting_one * 100 /reviews_count %> +<% if reviews_count.present? %> + <% raiting_five = product.reviews.raiting_five * 100 /reviews_count %> + <% raiting_four = product.reviews.raiting_four * 100 /reviews_count %> + <% raiting_three = product.reviews.raiting_three * 100 /reviews_count %> + <% raiting_two = product.reviews.raiting_two * 100 /reviews_count %> + <% raiting_one = product.reviews.raiting_one * 100 /reviews_count %> +<% end %>

Let us know your thoughts on a product or view reviews from our members, diff --git a/config/locales/en.yml b/config/locales/en.yml index 67e60238..d1684ff3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -22,7 +22,7 @@ en: average_customer_rating: Average rating back_reviews: Back to the reviews based_upon_review_count: - one: based upon one review + one: based upon 1 review other: "based upon %{count} reviews" by: by editing_review_for_html: 'Editing review for %{link}' From eaa4515068e3d2ae83803874c80c2f6d4c82e6d9 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 18:17:04 +0500 Subject: [PATCH 05/15] fix(rating): when reviews are zero --- app/views/spree/shared/_rating.html.erb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index 977ae845..bcc0b601 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -25,39 +25,39 @@

-

5

+

5

-
+
-

<%= raiting_five %>%

+

<%= raiting_five.present? ? raiting_five : 0 %>%

4

-
+
-

<%= raiting_four %>%

+

<%= raiting_four.present? ? raiting_four : 0 %>%

3

-
+
-

<%= raiting_three %>%

+

<%= raiting_three.present? ? raiting_three : 0 %>%

2

-
+
-

<%= raiting_two %>%

+

<%= raiting_two.present? ? raiting_two : 0 %>%

1

-
+
-

<%= raiting_one %>%

+

<%= raiting_one.present? ? raiting_one : 0 %>%

From 4c05dda29e3c76b483a28b9220da1616f5eb4b0f Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 18:58:51 +0500 Subject: [PATCH 06/15] fix(review-count): update when count is zero --- app/views/spree/shared/_rating.html.erb | 37 ++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index bcc0b601..ecc867cb 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -1,13 +1,12 @@ <% stars = @product.stars %> -<% reviews_count = product.reviews_count %> -<% if reviews_count.present? %> - <% raiting_five = product.reviews.raiting_five * 100 /reviews_count %> - <% raiting_four = product.reviews.raiting_four * 100 /reviews_count %> - <% raiting_three = product.reviews.raiting_three * 100 /reviews_count %> - <% raiting_two = product.reviews.raiting_two * 100 /reviews_count %> - <% raiting_one = product.reviews.raiting_one * 100 /reviews_count %> -<% end %> +<% reviews_count = product.reviews.count %> +<% raiting_five = reviews_count != 0 ? product.reviews.raiting_five * 100 / reviews_count : 0 %> +<% raiting_four = reviews_count != 0 ? product.reviews.raiting_four * 100 / reviews_count : 0 %> +<% raiting_three = reviews_count != 0 ? product.reviews.raiting_three * 100 / reviews_count : 0 %> +<% raiting_two = reviews_count != 0 ? product.reviews.raiting_two * 100 / reviews_count : 0%> +<% raiting_one = reviews_count != 0 ? product.reviews.raiting_one * 100 / reviews_count : 0 %> +

Let us know your thoughts on a product or view reviews from our members, @@ -25,39 +24,39 @@

-

5

+

5

-
+
-

<%= raiting_five.present? ? raiting_five : 0 %>%

+

<%= raiting_five %>%

4

-
+
-

<%= raiting_four.present? ? raiting_four : 0 %>%

+

<%= raiting_four %>%

3

-
+
-

<%= raiting_three.present? ? raiting_three : 0 %>%

+

<%= raiting_three %>%

2

-
+
-

<%= raiting_two.present? ? raiting_two : 0 %>%

+

<%= raiting_two %>%

1

-
+
-

<%= raiting_one.present? ? raiting_one : 0 %>%

+

<%= raiting_one %>%

From 4cb3e5693a9ee46dc4aeadedb562559830028c91 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 19:19:39 +0500 Subject: [PATCH 07/15] fix(avg-rating): adjust average rating --- app/models/spree/product_decorator.rb | 2 +- app/views/spree/shared/_rating.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 6ed0bdb2..297fa4b8 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -14,7 +14,7 @@ def stars def recalculate_rating self[:reviews_count] = reviews.count self[:avg_rating] = if reviews_count > 0 - reviews.sum(:rating).to_f / reviews_count + reviews.sum(:rating).to_f / reviews.count else 0 end diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index ecc867cb..074c5578 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -1,4 +1,4 @@ -<% stars = @product.stars %> +<% stars = product.stars %> <% reviews_count = product.reviews.count %> <% raiting_five = reviews_count != 0 ? product.reviews.raiting_five * 100 / reviews_count : 0 %> @@ -14,7 +14,7 @@

- <%= @product.stars %> + <%= product.stars %> <%= render 'spree/reviews/stars', stars: stars %> From 29d3c26edb04aebd6a46a90c130d03df2202d42f Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 20:22:04 +0500 Subject: [PATCH 08/15] fix(average): resolve average issue --- app/views/spree/shared/_rating.html.erb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index 074c5578..bed4df09 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -1,4 +1,4 @@ -<% stars = product.stars %> +<% @average_rating = product.reviews.count > 0 ? product.reviews.sum(:rating).to_f / product.reviews.count : 0 %> <% reviews_count = product.reviews.count %> <% raiting_five = reviews_count != 0 ? product.reviews.raiting_five * 100 / reviews_count : 0 %> @@ -14,9 +14,13 @@

- <%= product.stars %> - - <%= render 'spree/reviews/stars', stars: stars %> + <% if product.reviews.count > 0 %> + <%= @average_rating.try(:round) %> + <% else %> + 0 + <% end %> + + <%= render 'spree/reviews/stars', stars: @average_rating.try(:round) %>

@@ -62,7 +66,7 @@
- +
\ No newline at end of file From 5ec3ead6e81493b8cb03b92a0080f56c57cb0dfd Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 21:54:26 +0500 Subject: [PATCH 09/15] fix(text): variable names and design --- app/models/spree/review.rb | 10 ++++---- app/views/spree/shared/_rating.html.erb | 30 ++++++++++++------------ app/views/spree/shared/_reviews.html.erb | 11 +++++---- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/app/models/spree/review.rb b/app/models/spree/review.rb index dd2e5aa6..83e51b20 100644 --- a/app/models/spree/review.rb +++ b/app/models/spree/review.rb @@ -22,11 +22,11 @@ class Spree::Review < ActiveRecord::Base scope :approved, -> { where(approved: true) } scope :not_approved, -> { where(approved: false) } scope :default_approval_filter, -> { Spree::Reviews::Config[:include_unapproved_reviews] ? all : approved } - scope :raiting_five, -> { where(rating: '5').count } - scope :raiting_four, -> { where(rating: '4').count } - scope :raiting_three, -> { where(rating: '3').count } - scope :raiting_two, -> { where(rating: '2').count } - scope :raiting_one, -> { where(rating: '1').count } + scope :rating_with_five, -> { where(rating: '5').count } + scope :rating_with_four, -> { where(rating: '4').count } + scope :rating_with_three, -> { where(rating: '3').count } + scope :rating_with_two, -> { where(rating: '2').count } + scope :rating_with_one, -> { where(rating: '1').count } enum product_worth: %i[yes no dont_know], _prefix: :product_worth enum product_recommend: %i[yes no dont_know], _prefix: :product_recommend diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index bed4df09..7e753d57 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -1,11 +1,11 @@ <% @average_rating = product.reviews.count > 0 ? product.reviews.sum(:rating).to_f / product.reviews.count : 0 %> <% reviews_count = product.reviews.count %> -<% raiting_five = reviews_count != 0 ? product.reviews.raiting_five * 100 / reviews_count : 0 %> -<% raiting_four = reviews_count != 0 ? product.reviews.raiting_four * 100 / reviews_count : 0 %> -<% raiting_three = reviews_count != 0 ? product.reviews.raiting_three * 100 / reviews_count : 0 %> -<% raiting_two = reviews_count != 0 ? product.reviews.raiting_two * 100 / reviews_count : 0%> -<% raiting_one = reviews_count != 0 ? product.reviews.raiting_one * 100 / reviews_count : 0 %> +<% rating_with_five = reviews_count != 0 ? product.reviews.rating_five * 100 / reviews_count : 0 %> +<% rating_with_four = reviews_count != 0 ? product.reviews.rating_four * 100 / reviews_count : 0 %> +<% rating_with_three = reviews_count != 0 ? product.reviews.rating_three * 100 / reviews_count : 0 %> +<% rating_with_two = reviews_count != 0 ? product.reviews.rating_two * 100 / reviews_count : 0%> +<% rating_with_one = reviews_count != 0 ? product.reviews.rating_one * 100 / reviews_count : 0 %>

@@ -30,37 +30,37 @@

5

-
+
-

<%= raiting_five %>%

+

<%= rating_with_five %>%

4

-
+
-

<%= raiting_four %>%

+

<%= rating_with_four %>%

3

-
+
-

<%= raiting_three %>%

+

<%= rating_with_three %>%

2

-
+
-

<%= raiting_two %>%

+

<%= rating_with_two %>%

1

-
+
-

<%= raiting_one %>%

+

<%= rating_with_one %>%

diff --git a/app/views/spree/shared/_reviews.html.erb b/app/views/spree/shared/_reviews.html.erb index 3c2c3aa0..3ee47309 100644 --- a/app/views/spree/shared/_reviews.html.erb +++ b/app/views/spree/shared/_reviews.html.erb @@ -1,14 +1,17 @@

<%= Spree.t(:reviews) %>

- <% if Spree::Reviews::Config[:include_unapproved_reviews] == false and @product.reviews.count == 0 %> + <% if @product.reviews.count == 0 %>

<%= Spree.t(:no_reviews_available) %>

+
+

<%= Spree.t(:write_your_own_review) %>

+
<% else %> <%= render 'spree/shared/rating', product: @product, review: 0 %> +
+

<%= Spree.t(:write_your_own_review) %>

+
<% for review in (Spree::Reviews::Config[:track_locale] ? @product.reviews.localized(I18n.locale) : @product.reviews).default_approval_filter.preview %> <%= render 'spree/shared/review', review: review %> <% end %> <% end %> -
-

<%= Spree.t(:write_your_own_review) %>

-
\ No newline at end of file From 562379ed9a85b5bf811ad929cc1694ae1ff0e476 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Fri, 21 May 2021 22:23:24 +0500 Subject: [PATCH 10/15] fix(text): change names --- app/views/spree/shared/_rating.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/spree/shared/_rating.html.erb b/app/views/spree/shared/_rating.html.erb index 7e753d57..4e31a9bb 100644 --- a/app/views/spree/shared/_rating.html.erb +++ b/app/views/spree/shared/_rating.html.erb @@ -1,11 +1,11 @@ <% @average_rating = product.reviews.count > 0 ? product.reviews.sum(:rating).to_f / product.reviews.count : 0 %> <% reviews_count = product.reviews.count %> -<% rating_with_five = reviews_count != 0 ? product.reviews.rating_five * 100 / reviews_count : 0 %> -<% rating_with_four = reviews_count != 0 ? product.reviews.rating_four * 100 / reviews_count : 0 %> -<% rating_with_three = reviews_count != 0 ? product.reviews.rating_three * 100 / reviews_count : 0 %> -<% rating_with_two = reviews_count != 0 ? product.reviews.rating_two * 100 / reviews_count : 0%> -<% rating_with_one = reviews_count != 0 ? product.reviews.rating_one * 100 / reviews_count : 0 %> +<% rating_with_five = reviews_count != 0 ? product.reviews.rating_with_five * 100 / reviews_count : 0 %> +<% rating_with_four = reviews_count != 0 ? product.reviews.rating_with_four * 100 / reviews_count : 0 %> +<% rating_with_three = reviews_count != 0 ? product.reviews.rating_with_three * 100 / reviews_count : 0 %> +<% rating_with_two = reviews_count != 0 ? product.reviews.rating_with_two * 100 / reviews_count : 0%> +<% rating_with_one = reviews_count != 0 ? product.reviews.rating_with_one * 100 / reviews_count : 0 %>

From 004b6e55ebfbd7caccfd4068c7a58cbda055f030 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Mon, 24 May 2021 16:19:01 +0500 Subject: [PATCH 11/15] fix(user-check): only for auth --- app/views/spree/reviews/_form.html.erb | 7 ++++--- app/views/spree/shared/_reviews.html.erb | 13 ++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/spree/reviews/_form.html.erb b/app/views/spree/reviews/_form.html.erb index 6b1c0959..c8d036a7 100644 --- a/app/views/spree/reviews/_form.html.erb +++ b/app/views/spree/reviews/_form.html.erb @@ -8,17 +8,18 @@

<%= f.label :name %> - <%= f.text_field :name, maxlength: 255, size: 50, class: 'form-control', required: true %> + <%= f.text_field :name, maxlength: 20, size: 50, class: 'form-control', required: true %>
<%= f.label :title %> - <%= f.text_field :title, maxlength: 255, size: 50, class: 'form-control' %> + <%= f.text_field :title, maxlength: 20, size: 50, class: 'form-control' %>
<%= f.label :review %> - <%= f.text_area :review, wrap: 'virtual', rows: 4, cols: 50, class: 'form-control', required: true %> + Max limit 25 characters + <%= f.text_area :review, maxlength: 25, wrap: 'virtual', rows: 4, cols: 50, class: 'form-control', required: true %>
diff --git a/app/views/spree/shared/_reviews.html.erb b/app/views/spree/shared/_reviews.html.erb index 3ee47309..11885597 100644 --- a/app/views/spree/shared/_reviews.html.erb +++ b/app/views/spree/shared/_reviews.html.erb @@ -3,13 +3,20 @@ <% if @product.reviews.count == 0 %>

<%= Spree.t(:no_reviews_available) %>

-

<%= Spree.t(:write_your_own_review) %>

-
+

"> <%= Spree.t(:write_your_own_review) %>

+
+ <% unless spree_current_user.present? %> +

You need to login to Post a review

+ <% end %> + <% else %> <%= render 'spree/shared/rating', product: @product, review: 0 %>
-

<%= Spree.t(:write_your_own_review) %>

+

"> <%= Spree.t(:write_your_own_review) %>

+ <% unless spree_current_user.present? %> +

You need to login to Post a review

+ <% end %> <% for review in (Spree::Reviews::Config[:track_locale] ? @product.reviews.localized(I18n.locale) : @product.reviews).default_approval_filter.preview %> <%= render 'spree/shared/review', review: review %> <% end %> From e10e3b9db47d685e492ef23057c0531e2a498c30 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Mon, 24 May 2021 17:03:35 +0500 Subject: [PATCH 12/15] fix(form): remove name and show user name --- app/models/spree/review.rb | 1 - app/views/spree/reviews/_form.html.erb | 5 ----- app/views/spree/shared/_review.html.erb | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/models/spree/review.rb b/app/models/spree/review.rb index 83e51b20..58f12861 100644 --- a/app/models/spree/review.rb +++ b/app/models/spree/review.rb @@ -6,7 +6,6 @@ class Spree::Review < ActiveRecord::Base after_save :recalculate_product_rating after_destroy :recalculate_product_rating - validates :name, :review, presence: true validates :rating, numericality: { only_integer: true, greater_than_or_equal_to: 1, diff --git a/app/views/spree/reviews/_form.html.erb b/app/views/spree/reviews/_form.html.erb index c8d036a7..54a557e5 100644 --- a/app/views/spree/reviews/_form.html.erb +++ b/app/views/spree/reviews/_form.html.erb @@ -6,11 +6,6 @@ <%= render 'spree/reviews/stars', stars: review.rating, edit_enabled: true %>
-
- <%= f.label :name %> - <%= f.text_field :name, maxlength: 20, size: 50, class: 'form-control', required: true %> -
-
<%= f.label :title %> <%= f.text_field :title, maxlength: 20, size: 50, class: 'form-control' %> diff --git a/app/views/spree/shared/_review.html.erb b/app/views/spree/shared/_review.html.erb index c0fef422..64649094 100644 --- a/app/views/spree/shared/_review.html.erb +++ b/app/views/spree/shared/_review.html.erb @@ -23,7 +23,7 @@ <% if Spree::Reviews::Config[:show_email] && review.user %> <% else %> - + <% end %> <% else %> From 6c80ac1024692cc98eeab5afbb2b73808cf367c6 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Mon, 24 May 2021 18:40:37 +0500 Subject: [PATCH 13/15] fix(name): review user name --- app/views/spree/reviews/_form.html.erb | 4 ++-- app/views/spree/shared/_review.html.erb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/spree/reviews/_form.html.erb b/app/views/spree/reviews/_form.html.erb index 54a557e5..3cbe7a67 100644 --- a/app/views/spree/reviews/_form.html.erb +++ b/app/views/spree/reviews/_form.html.erb @@ -13,8 +13,8 @@
<%= f.label :review %> - Max limit 25 characters - <%= f.text_area :review, maxlength: 25, wrap: 'virtual', rows: 4, cols: 50, class: 'form-control', required: true %> + Max limit 40 characters + <%= f.text_area :review, maxlength: 40, wrap: 'virtual', rows: 4, cols: 50, class: 'form-control', required: true %>
diff --git a/app/views/spree/shared/_review.html.erb b/app/views/spree/shared/_review.html.erb index 64649094..7910c766 100644 --- a/app/views/spree/shared/_review.html.erb +++ b/app/views/spree/shared/_review.html.erb @@ -23,9 +23,10 @@ <% if Spree::Reviews::Config[:show_email] && review.user %> <% else %> - + <% end %> <% else %> <% end %>
+ From 5f592ad641e5e304632cd3e4ac9815133a4090d5 Mon Sep 17 00:00:00 2001 From: umairrazam Date: Mon, 28 Jun 2021 18:26:27 +0500 Subject: [PATCH 14/15] fix(form): hanf=dle nil cases --- app/views/spree/admin/reviews/index.html.erb | 2 +- app/views/spree/shared/_review.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/spree/admin/reviews/index.html.erb b/app/views/spree/admin/reviews/index.html.erb index 6ff82328..7eeff657 100644 --- a/app/views/spree/admin/reviews/index.html.erb +++ b/app/views/spree/admin/reviews/index.html.erb @@ -67,7 +67,7 @@ <% @reviews.each do |review| %> - <%= link_to_if review.product, review.product.name, product_path(review.product) %> + <%= link_to_if review.product, review&.product&.name, products_path(review.product) %> <%= txt_stars(review.rating) %> <%= link_to "(#{review.feedback_stars}/#{review.feedback_reviews.size})", admin_review_feedback_reviews_path(review) %> <%= review.user_id ? link_to(review.user.try(:email), admin_user_path(review.user)) : Spree.t(:anonymous) %> diff --git a/app/views/spree/shared/_review.html.erb b/app/views/spree/shared/_review.html.erb index 7910c766..99390105 100644 --- a/app/views/spree/shared/_review.html.erb +++ b/app/views/spree/shared/_review.html.erb @@ -1,9 +1,9 @@
- <%= render 'spree/reviews/stars', stars: review.rating %> + <%= render 'spree/reviews/stars', stars: review&.rating %>
- <%= review.title %> + <%= review&.title %>

<%= review.review %>

From e2a2c369e9ec10c56fc8c9a4f13cee48ba0aa4ec Mon Sep 17 00:00:00 2001 From: umairrazam Date: Tue, 29 Jun 2021 20:26:15 +0500 Subject: [PATCH 15/15] fix(permission):admin tab --- app/overrides/add_reviews_to_admin_configuration_sidebar.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/overrides/add_reviews_to_admin_configuration_sidebar.rb b/app/overrides/add_reviews_to_admin_configuration_sidebar.rb index e9032cd0..29e512c4 100644 --- a/app/overrides/add_reviews_to_admin_configuration_sidebar.rb +++ b/app/overrides/add_reviews_to_admin_configuration_sidebar.rb @@ -2,5 +2,5 @@ virtual_path: 'spree/admin/shared/sub_menu/_configuration', name: 'converted_admin_configurations_menu', insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]', - text: '<%= configurations_sidebar_menu_item Spree.t(:review_settings, scope: :spree_reviews), edit_admin_review_settings_path %>' + text: '<%= configurations_sidebar_menu_item(Spree.t(:review_settings, scope: :spree_reviews), edit_admin_review_settings_path) if can? :manage, Spree::Review %>' )