spree_zoned 0.5.12 → 0.5.13
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/admin/zoned.js +14 -8
- data/app/controllers/spree/admin/products_controller_decorator.rb +66 -0
- data/app/controllers/spree/admin/zoned_controller.rb +15 -0
- data/app/controllers/spree/products_controller_decorator.rb +7 -6
- data/config/initializers/zoned_init.rb +1 -0
- data/config/routes.rb +1 -0
- data/lib/spree/zoned/search/base.rb +1 -0
- data/spree_zoned.gemspec +1 -1
- metadata +2 -2
@@ -1,12 +1,18 @@
|
|
1
1
|
$(function () {
|
2
|
-
if (
|
2
|
+
if (location.href.match(/\/admin\/products$/))
|
3
3
|
{
|
4
|
-
$("
|
5
|
-
|
4
|
+
if ($("#sel-prd-country").data("prd-country") == 0)
|
5
|
+
{
|
6
|
+
$("#listing_products").removeClass("sortable");
|
7
|
+
$(".handle").hide();
|
8
|
+
$(".delfromcountry").hide();
|
9
|
+
}
|
10
|
+
else
|
11
|
+
{
|
12
|
+
$("#listing_products").addClass("sortable");
|
13
|
+
$("#listing_products").attr("data-sortable-link", "/admin/products/reorder");
|
14
|
+
$(".handle").show();
|
15
|
+
$(".delfromcountry").show();
|
16
|
+
}
|
6
17
|
}
|
7
|
-
else
|
8
|
-
{
|
9
|
-
$(".handle").show();
|
10
|
-
$(".delfromcountry").show();
|
11
|
-
}
|
12
18
|
});
|
@@ -10,6 +10,72 @@ Spree::Admin::ProductsController.class_eval do
|
|
10
10
|
|
11
11
|
protected
|
12
12
|
|
13
|
+
#
|
14
|
+
# Copied from spree_core-1.1.1/app/controllers/spree/admin/products_controller.rb
|
15
|
+
#
|
16
|
+
# changes are marked using "{ CHANGE" and "CHANGE }"
|
17
|
+
#
|
18
|
+
def collection
|
19
|
+
return @collection if @collection.present?
|
20
|
+
#
|
21
|
+
# Inserted retrieval of country from session
|
22
|
+
# { CHANGE
|
23
|
+
country = session[:zoned] && session[:zoned][:prd_country]
|
24
|
+
# CHANGE }
|
25
|
+
unless request.xhr?
|
26
|
+
params[:q] ||= {}
|
27
|
+
params[:q][:deleted_at_null] ||= "1"
|
28
|
+
|
29
|
+
#
|
30
|
+
# Appended unless clause
|
31
|
+
# { CHANGE
|
32
|
+
params[:q][:s] ||= "name asc" unless country && country.to_i != 0
|
33
|
+
# CHANGE }
|
34
|
+
|
35
|
+
@search = super.search(params[:q])
|
36
|
+
#
|
37
|
+
# Inserted query when country given
|
38
|
+
# { CHANGE
|
39
|
+
if country && country.to_i != 0
|
40
|
+
@collection = @search.result.
|
41
|
+
joins(
|
42
|
+
'LEFT OUTER JOIN spree_zoned_products ON spree_zoned_products.spree_product_id = spree_products.id' +
|
43
|
+
" AND spree_zoned_products.spree_country_id = #{country}").where(
|
44
|
+
'(spree_zoned_products.orderno IS NULL OR spree_zoned_products.orderno >= 0)').
|
45
|
+
order('spree_zoned_products.orderno').
|
46
|
+
includes([:master, {:variants => [:images, :option_values]}]).
|
47
|
+
page(params[:page]).
|
48
|
+
per(Spree::Config[:admin_products_per_page])
|
49
|
+
else
|
50
|
+
# CHANGE }
|
51
|
+
@collection = @search.result.
|
52
|
+
group_by_products_id.
|
53
|
+
includes([:master, {:variants => [:images, :option_values]}]).
|
54
|
+
page(params[:page]).
|
55
|
+
per(Spree::Config[:admin_products_per_page])
|
56
|
+
# Inserted end (for if) + made params[:q][:s].include? nil-resistant
|
57
|
+
# { CHANGE
|
58
|
+
end
|
59
|
+
if params[:q][:s] && params[:q][:s].include?("master_price")
|
60
|
+
# CHANGE }
|
61
|
+
# By applying the group in the main query we get an undefined method gsub for Arel::Nodes::Descending
|
62
|
+
# It seems to only work when the price is actually being sorted in the query
|
63
|
+
# To be investigated later.
|
64
|
+
@collection = @collection.group("spree_variants.price")
|
65
|
+
end
|
66
|
+
else
|
67
|
+
includes = [{:variants => [:images, {:option_values => :option_type}]}, {:master => :images}]
|
68
|
+
|
69
|
+
@collection = super.where(["name #{LIKE} ?", "%#{params[:q]}%"])
|
70
|
+
@collection = @collection.includes(includes).limit(params[:limit] || 10)
|
71
|
+
|
72
|
+
tmp = super.where(["#{Variant.table_name}.sku #{LIKE} ?", "%#{params[:q]}%"])
|
73
|
+
tmp = tmp.includes(:variants_including_master).limit(params[:limit] || 10)
|
74
|
+
@collection.concat(tmp)
|
75
|
+
end
|
76
|
+
@collection
|
77
|
+
end
|
78
|
+
|
13
79
|
def inorout(m)
|
14
80
|
country = session[:zoned] && session[:zoned][:prd_country]
|
15
81
|
m.call(country.to_i) if country
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Spree
|
2
2
|
module Admin
|
3
3
|
class ZonedController < BaseController
|
4
|
+
|
4
5
|
def setcountry
|
5
6
|
respond_to do |format|
|
6
7
|
format.js do
|
@@ -9,6 +10,20 @@ module Spree
|
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
13
|
+
|
14
|
+
def reorder
|
15
|
+
country = session[:zoned] && session[:zoned][:prd_country]
|
16
|
+
return if !country || country.to_i >= 0
|
17
|
+
country = country.to_i
|
18
|
+
params[:positions].each do |id, index|
|
19
|
+
Spree::Zoned::Product.find_or_create_by_spree_product_id_and_spree_country_id(id, country).update_attributes :orderno => index.to_i
|
20
|
+
end
|
21
|
+
respond_to do |format|
|
22
|
+
format.html { redirect_to admin_products_url }
|
23
|
+
format.js { render :text => 'Ok' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
12
27
|
end
|
13
28
|
end
|
14
29
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Spree
|
2
2
|
ProductsController.class_eval do
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
def index
|
5
|
+
p = params ? params : {}
|
6
|
+
country = session[:zoned] && session[:zoned][:current_country]
|
7
|
+
@searcher = Spree::Config.searcher_class.new(p.merge(country ? {zoned_country: country} : {}))
|
8
|
+
@products = @searcher.retrieve_products
|
9
|
+
respond_with(@products)
|
10
|
+
end
|
10
11
|
|
11
12
|
end
|
12
13
|
end
|
data/config/routes.rb
CHANGED
@@ -2,6 +2,7 @@ Spree::Core::Engine.routes.draw do
|
|
2
2
|
match '/zonedcs' => "zoned#setcountry"
|
3
3
|
namespace :admin do
|
4
4
|
match '/zonedcs' => "zoned#setcountry"
|
5
|
+
match '/products/reorder' => "zoned#reorder", :via => :post
|
5
6
|
match '/products/:id/zoneddfc' => "products#deletefc", :via => :delete
|
6
7
|
match '/products/:id/zonedbtc' => "products#backtocountry", :via => :put
|
7
8
|
end
|
@@ -46,6 +46,7 @@ module Spree
|
|
46
46
|
base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
|
47
47
|
base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
|
48
48
|
base_scope = add_search_scopes(base_scope)
|
49
|
+
base_scope = base_scope.order('spree_zoned_products.orderno') if country
|
49
50
|
base_scope
|
50
51
|
end
|
51
52
|
|
data/spree_zoned.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.name = 'spree_zoned'
|
5
|
-
s.version = '0.5.
|
5
|
+
s.version = '0.5.13'
|
6
6
|
s.summary = 'A Spree extension to make your store zoned'
|
7
7
|
s.description = "Everything you need for a zoned Spree store: zoned pricing, zoned products, zoned product ordering, zoned locales, ...\nProbalbly essential to you if you operate outside of the US."
|
8
8
|
s.required_ruby_version = '>= 1.9.2'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_zoned
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spree_core
|