workarea-reviews 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.eslintignore +2 -0
- data/.eslintrc +24 -0
- data/.eslintrc.json +35 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/ci.yml +60 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +3 -0
- data/.scss-lint.yml +188 -0
- data/.stylelintrc.json +8 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +745 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +8 -0
- data/LICENSE +52 -0
- data/README.md +107 -0
- data/Rakefile +53 -0
- data/app/assets/images/workarea/admin/icons/star.svg +1 -0
- data/app/assets/images/workarea/storefront/icons/empty_star.svg +1 -0
- data/app/assets/images/workarea/storefront/icons/half_star.svg +1 -0
- data/app/assets/images/workarea/storefront/icons/star.svg +1 -0
- data/app/assets/javascripts/workarea/storefront/reviews/modules/product_review_ajax_submit.js +39 -0
- data/app/assets/javascripts/workarea/storefront/reviews/modules/product_reviews_sort_menus.js +82 -0
- data/app/assets/javascripts/workarea/storefront/reviews/modules/rating_buttons.js +103 -0
- data/app/assets/javascripts/workarea/storefront/reviews/templates/sort_by_property.jst.ejs +11 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_rating.scss +28 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews.scss +59 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews_aggregate.scss +38 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_write_review.scss +63 -0
- data/app/controllers/workarea/admin/catalog_products_controller.decorator +9 -0
- data/app/controllers/workarea/admin/reports_controller.decorator +10 -0
- data/app/controllers/workarea/admin/reviews_controller.rb +51 -0
- data/app/controllers/workarea/storefront/review_requests_controller.rb +50 -0
- data/app/controllers/workarea/storefront/reviews_controller.rb +53 -0
- data/app/helpers/workarea/admin/reviews_helper.rb +13 -0
- data/app/helpers/workarea/storefront/reviews_helper.rb +22 -0
- data/app/helpers/workarea/storefront/reviews_schema_org_helper.rb +34 -0
- data/app/mailers/workarea/admin/status_report_mailer.decorator +8 -0
- data/app/mailers/workarea/storefront/review_mailer.rb +23 -0
- data/app/models/workarea/catalog/product.decorator +15 -0
- data/app/models/workarea/fulfillment.decorator +11 -0
- data/app/models/workarea/insights/most_active_reviewers.rb +34 -0
- data/app/models/workarea/insights/most_reviewed_products.rb +33 -0
- data/app/models/workarea/insights/top_rated_products.rb +33 -0
- data/app/models/workarea/review.rb +124 -0
- data/app/models/workarea/review/request.rb +62 -0
- data/app/models/workarea/search/admin/review.rb +72 -0
- data/app/models/workarea/search/storefront/product.decorator +9 -0
- data/app/models/workarea/sort.decorator +17 -0
- data/app/queries/workarea/reports/reviews_by_product.rb +86 -0
- data/app/queries/workarea/reports/reviews_by_user.rb +71 -0
- data/app/queries/workarea/review_request_params.rb +47 -0
- data/app/queries/workarea/review_summary.rb +11 -0
- data/app/queries/workarea/search/admin_reviews.rb +40 -0
- data/app/queries/workarea/search/category_browse.decorator +9 -0
- data/app/queries/workarea/search/product_search.decorator +9 -0
- data/app/seeds/workarea/review_seeds.rb +49 -0
- data/app/services/workarea/create_review.rb +99 -0
- data/app/view_models/workarea/admin/dashboards/reports_view_model.decorator +11 -0
- data/app/view_models/workarea/admin/product_view_model.decorator +7 -0
- data/app/view_models/workarea/admin/reports/reviews_by_product_view_model.rb +27 -0
- data/app/view_models/workarea/admin/review_view_model.rb +23 -0
- data/app/view_models/workarea/admin/reviews_search_view_model.rb +46 -0
- data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
- data/app/view_models/workarea/storefront/review_view_model.rb +14 -0
- data/app/views/workarea/admin/activities/_review_create.html.haml +12 -0
- data/app/views/workarea/admin/activities/_review_destroy.html.haml +10 -0
- data/app/views/workarea/admin/activities/_review_update.html.haml +10 -0
- data/app/views/workarea/admin/dashboards/_reviews_by_product_card.html.haml +17 -0
- data/app/views/workarea/admin/insights/_most_active_reviewers.html.haml +22 -0
- data/app/views/workarea/admin/insights/_most_reviewed_products.html.haml +22 -0
- data/app/views/workarea/admin/insights/_top_rated_products.html.haml +22 -0
- data/app/views/workarea/admin/reports/reviews_by_product.html.haml +44 -0
- data/app/views/workarea/admin/reviews/_aux_navigation.html.haml +5 -0
- data/app/views/workarea/admin/reviews/_catalog_products_aux_link.html.haml +5 -0
- data/app/views/workarea/admin/reviews/_dashboard_navigation.html.haml +1 -0
- data/app/views/workarea/admin/reviews/_menu.html.haml +3 -0
- data/app/views/workarea/admin/reviews/_summary.html.haml +12 -0
- data/app/views/workarea/admin/reviews/edit.html.haml +77 -0
- data/app/views/workarea/admin/reviews/index.html.haml +74 -0
- data/app/views/workarea/admin/status_report_mailer/_reviews.html.haml +5 -0
- data/app/views/workarea/storefront/products/_rating.html.haml +9 -0
- data/app/views/workarea/storefront/products/_reviews.html.haml +23 -0
- data/app/views/workarea/storefront/products/_reviews_aggregate.html.haml +22 -0
- data/app/views/workarea/storefront/products/_reviews_summary.html.haml +2 -0
- data/app/views/workarea/storefront/review_mailer/review_request.html.haml +24 -0
- data/app/views/workarea/storefront/review_requests/show.html.haml +45 -0
- data/app/views/workarea/storefront/reviews/new.html.haml +68 -0
- data/app/views/workarea/storefront/style_guides/_reviews_product_summary_docs.html.haml +13 -0
- data/app/views/workarea/storefront/style_guides/components/_reviews.html.haml +17 -0
- data/app/workers/workarea/create_review_requests.rb +33 -0
- data/app/workers/workarea/schedule_review_requests.rb +44 -0
- data/app/workers/workarea/send_review_requests.rb +12 -0
- data/app/workers/workarea/update_product_review_data.rb +26 -0
- data/bin/rails +18 -0
- data/config/initializers/append_points.rb +75 -0
- data/config/initializers/assets.rb +1 -0
- data/config/initializers/configuration.rb +31 -0
- data/config/initializers/rack_attack.rb +11 -0
- data/config/initializers/recaptcha.rb +19 -0
- data/config/initializers/scheduled_jobs.rb +8 -0
- data/config/locales/en.yml +150 -0
- data/config/routes.rb +25 -0
- data/lib/tasks/verify.rake +16 -0
- data/lib/workarea/mailer_previews/storefront/review_mailer_preview.rb +10 -0
- data/lib/workarea/reviews.rb +13 -0
- data/lib/workarea/reviews/engine.rb +16 -0
- data/lib/workarea/reviews/version.rb +5 -0
- data/package.json +9 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +55 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +5 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/factories/reviews.rb +32 -0
- data/test/fixtures/reviews.csv +5 -0
- data/test/helpers/workarea/storefront/reviews_helper_test.rb +20 -0
- data/test/integration/workarea/admin/reviews_integration_test.rb +37 -0
- data/test/integration/workarea/storefront/review_requests_integration_test.rb +63 -0
- data/test/integration/workarea/storefront/reviews_integration_test.rb +82 -0
- data/test/javascripts/fixtures/product_review_ajax_submit.html.haml +4 -0
- data/test/javascripts/product_review_ajax_submit_spec.js +28 -0
- data/test/javascripts/spec_helper.js +23 -0
- data/test/models/workarea/insights/most_active_reviewers_test.rb +32 -0
- data/test/models/workarea/insights/most_reviewed_products_test.rb +32 -0
- data/test/models/workarea/insights/top_rated_products_test.rb +49 -0
- data/test/models/workarea/review/request_test.rb +18 -0
- data/test/models/workarea/review_test.rb +105 -0
- data/test/models/workarea/search/storefront/product_test.decorator +14 -0
- data/test/queries/workarea/reports/reviews_by_product_test.rb +104 -0
- data/test/queries/workarea/reports/reviews_by_user_test.rb +102 -0
- data/test/queries/workarea/review_request_params_test.rb +64 -0
- data/test/services/workarea/create_review_test.rb +131 -0
- data/test/system/workarea/admin/review_system_test.rb +96 -0
- data/test/system/workarea/admin/reviews_by_product_system_test.rb +60 -0
- data/test/system/workarea/storefront/review_request_system_test.rb +34 -0
- data/test/system/workarea/storefront/review_system_test.rb +113 -0
- data/test/teaspoon_env.rb +10 -0
- data/test/test_helper.rb +11 -0
- data/test/workers/workarea/create_review_requests_test.rb +38 -0
- data/test/workers/workarea/schedule_review_requests_test.rb +115 -0
- data/test/workers/workarea/send_review_requests_test.rb +30 -0
- data/workarea-reviews.gemspec +22 -0
- data/yarn.lock +3265 -0
- 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,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
|