From 60030182da9ef6c9c1fa7b859e19b8208f7a3b2a Mon Sep 17 00:00:00 2001 From: panhachom Date: Wed, 27 Mar 2024 16:38:04 +0700 Subject: [PATCH] spree-4-5-0-only-backend --- .../spree/admin/reviews_controller.rb | 16 ++++++++++----- app/models/spree/feedback_review.rb | 4 ++-- app/models/spree/review.rb | 2 +- app/views/spree/admin/reviews/_form.html.erb | 2 +- app/views/spree/admin/reviews/edit.html.erb | 2 +- app/views/spree/admin/reviews/index.html.erb | 20 +++++++++++++------ spree_reviews.gemspec | 1 - 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/app/controllers/spree/admin/reviews_controller.rb b/app/controllers/spree/admin/reviews_controller.rb index 375c4a62..e311f4f9 100644 --- a/app/controllers/spree/admin/reviews_controller.rb +++ b/app/controllers/spree/admin/reviews_controller.rb @@ -8,14 +8,20 @@ def index end def approve + review = Spree::Review.find(params[:id]) - if review.update_attribute(:approved, true) - flash[:notice] = Spree.t(:info_approve_review) - else - flash[:error] = Spree.t(:error_approve_review) - end + + ActiveRecord::Base.connected_to(role: :writing) do + + if review.update_attribute(:approved, true) + flash[:notice] = Spree.t(:info_approve_review) + else + flash[:error] = Spree.t(:error_approve_review) + end redirect_to admin_reviews_path + + end end def edit diff --git a/app/models/spree/feedback_review.rb b/app/models/spree/feedback_review.rb index 0ba02d89..c05fe091 100644 --- a/app/models/spree/feedback_review.rb +++ b/app/models/spree/feedback_review.rb @@ -1,7 +1,7 @@ class Spree::FeedbackReview < ActiveRecord::Base belongs_to :user, class_name: Spree.user_class.to_s - belongs_to :review, dependent: :destroy - + belongs_to :review + validates :review, presence: true validates :rating, numericality: { only_integer: true, diff --git a/app/models/spree/review.rb b/app/models/spree/review.rb index 6ec56bda..5122129d 100644 --- a/app/models/spree/review.rb +++ b/app/models/spree/review.rb @@ -1,7 +1,7 @@ class Spree::Review < ActiveRecord::Base belongs_to :product, touch: true belongs_to :user, class_name: Spree.user_class.to_s - has_many :feedback_reviews + has_many :feedback_reviews , dependent: :destroy after_save :recalculate_product_rating, if: :approved? after_destroy :recalculate_product_rating diff --git a/app/views/spree/admin/reviews/_form.html.erb b/app/views/spree/admin/reviews/_form.html.erb index eb4c25bc..461de78d 100644 --- a/app/views/spree/admin/reviews/_form.html.erb +++ b/app/views/spree/admin/reviews/_form.html.erb @@ -1,4 +1,4 @@ -<%= render 'spree/shared/error_messages', target: @review %> +<%= render 'spree/admin/shared/error_messages', target: @review %>
<%= f.label :name %> diff --git a/app/views/spree/admin/reviews/edit.html.erb b/app/views/spree/admin/reviews/edit.html.erb index 6413e254..c7a7677c 100644 --- a/app/views/spree/admin/reviews/edit.html.erb +++ b/app/views/spree/admin/reviews/edit.html.erb @@ -1,5 +1,5 @@ <% content_for :page_title do %> - <%= Spree.t(:editing_review_for_html, link: link_to(@review.product.name, product_path(@review.product))) %> + <%= Spree.t(:editing_review_for_html, link: link_to(@review.product.name, edit_admin_product_path(@review.product))) %> <% end %> <%= form_for [:admin, @review] do |f| %> diff --git a/app/views/spree/admin/reviews/index.html.erb b/app/views/spree/admin/reviews/index.html.erb index 6ff82328..f2c6a246 100644 --- a/app/views/spree/admin/reviews/index.html.erb +++ b/app/views/spree/admin/reviews/index.html.erb @@ -14,8 +14,8 @@
- <%= label_tag :q_name_cont, Spree::Review.human_attribute_name(:user) %> - <%= f.text_field :name_cont, size: 25, class: 'form-control' %> + <%= label_tag :q_name_cont, Spree::Review.human_attribute_name(:product_name) %> + <%= f.text_field :name_cont, size: 25, class: 'form-control js-quick-search-target js-filterable' %>
@@ -49,14 +49,13 @@
<% end %> -<%= render 'spree/admin/shared/index_table_options', collection: @reviews %> <% if @reviews.any? %> - - + + @@ -67,7 +66,16 @@ <% @reviews.each do |review| %> - + + diff --git a/spree_reviews.gemspec b/spree_reviews.gemspec index 045a2ff3..e62aadf8 100644 --- a/spree_reviews.gemspec +++ b/spree_reviews.gemspec @@ -24,7 +24,6 @@ Gem::Specification.new do |s| s.add_dependency 'deface', '~> 1.0' s.add_dependency 'spree_api', spree_version s.add_dependency 'spree_backend', spree_version - s.add_dependency 'spree_frontend', spree_version s.add_dependency 'spree_core', spree_version s.add_dependency 'spree_extension'
<%= sort_link @search, :product, Spree.t(:product) %><%= sort_link @search, :rating, Spree::Review.human_attribute_name(:rating) %><%= sort_link @search, :product, Spree.t(:product) %><%= sort_link @search, :rating, Spree::Review.human_attribute_name(:rating) %> <%= Spree.t(:feedback) %> <%= sort_link @search, :user, Spree::Review.human_attribute_name(:user) %> <%= sort_link @search, :ip_address, Spree::Review.human_attribute_name(:ip_address) %>
<%= link_to_if review.product, review.product.name, product_path(review.product) %> + <%= link_to edit_admin_product_path(review.product) do %> + <%= small_image review.product %> + <% end %> + + <%= link_to review.product.name, edit_admin_product_path(review.product) %> +
+ <%= review.product.sku rescue '' %> +
<%= 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) %>