Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to spree 4.1 #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ appraise 'spree-3-7' do
gem 'rails-controller-testing', '~> 1.0.1'
end

appraise 'spree-4-1' do
gem 'spree', '~> 4.1.0'
gem 'spree_auth_devise', '~> 4.2'
gem 'rails-controller-testing'
end

appraise 'spree-master' do
gem 'spree', github: 'spree/spree', branch: 'master'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class FavoriteProductsController < Spree::Admin::BaseController

def index
@search = Spree::Product.favorite.search(params[:q])
@favorite_products = @search.result.includes(master: :images).joins(:master).order_by_favorite_users_count(sort_in_ascending_users_count?).page(params[:page]).per(Spree::Config.favorite_products_per_page)
@favorite_products = @search.result.includes(master: :images).joins(:master).order_by_favorite_users_count(sort_in_ascending_users_count?).page(params[:page]).per(Spree::AppConfiguration.new.favorite_products_per_page)
end

def destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class FavoriteVariantsController < Spree::Admin::BaseController

def index
@search = Spree::Variant.favorite.search(params[:q])
@favorite_variants = @search.result.includes(:product, :images).joins(:product).order_by_favorite_users_count(sort_in_ascending_users_count?).page(params[:page]).per(Spree::Config.favorite_products_per_page)
@favorite_variants = @search.result.includes(:product, :images).joins(:product).order_by_favorite_users_count(sort_in_ascending_users_count?).page(params[:page]).per(Spree::AppConfiguration.new.favorite_products_per_page)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def set_variant
end

def set_favorite_product_users
@favorite_product_users = @product.favorite_users.page(params[:favorite_product_users_page]).per(Spree::Config.favorite_users_per_page)
@favorite_product_users = @product.favorite_users.page(params[:favorite_product_users_page]).per(Spree::AppConfiguration.new.favorite_users_per_page)
end

def set_favorite_variant_users(id)
Expand Down
9 changes: 9 additions & 0 deletions app/models/spree/app_configuration_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# module SpreeFavoriteProducts::AppConfigurationDecorator
# def self.prepended(base)
# base.preference :favorite_products_per_page, :integer, default: 10
# base.preference :favorite_users_per_page, :integer, default: 10
# end
# end

# ::Spree::AppConfiguration.prepend(SpreeFavoriteProducts::AppConfigurationDecorator)

Spree::AppConfiguration.class_eval do
preference :favorite_products_per_page, :integer, default: 10
preference :favorite_users_per_page, :integer, default: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="col-md-6">
<div class="form-group" data-hook="admin_general_setting_favorite_products_per_page">
<%= label_tag :favorite_products_per_page, Spree.t(:favorite_products_per_page) %>
<%= text_field_tag :favorite_products_per_page, Spree::Config[:favorite_products_per_page], size: 3 %>
<%= text_field_tag :favorite_products_per_page, Spree::AppConfiguration.new[:favorite_products_per_page], size: 3 %>
</div>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions app/overrides/add_link_to_mark_product_as_favorite.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Deface::Override.new(
virtual_path: 'spree/products/show',
name: 'add_link_to_mark_product_as_favorite',
surround_contents: "h1[itemprop='name']",
insert_before: "div#cart-form",
text: %Q{
<%= render_original %>
<% if spree_user_signed_in? && spree_current_user.has_favorite_product?(@product.id) %>
<%= link_to Spree.t(:unmark_as_favorite), favorite_product_path(id: @product.id, type: 'Spree::Product'), method: :delete, remote: true, class: 'favorite_link btn btn-primary pull-right', id: 'unmark-as-favorite' %>
<% else %>
Expand Down
23 changes: 16 additions & 7 deletions app/overrides/add_link_to_users_favorite_products.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
Deface::Override.new(
virtual_path: "spree/shared/_main_nav_bar",
name: "add_link_to_users_favorite_products",
insert_after: "#home-link",
text: "<% if spree_current_user %><li><%= link_to 'Favorite Products', favorite_products_path %></li><% end %>",
sequence: { before: "auth_shared_login_bar"}
)
if Spree.version.to_f > 4.0
Deface::Override.new(
virtual_path: "spree/shared/_link_to_account",
name: "add_link_to_users_favorite_products",
insert_after: "erb[loud]:contains('spree.account_path')",
text: "<% if spree_current_user %><li><%= link_to Spree.t('favorite_product_uppercase'), favorite_products_path , class: 'dropdown-item' %></li><% end %>"
)
else
Deface::Override.new(
virtual_path: "spree/shared/_main_nav_bar",
name: "add_link_to_users_favorite_products",
insert_after: "#home-link",
text: "<% if spree_current_user %><li><%= link_to 'Favorite Products', favorite_products_path %></li><% end %>",
sequence: { before: "auth_shared_login_bar"}
)
end

1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ en:
variant_does_not_exist: Variant does not exist
save_for_later: Save For Later
product_not_found: Product Not Found
favorite_product_uppercase: "FAVORITE PRODUCTS"
9 changes: 9 additions & 0 deletions gemfiles/spree_4_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "spree", "~> 4.1.0"
gem "spree_auth_devise", "~> 4.2"
gem "rails-controller-testing"

gemspec path: "../"
2 changes: 1 addition & 1 deletion spree_favorite_products.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

spree_version = '>= 3.2.0', '< 4.0.0'
spree_version = '>= 3.2.0'

s.add_dependency 'spree_core', spree_version
s.add_dependency 'spree_extension', '~> 0.0.5'
Expand Down