Skip to content

Commit

Permalink
spree-4-5-0-only-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
panhachom committed Mar 29, 2024
1 parent 36ef280 commit e0e49ba
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
16 changes: 11 additions & 5 deletions app/controllers/spree/admin/reviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/spree/feedback_review.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/review.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/reviews/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render 'spree/shared/error_messages', target: @review %>
<%= render 'spree/admin/shared/error_messages', target: @review %>

<div class="form-group">
<%= f.label :name %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/reviews/edit.html.erb
Original file line number Diff line number Diff line change
@@ -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| %>
Expand Down
17 changes: 13 additions & 4 deletions app/views/spree/admin/reviews/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="col-md-6">
<div class="form-group">
<%= label_tag :q_name_cont, Spree::Review.human_attribute_name(:user) %>
<%= f.text_field :name_cont, size: 25, class: 'form-control' %>
<%= f.text_field :name_cont, size: 25, class: 'form-control js-quick-search-target js-filterable' %>
</div>
</div>

Expand Down Expand Up @@ -55,8 +55,8 @@
<table class="table" id="listing_reviews">
<thead>
<tr>
<th><%= sort_link @search, :product, Spree.t(:product) %></th>
<th><%= sort_link @search, :rating, Spree::Review.human_attribute_name(:rating) %></th>
<th colspan= '2'><%= sort_link @search, :product, Spree.t(:product) %></th>
<th ><%= sort_link @search, :rating, Spree::Review.human_attribute_name(:rating) %></th>
<th><%= Spree.t(:feedback) %></th>
<th><%= sort_link @search, :user, Spree::Review.human_attribute_name(:user) %></th>
<th><%= sort_link @search, :ip_address, Spree::Review.human_attribute_name(:ip_address) %></th>
Expand All @@ -67,7 +67,16 @@
<tbody>
<% @reviews.each do |review| %>
<tr data-hook="admin_reviews_index_rows" id="<%= dom_id review %>" class="<%= cycle('odd', 'even') %>">
<td><%= link_to_if review.product, review.product.name, product_path(review.product) %></td>
<td scope="row" class="image">
<%= link_to edit_admin_product_path(review.product) do %>
<%= small_image review.product %>
<% end %>
</td>
<td >
<%= link_to review.product.name, edit_admin_product_path(review.product) %>
<br />
<small><%= review.product.sku rescue '' %></small>
</td>
<td><%= txt_stars(review.rating) %></td>
<td><%= link_to "(#{review.feedback_stars}/#{review.feedback_reviews.size})", admin_review_feedback_reviews_path(review) %></td>
<td><%= review.user_id ? link_to(review.user.try(:email), admin_user_path(review.user)) : Spree.t(:anonymous) %></td>
Expand Down
1 change: 0 additions & 1 deletion spree_reviews.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit e0e49ba

Please sign in to comment.