caboose-store 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTk1OGJkNDlmMmYyZjdiZDk4OTk4NzA3NjFjMzRiYjIzZDVjODAyYw==
4
+ YzRiY2ZkM2YyMTkwNmVmYWI4ZjMyYzkwNDhjZDk3MTM0ZmE4NzgwZg==
5
5
  data.tar.gz: !binary |-
6
- OTg4ZTI2NWY0NGM0YzYyYzNjNTc1YTNkY2NiYjM1MGI1NzA1OWE5Yw==
6
+ NTlmOTFlMGQwZDcxMjYxZTRlYTRiY2UwMDFhOThhYWIwNTUwYTdmMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NThlNTI5M2ZlNDMzMzZhYWI4MWI2OWMwNjViNDAyNmRkYmUwZWM2ZDY3YThk
10
- NDJiZWUwOTdmNjQ0MWUwZTAxYTQ0MDQwOGM0MGViZGI1NTllNDQzOGEwNDZi
11
- OTg5MzgzZTJlZWExZGE0ODQzOTE0ZGMxN2ZhNjQxNGM4NDRiMDY=
9
+ OWU3OWM3ZWYzMzBkYzE1MjJmYzdhOTdiMjgwMzFhOTU5ZWUwZmQ4ZjJjODk3
10
+ YmE4YTU3MDAzYjdjYzRiYWQ3M2I4NjdlMDg2MWI1ZjI4NTQ1NmExODk0N2Zl
11
+ NGYzNzA0ZDZlY2YyOTdkNDgyNTg5NzVkMTAxNzIyNTNlZTIyYjA=
12
12
  data.tar.gz: !binary |-
13
- YzNkMzM4OGQzZjE2ZDc3M2UzNmFkMGU4YWZlZWNlNDYyMzM4ZDIyMDU1MTg4
14
- ZDhlYzExZTExZWFkMzdhODRhODVjNDQ3N2VhMGIxNGU1ZjI5YjFjNDFjNTM2
15
- MDJhOWJlMDg2MmM5NTI0ZjkzOWFiMTFiNzIxYTZiMDI3NDMxNDQ=
13
+ OTZjNWFlNDE0YzVmOTNjN2JlYTRjYmQ5MTNiNTYyMGQyN2EzNjhmZTFmYjZl
14
+ YmJiYzAwNzE2ZWI0OTMzMzBlOTlkYjg0Y2I2ZWExNDhlOWJiNzZmZDNkNTIx
15
+ OGY5NDk5NjdlMWQ4NmJiYjAzM2M0YWFkMTEwYzVkNzAxYTVmYTQ=
@@ -3,59 +3,52 @@ module CabooseStore
3
3
 
4
4
  # GET /products/
5
5
  def index
6
- @category = Category.where(:url => request.fullpath).first
7
- @review = Review.new
8
-
9
- if @category.nil?
10
- if params[:id].nil? || !Product.exists?(params[:id])
11
-
12
- @gen = Caboose::PageBarGenerator.new(params, {
13
- 'title_like' => '',
14
- 'id' => ''
15
- },{
16
- 'model' => 'CabooseStore::Product',
17
- 'sort' => 'title',
18
- 'desc' => false,
19
- 'base_url' => '/admin/products'
20
- })
21
- @products = @gen.items
22
- render 'caboose_store/products/search'
23
-
24
- else
25
-
26
- @product = Product.find(params[:id])
27
-
28
- if @product.status == 'Inactive'
29
- render 'products/not_available'
30
- return
31
- end
32
- @reviews = Review.where(:product_id => @product.id).limit(10).order("id DESC") || nil
33
- @is_logged_in = logged_in?
34
- if @is_logged_in
35
- #@order.customer_id = logged_in_user.id
36
- #@order.save
37
- @first_name = logged_in_user.first_name
38
- @last_name = logged_in_user.last_name
39
- end
40
-
41
- all_reviews = Review.where(:product_id => @product.id)
42
- score = 0
43
- count = 0
44
- all_reviews.each do |r|
45
- if r.rating && r.rating != 0
46
- score += r.rating
47
- count += 1
48
- end
49
- end
50
- if count > 0
51
- @average = score / count
52
- else
53
- @average = 0
54
- end
55
-
56
- render 'caboose_store/products/details'
6
+ @category = Category.exists?(:url => request.fullpath) ? Category.where(:url => request.fullpath).first : nil
7
+
8
+ # If looking at single item
9
+ if @category.nil? && params[:id] && Product.exists?(params[:id])
10
+ @product = Product.find(params[:id])
11
+
12
+ if @product.status == 'Inactive'
13
+ render 'products/not_available'
14
+ return
57
15
  end
16
+
17
+ @review = Review.new
18
+ @reviews = Review.where(:product_id => @product.id).limit(10).order("id DESC") || nil
19
+ @logged_in_user = logged_in_user
20
+
21
+ render 'caboose_store/products/details'
22
+ return
58
23
  end
24
+
25
+ # Otherwise looking at a category or search parameters
26
+ @pager = Caboose::Pager.new(params, {
27
+ 'category_id' => @category ? @category.id : '',
28
+ 'title_like' => '',
29
+ 'description_like' => '',
30
+ 'vendor_id' => '',
31
+ 'price_gte' => '',
32
+ 'price_lte' => '',
33
+ 'sku_like' => ''
34
+ },{
35
+ 'model' => 'CabooseStore::Product',
36
+ 'includes' => {
37
+ 'category_id' => ['categories' , 'id' ],
38
+ 'price_gte' => ['variants' , 'price' ],
39
+ 'price_lte' => ['variants' , 'price' ],
40
+ 'sku_like' => ['variants' , 'sku' ]
41
+ },
42
+ 'sort' => 'title',
43
+ 'desc' => false,
44
+ 'base_url' => '/products'
45
+ })
46
+ @products = @pager.items
47
+
48
+ @filter = SearchFilter.exists?(:url => request.fullpath) ?
49
+ SearchFilter.where(:url => request.fullpath).first :
50
+ SearchFilter.create_from_url(request.fullpath, @pager)
51
+
59
52
  end
60
53
 
61
54
  def show
@@ -2,12 +2,12 @@ module CabooseStore
2
2
  class Product < ActiveRecord::Base
3
3
  self.table_name = "store_products"
4
4
 
5
- belongs_to :vendor
6
- has_many :categories, :through => :category_memberships
7
- has_many :category_memberships
8
- has_many :variants
9
- has_many :product_images
10
- has_many :reviews
5
+ belongs_to :vendor, :class_name => 'CabooseStore::Vendor'
6
+ has_many :categories, :through => :category_memberships, :class_name => 'CabooseStore::Category'
7
+ has_many :category_memberships , :class_name => 'CabooseStore::CategoryMembership'
8
+ has_many :variants , :class_name => 'CabooseStore::Variant'
9
+ has_many :product_images , :class_name => 'CabooseStore::ProductImage'
10
+ has_many :reviews , :class_name => 'CabooseStore::Review'
11
11
 
12
12
  attr_accessible :id,
13
13
  :title,
@@ -1,6 +1,17 @@
1
1
 
2
2
  class CabooseStore::Schema < Caboose::Utilities::Schema
3
-
3
+
4
+ def self.removed_columns
5
+ {
6
+ CabooseStore::SearchFilter => [
7
+ :option1_values,
8
+ :option2_values,
9
+ :option3_values,
10
+ :category
11
+ ]
12
+ }
13
+ end
14
+
4
15
  def self.schema
5
16
  {
6
17
  CabooseStore::Category => [
@@ -110,10 +121,20 @@ class CabooseStore::Schema < Caboose::Utilities::Schema
110
121
  [ :date_available , :datetime ]
111
122
  ],
112
123
  CabooseStore::Review => [
113
- [ :product_id , :integer ],
114
- [ :content , :string ],
115
- [ :name , :string ],
116
- [ :rating , :decimal ]
124
+ [ :product_id , :integer ],
125
+ [ :content , :string ],
126
+ [ :name , :string ],
127
+ [ :rating , :decimal ]
128
+ ],
129
+ CabooseStore::SearchFilter => [
130
+ [ :url , :string ],
131
+ [ :title_like , :string ],
132
+ [ :categories , :text ],
133
+ [ :vendors , :text ],
134
+ [ :option1 , :text ],
135
+ [ :option2 , :text ],
136
+ [ :option3 , :text ],
137
+ [ :prices , :text ]
117
138
  ],
118
139
  CabooseStore::Variant => [
119
140
  [ :sku , :string ],
@@ -0,0 +1,125 @@
1
+ require 'json'
2
+
3
+ module CabooseStore
4
+ class SearchFilter < ActiveRecord::Base
5
+
6
+ self.table_name = "store_search_filters"
7
+ attr_accessible :id,
8
+ :url,
9
+ :title_like,
10
+ :categories,
11
+ :vendors,
12
+ :option1,
13
+ :option2,
14
+ :option3,
15
+ :prices
16
+
17
+ before_save :json_encode
18
+ after_initialize :json_decode
19
+
20
+ def json_encode
21
+ self.categories = self.categories.to_json if !self.categories.nil?
22
+ self.vendors = self.vendors.to_json if !self.vendors.nil?
23
+ self.option1 = self.option1.to_json if !self.option1.nil?
24
+ self.option2 = self.option2.to_json if !self.option2.nil?
25
+ self.option3 = self.option3.to_json if !self.option3.nil?
26
+ self.prices = self.prices.to_json if !self.prices.nil?
27
+ end
28
+
29
+ def json_decode
30
+ self.categories = JSON.parse(self.categories).collect{ |hash| Caboose::StdClass.new(hash) } if !self.categories.nil?
31
+ self.vendors = JSON.parse(self.vendors ).collect{ |hash| Caboose::StdClass.new(hash) } if !self.vendors.nil?
32
+ self.option1 = JSON.parse(self.option1 ) if !self.option1.nil?
33
+ self.option2 = JSON.parse(self.option2 ) if !self.option2.nil?
34
+ self.option3 = JSON.parse(self.option3 ) if !self.option3.nil?
35
+ self.prices = JSON.parse self.prices if !self.prices.nil?
36
+
37
+ Caboose.log(self.option1)
38
+ end
39
+
40
+ def self.create_from_url(url, pager)
41
+
42
+ f = SearchFilter.new
43
+ f.url = url
44
+
45
+ url2 = url.split("?")[0]
46
+ f.categories = nil
47
+ if Category.exists?(:url => url2)
48
+ parent = Category.where(:url => url2).first
49
+ if parent.children && parent.children.count > 0
50
+ f.categories = []
51
+ parent.children.each { |cat| f.categories << Caboose::StdClass.new({ 'id' => cat.id, 'name' => cat.name }) }
52
+ end
53
+ end
54
+
55
+ vendor_ids = []
56
+ option1 = Caboose::StdClass.new({ 'name' => [], 'values' => [] })
57
+ option2 = Caboose::StdClass.new({ 'name' => [], 'values' => [] })
58
+ option3 = Caboose::StdClass.new({ 'name' => [], 'values' => [] })
59
+ min = 0.0
60
+ max = 1000000.0
61
+
62
+ prices = [
63
+ [ 0, 10],
64
+ [ 10, 25],
65
+ [ 25, 50],
66
+ [ 50, 75],
67
+ [ 75, 100],
68
+ [ 100, 150],
69
+ [ 150, 200],
70
+ [ 200, 250],
71
+ [ 250, 300],
72
+ [ 300, 400],
73
+ [ 400, 500],
74
+ [ 500, 1000],
75
+ [ 1000, 2000],
76
+ [ 2000, 3000],
77
+ [ 4000, 5000],
78
+ [ 7000, 7500],
79
+ [ 7500, 10000],
80
+ [10000, 50000]
81
+ ]
82
+ price_counts = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
83
+
84
+ pager.all_items.each do |p|
85
+ vendor_ids << p.vendor_id
86
+ option1.name << p.option1
87
+ option2.name << p.option2
88
+ option3.name << p.option3
89
+ p.variants.each do |v|
90
+ option1.values << v.option1
91
+ option2.values << v.option2
92
+ option3.values << v.option3
93
+ min = v.price if v.price < min
94
+ max = v.price if v.price > max
95
+ prices.each_index do |i|
96
+ minmax = prices[i]
97
+ price_counts[i] = price_counts[i] + 1 if v.price > minmax[0] && v.price < minmax[1]
98
+ end
99
+ end
100
+ end
101
+
102
+ vendor_ids = vendor_ids ? vendor_ids.compact.uniq : nil
103
+ f.vendors = vendor_ids && vendor_ids.count > 0 ? vendor_ids.collect { |vid| Vendor.find(vid) } : nil
104
+
105
+ option1.name = option1.name ? option1.name.compact.uniq : nil
106
+ option2.name = option2.name ? option2.name.compact.uniq : nil
107
+ option3.name = option3.name ? option3.name.compact.uniq : nil
108
+
109
+ f.option1 = option1.name && option1.name.count == 1 ? Caboose::StdClass.new({ 'name' => option1.name[0], 'values' => option1.values.compact.uniq.sort }) : nil
110
+ f.option2 = option2.name && option2.name.count == 1 ? Caboose::StdClass.new({ 'name' => option2.name[0], 'values' => option2.values.compact.uniq.sort }) : nil
111
+ f.option3 = option3.name && option3.name.count == 1 ? Caboose::StdClass.new({ 'name' => option3.name[0], 'values' => option3.values.compact.uniq.sort }) : nil
112
+
113
+ f.prices = []
114
+ price_counts.each_index do |i|
115
+ f.prices << prices[i] if price_counts[i] > 0
116
+ end
117
+ f.prices = nil if f.prices.count == 0
118
+
119
+ f.save
120
+ return f
121
+
122
+ end
123
+
124
+ end
125
+ end
@@ -1,3 +1,3 @@
1
1
  module CabooseStore
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-07 00:00:00.000000000 Z
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caboose-cms
@@ -91,6 +91,7 @@ files:
91
91
  - app/models/caboose_store/product_image_variant.rb
92
92
  - app/models/caboose_store/review.rb
93
93
  - app/models/caboose_store/schema.rb
94
+ - app/models/caboose_store/search_filter.rb
94
95
  - app/models/caboose_store/shipping_calculator.rb
95
96
  - app/models/caboose_store/states.rb
96
97
  - app/models/caboose_store/tax_calculator.rb