workarea-reviews 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintignore +2 -0
  4. data/.eslintrc +24 -0
  5. data/.eslintrc.json +35 -0
  6. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  7. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  8. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  9. data/.github/workflows/ci.yml +60 -0
  10. data/.gitignore +15 -0
  11. data/.rubocop.yml +3 -0
  12. data/.scss-lint.yml +188 -0
  13. data/.stylelintrc.json +8 -0
  14. data/.yardopts +1 -0
  15. data/CHANGELOG.md +745 -0
  16. data/CODE_OF_CONDUCT.md +3 -0
  17. data/CONTRIBUTING.md +3 -0
  18. data/Gemfile +8 -0
  19. data/LICENSE +52 -0
  20. data/README.md +107 -0
  21. data/Rakefile +53 -0
  22. data/app/assets/images/workarea/admin/icons/star.svg +1 -0
  23. data/app/assets/images/workarea/storefront/icons/empty_star.svg +1 -0
  24. data/app/assets/images/workarea/storefront/icons/half_star.svg +1 -0
  25. data/app/assets/images/workarea/storefront/icons/star.svg +1 -0
  26. data/app/assets/javascripts/workarea/storefront/reviews/modules/product_review_ajax_submit.js +39 -0
  27. data/app/assets/javascripts/workarea/storefront/reviews/modules/product_reviews_sort_menus.js +82 -0
  28. data/app/assets/javascripts/workarea/storefront/reviews/modules/rating_buttons.js +103 -0
  29. data/app/assets/javascripts/workarea/storefront/reviews/templates/sort_by_property.jst.ejs +11 -0
  30. data/app/assets/stylesheets/workarea/storefront/reviews/components/_rating.scss +28 -0
  31. data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews.scss +59 -0
  32. data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews_aggregate.scss +38 -0
  33. data/app/assets/stylesheets/workarea/storefront/reviews/components/_write_review.scss +63 -0
  34. data/app/controllers/workarea/admin/catalog_products_controller.decorator +9 -0
  35. data/app/controllers/workarea/admin/reports_controller.decorator +10 -0
  36. data/app/controllers/workarea/admin/reviews_controller.rb +51 -0
  37. data/app/controllers/workarea/storefront/review_requests_controller.rb +50 -0
  38. data/app/controllers/workarea/storefront/reviews_controller.rb +53 -0
  39. data/app/helpers/workarea/admin/reviews_helper.rb +13 -0
  40. data/app/helpers/workarea/storefront/reviews_helper.rb +22 -0
  41. data/app/helpers/workarea/storefront/reviews_schema_org_helper.rb +34 -0
  42. data/app/mailers/workarea/admin/status_report_mailer.decorator +8 -0
  43. data/app/mailers/workarea/storefront/review_mailer.rb +23 -0
  44. data/app/models/workarea/catalog/product.decorator +15 -0
  45. data/app/models/workarea/fulfillment.decorator +11 -0
  46. data/app/models/workarea/insights/most_active_reviewers.rb +34 -0
  47. data/app/models/workarea/insights/most_reviewed_products.rb +33 -0
  48. data/app/models/workarea/insights/top_rated_products.rb +33 -0
  49. data/app/models/workarea/review.rb +124 -0
  50. data/app/models/workarea/review/request.rb +62 -0
  51. data/app/models/workarea/search/admin/review.rb +72 -0
  52. data/app/models/workarea/search/storefront/product.decorator +9 -0
  53. data/app/models/workarea/sort.decorator +17 -0
  54. data/app/queries/workarea/reports/reviews_by_product.rb +86 -0
  55. data/app/queries/workarea/reports/reviews_by_user.rb +71 -0
  56. data/app/queries/workarea/review_request_params.rb +47 -0
  57. data/app/queries/workarea/review_summary.rb +11 -0
  58. data/app/queries/workarea/search/admin_reviews.rb +40 -0
  59. data/app/queries/workarea/search/category_browse.decorator +9 -0
  60. data/app/queries/workarea/search/product_search.decorator +9 -0
  61. data/app/seeds/workarea/review_seeds.rb +49 -0
  62. data/app/services/workarea/create_review.rb +99 -0
  63. data/app/view_models/workarea/admin/dashboards/reports_view_model.decorator +11 -0
  64. data/app/view_models/workarea/admin/product_view_model.decorator +7 -0
  65. data/app/view_models/workarea/admin/reports/reviews_by_product_view_model.rb +27 -0
  66. data/app/view_models/workarea/admin/review_view_model.rb +23 -0
  67. data/app/view_models/workarea/admin/reviews_search_view_model.rb +46 -0
  68. data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
  69. data/app/view_models/workarea/storefront/review_view_model.rb +14 -0
  70. data/app/views/workarea/admin/activities/_review_create.html.haml +12 -0
  71. data/app/views/workarea/admin/activities/_review_destroy.html.haml +10 -0
  72. data/app/views/workarea/admin/activities/_review_update.html.haml +10 -0
  73. data/app/views/workarea/admin/dashboards/_reviews_by_product_card.html.haml +17 -0
  74. data/app/views/workarea/admin/insights/_most_active_reviewers.html.haml +22 -0
  75. data/app/views/workarea/admin/insights/_most_reviewed_products.html.haml +22 -0
  76. data/app/views/workarea/admin/insights/_top_rated_products.html.haml +22 -0
  77. data/app/views/workarea/admin/reports/reviews_by_product.html.haml +44 -0
  78. data/app/views/workarea/admin/reviews/_aux_navigation.html.haml +5 -0
  79. data/app/views/workarea/admin/reviews/_catalog_products_aux_link.html.haml +5 -0
  80. data/app/views/workarea/admin/reviews/_dashboard_navigation.html.haml +1 -0
  81. data/app/views/workarea/admin/reviews/_menu.html.haml +3 -0
  82. data/app/views/workarea/admin/reviews/_summary.html.haml +12 -0
  83. data/app/views/workarea/admin/reviews/edit.html.haml +77 -0
  84. data/app/views/workarea/admin/reviews/index.html.haml +74 -0
  85. data/app/views/workarea/admin/status_report_mailer/_reviews.html.haml +5 -0
  86. data/app/views/workarea/storefront/products/_rating.html.haml +9 -0
  87. data/app/views/workarea/storefront/products/_reviews.html.haml +23 -0
  88. data/app/views/workarea/storefront/products/_reviews_aggregate.html.haml +22 -0
  89. data/app/views/workarea/storefront/products/_reviews_summary.html.haml +2 -0
  90. data/app/views/workarea/storefront/review_mailer/review_request.html.haml +24 -0
  91. data/app/views/workarea/storefront/review_requests/show.html.haml +45 -0
  92. data/app/views/workarea/storefront/reviews/new.html.haml +68 -0
  93. data/app/views/workarea/storefront/style_guides/_reviews_product_summary_docs.html.haml +13 -0
  94. data/app/views/workarea/storefront/style_guides/components/_reviews.html.haml +17 -0
  95. data/app/workers/workarea/create_review_requests.rb +33 -0
  96. data/app/workers/workarea/schedule_review_requests.rb +44 -0
  97. data/app/workers/workarea/send_review_requests.rb +12 -0
  98. data/app/workers/workarea/update_product_review_data.rb +26 -0
  99. data/bin/rails +18 -0
  100. data/config/initializers/append_points.rb +75 -0
  101. data/config/initializers/assets.rb +1 -0
  102. data/config/initializers/configuration.rb +31 -0
  103. data/config/initializers/rack_attack.rb +11 -0
  104. data/config/initializers/recaptcha.rb +19 -0
  105. data/config/initializers/scheduled_jobs.rb +8 -0
  106. data/config/locales/en.yml +150 -0
  107. data/config/routes.rb +25 -0
  108. data/lib/tasks/verify.rake +16 -0
  109. data/lib/workarea/mailer_previews/storefront/review_mailer_preview.rb +10 -0
  110. data/lib/workarea/reviews.rb +13 -0
  111. data/lib/workarea/reviews/engine.rb +16 -0
  112. data/lib/workarea/reviews/version.rb +5 -0
  113. data/package.json +9 -0
  114. data/test/dummy/Rakefile +6 -0
  115. data/test/dummy/app/assets/config/manifest.js +4 -0
  116. data/test/dummy/app/assets/images/.keep +0 -0
  117. data/test/dummy/app/assets/javascripts/application.js +13 -0
  118. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  119. data/test/dummy/app/controllers/application_controller.rb +3 -0
  120. data/test/dummy/app/controllers/concerns/.keep +0 -0
  121. data/test/dummy/app/helpers/application_helper.rb +2 -0
  122. data/test/dummy/app/jobs/application_job.rb +2 -0
  123. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  124. data/test/dummy/app/models/concerns/.keep +0 -0
  125. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  126. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  127. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  128. data/test/dummy/bin/bundle +3 -0
  129. data/test/dummy/bin/rails +4 -0
  130. data/test/dummy/bin/rake +4 -0
  131. data/test/dummy/bin/setup +34 -0
  132. data/test/dummy/bin/update +29 -0
  133. data/test/dummy/config.ru +5 -0
  134. data/test/dummy/config/application.rb +25 -0
  135. data/test/dummy/config/boot.rb +5 -0
  136. data/test/dummy/config/cable.yml +9 -0
  137. data/test/dummy/config/environment.rb +5 -0
  138. data/test/dummy/config/environments/development.rb +55 -0
  139. data/test/dummy/config/environments/production.rb +86 -0
  140. data/test/dummy/config/environments/test.rb +43 -0
  141. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  142. data/test/dummy/config/initializers/assets.rb +11 -0
  143. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  144. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  145. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  146. data/test/dummy/config/initializers/inflections.rb +16 -0
  147. data/test/dummy/config/initializers/mime_types.rb +4 -0
  148. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  149. data/test/dummy/config/initializers/session_store.rb +5 -0
  150. data/test/dummy/config/initializers/workarea.rb +5 -0
  151. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  152. data/test/dummy/config/locales/en.yml +23 -0
  153. data/test/dummy/config/puma.rb +47 -0
  154. data/test/dummy/config/routes.rb +5 -0
  155. data/test/dummy/config/secrets.yml +22 -0
  156. data/test/dummy/config/spring.rb +6 -0
  157. data/test/dummy/db/seeds.rb +2 -0
  158. data/test/dummy/lib/assets/.keep +0 -0
  159. data/test/dummy/log/.keep +0 -0
  160. data/test/factories/reviews.rb +32 -0
  161. data/test/fixtures/reviews.csv +5 -0
  162. data/test/helpers/workarea/storefront/reviews_helper_test.rb +20 -0
  163. data/test/integration/workarea/admin/reviews_integration_test.rb +37 -0
  164. data/test/integration/workarea/storefront/review_requests_integration_test.rb +63 -0
  165. data/test/integration/workarea/storefront/reviews_integration_test.rb +82 -0
  166. data/test/javascripts/fixtures/product_review_ajax_submit.html.haml +4 -0
  167. data/test/javascripts/product_review_ajax_submit_spec.js +28 -0
  168. data/test/javascripts/spec_helper.js +23 -0
  169. data/test/models/workarea/insights/most_active_reviewers_test.rb +32 -0
  170. data/test/models/workarea/insights/most_reviewed_products_test.rb +32 -0
  171. data/test/models/workarea/insights/top_rated_products_test.rb +49 -0
  172. data/test/models/workarea/review/request_test.rb +18 -0
  173. data/test/models/workarea/review_test.rb +105 -0
  174. data/test/models/workarea/search/storefront/product_test.decorator +14 -0
  175. data/test/queries/workarea/reports/reviews_by_product_test.rb +104 -0
  176. data/test/queries/workarea/reports/reviews_by_user_test.rb +102 -0
  177. data/test/queries/workarea/review_request_params_test.rb +64 -0
  178. data/test/services/workarea/create_review_test.rb +131 -0
  179. data/test/system/workarea/admin/review_system_test.rb +96 -0
  180. data/test/system/workarea/admin/reviews_by_product_system_test.rb +60 -0
  181. data/test/system/workarea/storefront/review_request_system_test.rb +34 -0
  182. data/test/system/workarea/storefront/review_system_test.rb +113 -0
  183. data/test/teaspoon_env.rb +10 -0
  184. data/test/test_helper.rb +11 -0
  185. data/test/workers/workarea/create_review_requests_test.rb +38 -0
  186. data/test/workers/workarea/schedule_review_requests_test.rb +115 -0
  187. data/test/workers/workarea/send_review_requests_test.rb +30 -0
  188. data/workarea-reviews.gemspec +22 -0
  189. data/yarn.lock +3265 -0
  190. metadata +265 -0
@@ -0,0 +1,11 @@
1
+ <div class="property property--responsive">
2
+ <label class="property__name"><span class="property__text">Sort By</span></label>
3
+ <div class="value">
4
+ <select data-product-reviews-sort-menu="">
5
+ <option value="newest" selected>Most Recent</option>
6
+ <option value="oldest">Oldest First</option>
7
+ <option value="highest">Rating: High to Low</option>
8
+ <option value="lowest">Rating: Low to High</option>
9
+ </select>
10
+ </div>
11
+ </div>
@@ -0,0 +1,28 @@
1
+ /*------------------------------------*\
2
+ #RATING
3
+ \*------------------------------------*/
4
+
5
+ $rating-fill-color: $yellow !default;
6
+ $rating-empty-color: $gray !default;
7
+ $rating-star-size: 16px !default;
8
+
9
+
10
+
11
+ .rating {
12
+ position: relative;
13
+ white-space: nowrap;
14
+ vertical-align: middle;
15
+ user-select: none;
16
+
17
+ .product-summary & {
18
+ margin: $spacing-unit auto 0;
19
+ }
20
+ }
21
+
22
+ .rating__star {
23
+ display: inline-block;
24
+ width: $rating-star-size;
25
+ height: $rating-star-size;
26
+ fill: $rating-fill-color;
27
+ overflow: hidden;
28
+ }
@@ -0,0 +1,59 @@
1
+ /*------------------------------------*\
2
+ #REVIEWS
3
+ \*------------------------------------*/
4
+
5
+ .reviews {
6
+ margin: ($spacing-unit * 3) 0 0;
7
+ }
8
+
9
+ .reviews__header {
10
+ display: table;
11
+ margin: 0 0 ($spacing-unit * 2);
12
+ width: 100%;
13
+ }
14
+
15
+ .reviews__count {
16
+ display: table-cell;
17
+ }
18
+
19
+ .reviews__write-action {
20
+ display: table-cell;
21
+ text-align: right;
22
+ }
23
+
24
+ .reviews__review-group {
25
+ @extend %list-reset;
26
+ }
27
+
28
+ .reviews__review {
29
+ padding: ($spacing-unit * 2) 0;
30
+ }
31
+
32
+ .reviews__review-title {}
33
+
34
+ .reviews__review-body {}
35
+
36
+ .reviews__review-meta {
37
+ @extend %clearfix;
38
+ }
39
+
40
+ .reviews__review-author {
41
+ margin: 0;
42
+ float: left;
43
+ line-height: 1;
44
+ }
45
+
46
+ .reviews__review-verified {
47
+ margin: 0 0 0 $spacing-unit;
48
+ padding-left: $spacing-unit;
49
+ float: left;
50
+ line-height: 1;
51
+ font-weight: bold;
52
+ }
53
+
54
+ .reviews__review-date {
55
+ margin: 0 0 0 $spacing-unit;
56
+ padding-left: $spacing-unit;
57
+ float: left;
58
+ line-height: 1;
59
+ }
@@ -0,0 +1,38 @@
1
+ /*------------------------------------*\
2
+ #REVIEWS-AGGREGATE
3
+ \*------------------------------------*/
4
+
5
+ $reviews-aggregate-border: 1px solid $link-color !default;
6
+
7
+
8
+ .reviews-aggregate {
9
+ @extend %clearfix;
10
+ margin: 0 0 12px;
11
+
12
+ /**
13
+ * Extend `.rating {}` in _rating.scss.
14
+ */
15
+
16
+ .rating {
17
+ @extend %inline-list;
18
+ margin: 0 ($spacing-unit / 2) 0 0;
19
+ }
20
+ }
21
+
22
+ .reviews-aggregate__rating-link:hover {
23
+ text-decoration: none;
24
+ }
25
+
26
+ .reviews-aggregate__count {
27
+ @extend %inline-list;
28
+ }
29
+
30
+ .reviews-aggregate__read {}
31
+
32
+ .reviews-aggregate__write-action {
33
+ &::before {
34
+ padding-right: ($spacing-unit / 2);
35
+ border-left: $reviews-aggregate-border;
36
+ content: '';
37
+ }
38
+ }
@@ -0,0 +1,63 @@
1
+ /*------------------------------------*\
2
+ #WRITE-REVIEW
3
+ \*------------------------------------*/
4
+
5
+ $write-review-fill-color: $yellow !default;
6
+ $write-review-empty-color: $transparent !default;
7
+ $write-review-star-size: 16px !default;
8
+
9
+
10
+ .write-review {}
11
+
12
+ .write-review__ratings {
13
+ @extend %inline-list;
14
+
15
+
16
+ .js & {
17
+ @extend %clearfix;
18
+ }
19
+ }
20
+
21
+ .write-review__rating {
22
+ font-size: $write-review-star-size;
23
+
24
+ .js & {
25
+ padding-right: ($spacing-unit / 2);
26
+ float: left;
27
+ }
28
+ }
29
+
30
+ .write-review__rating-input {
31
+ margin: 0 ($spacing-unit / 2) 0 0;
32
+
33
+ .js & {
34
+ @extend %visually-hidden;
35
+ }
36
+ }
37
+
38
+ .write-review__star {}
39
+
40
+ .write-review__star-icon {
41
+ width: $write-review-star-size;
42
+ height: $write-review-star-size;
43
+ fill: $write-review-empty-color;
44
+ stroke: $write-review-fill-color;
45
+
46
+ .write-review__star--hovered &,
47
+ .write-review__star--active & {
48
+ fill: $write-review-fill-color;
49
+ }
50
+ }
51
+
52
+
53
+ .write-review__star--hovered {
54
+ opacity: 0.4;
55
+ }
56
+
57
+ .write-review__star--active {
58
+ opacity: 1;
59
+ }
60
+
61
+ .write-review__star-text {
62
+ @extend %hidden-if-js-enabled;
63
+ }
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ decorate Admin::CatalogProductsController, with: :reviews do
3
+ decorated { helper Admin::ReviewsHelper }
4
+
5
+ def reviews
6
+ @reviews = Review.find_for_product(@product.id, true)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate Admin::ReportsController, with: :reviews do
3
+ def reviews_by_product
4
+ @report = Admin::Reports::ReviewsByProductViewModel.wrap(
5
+ Workarea::Reports::ReviewsByProduct.new(params),
6
+ view_model_options
7
+ )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ module Workarea
2
+ class Admin::ReviewsController < Admin::ApplicationController
3
+ required_permissions :marketing
4
+ before_action :find_review, except: :index
5
+
6
+ def index
7
+ search = Search::AdminReviews.new(params.merge(autocomplete: request.xhr?))
8
+ @search = Admin::ReviewsSearchViewModel.new(search, view_model_options)
9
+ end
10
+
11
+ def show
12
+ redirect_to edit_review_path(@review)
13
+ end
14
+
15
+ def edit; end
16
+
17
+ def update
18
+ if @review.update_attributes(review_params)
19
+ flash[:success] = t('workarea.admin.reviews.flash_messages.updated')
20
+ redirect_to reviews_path
21
+ else
22
+ render :edit
23
+ end
24
+ end
25
+
26
+ def destroy
27
+ @review.destroy
28
+ flash[:success] = t('workarea.admin.reviews.flash_messages.destroyed')
29
+ if params[:product].present?
30
+ redirect_to reviews_catalog_product_path(params[:product])
31
+ else
32
+ redirect_to reviews_path
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def find_review
39
+ if params[:id].present?
40
+ review = Review.find(params[:id])
41
+ @review = Admin::ReviewViewModel.wrap(review)
42
+ @user = User.find(review.user_id) rescue nil
43
+ end
44
+ end
45
+
46
+ def review_params
47
+ return {} if params[:review].blank?
48
+ params[:review].permit(:body, :approved, :rating, :title)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,50 @@
1
+ module Workarea
2
+ module Storefront
3
+ class ReviewRequestsController < Storefront::ApplicationController
4
+ before_action :validate_request
5
+ before_action :find_product, :set_review
6
+
7
+ def show; end
8
+
9
+ def complete
10
+ if verify_recaptcha(model: @review, env: Rails.env) && @review.save
11
+ @request.complete!
12
+ Review::Request.cancel_for_orders!(@request.order_id)
13
+
14
+ flash[:success] = t('workarea.storefront.reviews.flash_messages.created')
15
+ redirect_to product_path(@product)
16
+ else
17
+ flash[:error] = t('workarea.storefront.reviews.flash_messages.failure')
18
+ render :show
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def validate_request
25
+ @request = Review::Request.find_by_token(params[:id])
26
+
27
+ if @request.nil? || @request.completed?
28
+ flash[:error] = t('workarea.storefront.review_requests.flash_messages.already_submitted')
29
+ redirect_to(root_path) && (return)
30
+ end
31
+ end
32
+
33
+ def find_product
34
+ model = Catalog::Product.find(@request.product_id)
35
+ @product = ProductViewModel.wrap(model, view_model_options)
36
+ end
37
+
38
+ def set_review
39
+ @review = ReviewViewModel.wrap(Review.new(review_params))
40
+ end
41
+
42
+ def review_params
43
+ ReviewRequestParams.new(
44
+ @request,
45
+ params[:review]&.permit(:rating, :title, :body)&.to_h || {}
46
+ ).to_h
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,53 @@
1
+ module Workarea
2
+ module Storefront
3
+ class ReviewsController < Storefront::ApplicationController
4
+ before_action :find_product
5
+ before_action :set_review
6
+
7
+ def new; end
8
+
9
+ def create
10
+ if review_can_be_saved? && @create_review.save
11
+ redirect_to product_path(params[:product_id])
12
+ flash[:success] = t('workarea.storefront.reviews.flash_messages.created')
13
+ else
14
+ render :new
15
+ flash[:error] = t('workarea.storefront.reviews.flash_messages.failure')
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def set_review
22
+ @create_review = CreateReview.for(
23
+ product: @product,
24
+ user: current_user,
25
+ params: review_params.to_h
26
+ )
27
+
28
+ @review = ReviewViewModel.wrap(@create_review.review)
29
+ end
30
+
31
+ def find_product
32
+ @product ||=
33
+ begin
34
+ model = Catalog::Product.find_by(slug: params[:product_id])
35
+ raise InvalidDisplay unless model.active? || current_user.try(:admin?)
36
+ ProductViewModel.wrap(model)
37
+ end
38
+ end
39
+
40
+ def review_params
41
+ return {} unless params[:review].present?
42
+
43
+ params[:review].permit(
44
+ :product_id, :rating, :title, :body, :first_name, :last_name, :email
45
+ )
46
+ end
47
+
48
+ def review_can_be_saved?
49
+ verify_recaptcha(model: @create_review, env: Rails.env)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ module Workarea
2
+ module Admin
3
+ module ReviewsHelper
4
+ def reviews_report_filter_options
5
+ [
6
+ [t('workarea.admin.reports.reviews_by_product.filters.all'), nil],
7
+ [t('workarea.admin.reports.reviews_by_product.filters.approved'), 'approved'],
8
+ [t('workarea.admin.reports.reviews_by_product.filters.unapproved'), 'unapproved']
9
+ ]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ module Workarea
2
+ module Storefront
3
+ module ReviewsHelper
4
+ def rating_stars(rating, options = {})
5
+ full_star_count = rating.floor
6
+ empty_star_count = 5 - rating.ceil
7
+ half_star_size = (rating % 1).round(2) * 100
8
+ half_star_width = 20 + (half_star_size - 0) * (80.0 - 20) / (100.0 - 0)
9
+
10
+ render 'workarea/storefront/products/rating', rating: rating, full_star_count: full_star_count, empty_star_count: empty_star_count, half_star_width: half_star_width, half_star_size: half_star_size
11
+ end
12
+
13
+ def display_purchase_requirement_message
14
+ if current_user && Workarea.config.require_purchase_to_post_review && current_user.total_spent.to_f.zero?
15
+ true
16
+ else
17
+ false
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Workarea
2
+ module Storefront
3
+ module ReviewsSchemaOrgHelper
4
+ def product_schema(product, related_products: nil)
5
+ schema = super.merge(
6
+ 'review': product.reviews.map do |review|
7
+ {
8
+ '@type': 'Review',
9
+ 'author': review.user_info,
10
+ 'datePublished': review.created_at.strftime('%Y-%m-%d'),
11
+ 'description': review.body,
12
+ 'name': review.title,
13
+ 'reviewRating': {
14
+ '@type': 'Rating',
15
+ 'bestRating': '5',
16
+ 'worstRating': '1',
17
+ 'ratingValue': review.rating.round(2).to_s
18
+ }
19
+ }
20
+ end
21
+ )
22
+
23
+ if product.total_reviews > 0 && product.average_rating.present?
24
+ schema['aggregateRating'] = {
25
+ 'reviewCount': product.total_reviews.to_s,
26
+ 'ratingValue': product.average_rating.round(2).to_s
27
+ }
28
+ end
29
+
30
+ schema
31
+ end
32
+ end
33
+ end
34
+ end