caboose-store 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/main.js +8 -0
  3. data/app/assets/javascripts/caboose_store/admin.js +0 -19
  4. data/app/assets/javascripts/caboose_store/admin_products.js +3 -4
  5. data/app/assets/javascripts/caboose_store/application.js +6 -5
  6. data/app/assets/javascripts/caboose_store/cart.js.bak +258 -0
  7. data/app/assets/javascripts/caboose_store/checkout.js +151 -0
  8. data/app/assets/javascripts/caboose_store/config.js +83 -0
  9. data/app/assets/javascripts/caboose_store/jquery-ui-multisortable.js +254 -0
  10. data/app/assets/javascripts/caboose_store/jquery-ui.js +3572 -0
  11. data/app/assets/javascripts/caboose_store/main.js +20 -0
  12. data/app/assets/javascripts/caboose_store/modules/cart.js +167 -0
  13. data/app/assets/javascripts/caboose_store/modules/checkout.js +313 -0
  14. data/app/assets/javascripts/caboose_store/modules/product.js +282 -0
  15. data/app/assets/stylesheets/caboose_store/admin.css +3 -3
  16. data/app/assets/stylesheets/caboose_store/application.css +2 -2
  17. data/app/assets/stylesheets/caboose_store/modal.css +1 -0
  18. data/app/assets/templates/caboose_store/cart/add_to_cart.jst.ejs +7 -0
  19. data/app/assets/templates/caboose_store/cart/line_items.jst.ejs +41 -0
  20. data/app/assets/templates/caboose_store/checkout/address.jst.ejs +53 -0
  21. data/app/assets/templates/caboose_store/checkout/forms/guest.jst.ejs +8 -0
  22. data/app/assets/templates/caboose_store/checkout/forms/register.jst.ejs +11 -0
  23. data/app/assets/templates/caboose_store/checkout/forms/signin.jst.ejs +7 -0
  24. data/app/assets/templates/caboose_store/checkout/line_items.jst.ejs +32 -0
  25. data/app/assets/templates/caboose_store/checkout/login.jst.ejs +21 -0
  26. data/app/assets/templates/caboose_store/checkout/payment.jst.ejs +5 -0
  27. data/app/assets/templates/caboose_store/checkout/shipping.jst.ejs +18 -0
  28. data/app/assets/templates/caboose_store/product/images.jst.ejs +8 -0
  29. data/app/assets/templates/caboose_store/product/options.jst.ejs +19 -0
  30. data/app/controllers/caboose_store/application_controller.rb +1 -11
  31. data/app/controllers/caboose_store/cart_controller.rb +36 -44
  32. data/app/controllers/caboose_store/cart_controller.rb.bak +169 -0
  33. data/app/controllers/caboose_store/categories_controller.rb +72 -92
  34. data/app/controllers/caboose_store/checkout_controller.rb +231 -151
  35. data/app/controllers/caboose_store/orders_controller.rb +235 -95
  36. data/app/controllers/caboose_store/product_images_controller.rb +1 -1
  37. data/app/controllers/caboose_store/products_controller.rb +275 -84
  38. data/app/controllers/caboose_store/reviews_controller.rb +1 -1
  39. data/app/controllers/caboose_store/variants_controller.rb +86 -20
  40. data/app/controllers/caboose_store/vendors_controller.rb +73 -0
  41. data/app/helpers/caboose_store/application_helper.rb +3 -41
  42. data/app/helpers/caboose_store/cart_helper.rb +0 -24
  43. data/app/helpers/caboose_store/categories_helper.rb +69 -25
  44. data/app/helpers/caboose_store/checkout_helper.rb +31 -0
  45. data/app/helpers/caboose_store/products_helper.rb +4 -80
  46. data/app/mailers/caboose_store/orders_mailer.rb +6 -13
  47. data/app/models/caboose_store/address.rb +5 -9
  48. data/app/models/caboose_store/caboose_store_plugin.rb +18 -7
  49. data/app/models/caboose_store/category.rb +66 -41
  50. data/app/models/caboose_store/category_membership.rb +1 -2
  51. data/app/models/caboose_store/customization_membership.rb +10 -0
  52. data/app/models/caboose_store/discount.rb +4 -2
  53. data/app/models/caboose_store/line_item.rb +77 -0
  54. data/app/models/caboose_store/message.rb +3 -5
  55. data/app/models/caboose_store/order.rb +153 -63
  56. data/app/models/caboose_store/order_discount.rb +1 -2
  57. data/app/models/caboose_store/order_pdf.rb +2 -4
  58. data/app/models/caboose_store/payment_processors/authorizenet.rb +20 -2
  59. data/app/models/caboose_store/payment_processors/base.rb +0 -2
  60. data/app/models/caboose_store/payment_processors/payscape.rb +91 -1
  61. data/app/models/caboose_store/product.rb +86 -30
  62. data/app/models/caboose_store/product_image.rb +50 -15
  63. data/app/models/caboose_store/product_image_variant.rb +3 -3
  64. data/app/models/caboose_store/review.rb +8 -8
  65. data/app/models/caboose_store/schema.rb +174 -119
  66. data/app/models/caboose_store/search_filter.rb +110 -115
  67. data/app/models/caboose_store/shipping_calculator.rb +51 -49
  68. data/app/models/caboose_store/tax_calculator.rb +2 -6
  69. data/app/models/caboose_store/tax_line.rb +1 -4
  70. data/app/models/caboose_store/variant.rb +77 -21
  71. data/app/models/caboose_store/vendor.rb +17 -2
  72. data/app/views/caboose_store/cart/index.html.erb +3 -18
  73. data/app/views/caboose_store/categories/admin_edit.html.erb +64 -67
  74. data/app/views/caboose_store/categories/admin_index.html.erb +7 -9
  75. data/app/views/caboose_store/categories/admin_new.html.erb +56 -39
  76. data/app/views/caboose_store/checkout/_address_form.html.erb +111 -0
  77. data/app/views/caboose_store/checkout/_billing_form.html.erb +47 -0
  78. data/app/views/caboose_store/checkout/_cart.html.erb +52 -0
  79. data/app/views/caboose_store/checkout/_order_discount.html.erb +40 -0
  80. data/app/views/caboose_store/checkout/_shipping_address.html.erb +10 -0
  81. data/app/views/caboose_store/checkout/_shipping_method.html.erb +2 -0
  82. data/app/views/caboose_store/checkout/_shipping_method_form.html.erb +21 -0
  83. data/app/views/caboose_store/checkout/billing.html.erb +4 -161
  84. data/app/views/caboose_store/checkout/discount.html.erb +5 -160
  85. data/app/views/caboose_store/checkout/empty.html.erb +2 -0
  86. data/app/views/caboose_store/checkout/error.html.erb +2 -0
  87. data/app/views/caboose_store/checkout/index.html.erb +30 -100
  88. data/app/views/caboose_store/checkout/login.html.erb +2 -0
  89. data/app/views/caboose_store/checkout/payment.html.erb +79 -0
  90. data/app/views/caboose_store/checkout/relay.html.erb +12 -0
  91. data/app/views/caboose_store/checkout/relay_postMessage.html.erb +19 -0
  92. data/app/views/caboose_store/checkout/shipping.html.erb +8 -83
  93. data/app/views/caboose_store/checkout/step_one.html.erb +15 -0
  94. data/app/views/caboose_store/checkout/step_two.html.erb +15 -0
  95. data/app/views/caboose_store/checkout/thanks.html.erb +5 -0
  96. data/app/views/caboose_store/layouts/_footer.html.erb +1 -1
  97. data/app/views/caboose_store/orders/admin_edit.html.erb +101 -7
  98. data/app/views/caboose_store/orders/admin_index.html.erb +8 -8
  99. data/app/views/caboose_store/orders_mailer/customer_new_order.html.erb +0 -46
  100. data/app/views/caboose_store/orders_mailer/customer_status_updated.html.erb +0 -48
  101. data/app/views/caboose_store/orders_mailer/fulfillment_new_order.html.erb +0 -42
  102. data/app/views/caboose_store/orders_mailer/shipping_order_ready.html.erb +0 -45
  103. data/app/views/caboose_store/products/_admin_header.html.erb +7 -6
  104. data/app/views/caboose_store/products/_sort_options.html.erb +19 -0
  105. data/app/views/caboose_store/products/admin_add_upcs.html.erb +58 -0
  106. data/app/views/caboose_store/products/admin_edit_categories.html.erb +1 -1
  107. data/app/views/caboose_store/products/admin_edit_description.html.erb +2 -5
  108. data/app/views/caboose_store/products/admin_edit_general.html.erb +58 -1
  109. data/app/views/caboose_store/products/admin_edit_images.html.erb +3 -1
  110. data/app/views/caboose_store/products/admin_edit_variants.html.erb +13 -2
  111. data/app/views/caboose_store/products/admin_edit_variants_single.html.erb +14 -14
  112. data/app/views/caboose_store/products/admin_group_variants.html.erb +433 -0
  113. data/app/views/caboose_store/products/admin_index.html.erb +87 -39
  114. data/app/views/caboose_store/products/admin_sort.html copy.erb +155 -0
  115. data/app/views/caboose_store/products/admin_sort.html.erb +254 -0
  116. data/app/views/caboose_store/products/details.html.erb +1 -2
  117. data/app/views/caboose_store/variants/admin_edit.html.erb +18 -16
  118. data/app/views/caboose_store/variants/admin_group.html.erb +184 -0
  119. data/app/views/caboose_store/vendors/admin_edit.html.erb +24 -0
  120. data/app/views/caboose_store/vendors/admin_index.html.erb +30 -0
  121. data/app/views/caboose_store/vendors/admin_new.html.erb +34 -0
  122. data/config/routes.rb +65 -27
  123. data/lib/caboose-store/caboose_store_helper.rb +29 -30
  124. data/lib/caboose-store/engine.rb +73 -28
  125. data/lib/caboose-store/version.rb +1 -1
  126. data/lib/caboose-store.rb +16 -7
  127. data/lib/tasks/caboose-store.rake +0 -2
  128. metadata +54 -17
  129. data/app/assets/javascripts/caboose_store/modal.js +0 -52
  130. data/app/assets/javascripts/caboose_store/modal_integration.js +0 -25
  131. data/app/assets/javascripts/caboose_store/model.form.page.js +0 -30
  132. data/app/assets/javascripts/caboose_store/model.form.user.js +0 -36
  133. data/app/assets/javascripts/caboose_store/payment_processors/authorizenet.js +0 -21
  134. data/app/assets/javascripts/caboose_store/payment_processors/base.js +0 -21
  135. data/app/assets/javascripts/caboose_store/payment_processors/payscape.js +0 -21
  136. data/app/assets/javascripts/caboose_store/shortcut.js +0 -11
  137. data/app/assets/javascripts/caboose_store/station.js +0 -60
  138. data/app/models/caboose_store/order_line_item.rb +0 -13
  139. data/app/models/caboose_store/states.rb +0 -60
  140. data/app/views/caboose_store/application/_category_thumb.html.erb +0 -6
  141. data/app/views/caboose_store/application/_product_thumb.html.erb +0 -13
  142. data/app/views/caboose_store/checkout/quantity_box.html.erb +0 -39
  143. data/app/views/caboose_store/checkout/thank_you.html.erb +0 -36
@@ -2,51 +2,41 @@ require 'json'
2
2
 
3
3
  module CabooseStore
4
4
  class SearchFilter < ActiveRecord::Base
5
-
6
- self.table_name = "store_search_filters"
7
- attr_accessible :id,
5
+ self.table_name = 'store_search_filters'
6
+
7
+ attr_accessible :id,
8
8
  :url,
9
9
  :title_like,
10
+ :search_like,
10
11
  :category_id,
11
12
  :category,
12
- :vendors,
13
+ :vendors,
13
14
  :option1,
14
15
  :option2,
15
16
  :option3,
16
17
  :prices
17
-
18
+
18
19
  before_save :json_encode
19
20
  after_initialize :json_decode
20
-
21
+
21
22
  def json_encode
22
- self.category = self.category.to_json if !self.category.nil?
23
- self.vendors = self.vendors.to_json if !self.vendors.nil?
24
- self.option1 = self.option1.to_json if !self.option1.nil?
25
- self.option2 = self.option2.to_json if !self.option2.nil?
26
- self.option3 = self.option3.to_json if !self.option3.nil?
27
- self.prices = self.prices.to_json if !self.prices.nil?
23
+ self.category = self.category.to_json if not self.category.nil?
24
+ self.vendors = self.vendors.to_json if not self.vendors.nil?
25
+ self.option1 = self.option1.to_json if not self.option1.nil?
26
+ self.option2 = self.option2.to_json if not self.option2.nil?
27
+ self.option3 = self.option3.to_json if not self.option3.nil?
28
+ self.prices = self.prices.to_json if not self.prices.nil?
28
29
  end
29
30
 
30
31
  def json_decode
31
- if !self.category.nil?
32
- cat = JSON.parse(self.category)
33
- self.category = Caboose::StdClass.new({
34
- 'id' => cat['id'],
35
- 'name' => cat['name'],
36
- 'children' => cat['children'].collect { |cat2| Caboose::StdClass.new(cat2) }
37
- })
38
- end
39
-
40
- #self.category = JSON.parse(self.category).collect{ |hash| Caboose::StdClass.new(hash) } if !self.category.nil?
41
- self.vendors = JSON.parse(self.vendors ).collect{ |hash| Caboose::StdClass.new(hash) } if !self.vendors.nil?
42
- self.option1 = JSON.parse(self.option1 ) if !self.option1.nil?
43
- self.option2 = JSON.parse(self.option2 ) if !self.option2.nil?
44
- self.option3 = JSON.parse(self.option3 ) if !self.option3.nil?
45
- self.prices = JSON.parse self.prices if !self.prices.nil?
46
-
47
- Caboose.log(self.option1)
32
+ self.category = JSON.parse(self.category) if not self.category.nil?
33
+ self.vendors = JSON.parse(self.vendors) if not self.vendors.nil?
34
+ self.option1 = JSON.parse(self.option1) if not self.option1.nil?
35
+ self.option2 = JSON.parse(self.option2) if not self.option2.nil?
36
+ self.option3 = JSON.parse(self.option3) if not self.option3.nil?
37
+ self.prices = JSON.parse(self.prices) if not self.prices.nil?
48
38
  end
49
-
39
+
50
40
  def self.exclude_params_from_url(url, exclude_params = nil)
51
41
  return url if exclude_params.nil? || exclude_params.count == 0
52
42
 
@@ -73,65 +63,54 @@ module CabooseStore
73
63
  return url2
74
64
  end
75
65
 
76
- def self.find_from_url(url, pager, exclude_params = nil)
66
+ def self.find_from_url(url, pager, exclude_params=nil)
77
67
 
78
- url2 = self.exclude_params_from_url(url, exclude_params)
79
- Caboose.log("url2 = #{url2}")
68
+ # Filter any specified parameters from the url
69
+ filtered_url = self.exclude_params_from_url(url, exclude_params)
80
70
 
81
- if SearchFilter.exists?(:url => url2)
82
- return SearchFilter.where(:url => url2).first
83
- end
84
-
85
- f = SearchFilter.new
86
- f.url = url2
87
-
88
- url2 = url2.split("?")[0] if url2.include?('?')
89
- parent = nil
90
- selected_cat_id = nil
91
-
92
- if Category.exists?(:url => url2)
93
- parent = Category.where(:url => url2).first
94
- f.category_id = parent.id if parent
95
- parent = Category.find(parent.parent_id) if parent && parent.children && parent.children.count == 0
96
- elsif pager.params['category_id'] && pager.params['category_id'] != ''
97
- cat_id = pager.params['category_id'].kind_of?(Array) ? pager.params['category_id'][0] : pager.params['category_id']
98
- cat = Category.find(cat_id)
99
- parent = cat.parent
100
- f.category_id = cat.id if !pager.params['category_id'].kind_of?(Array)
101
- elsif pager.params['category_slug'] && pager.params['category_slug'] != ''
102
- slug = pager.params['category_slug'].kind_of?(Array) ? pager.params['category_slug'][0] : pager.params['category_slug']
103
- cat = Category.where(:slug => slug).first
104
- parent = cat.parent
105
- f.category_id = cat.id if !pager.params['category_slug'].kind_of?(Array)
71
+ # If the search filter already exists pass it back
72
+ # return SearchFilter.where(url: pager.options['base_url']) if SearchFilter.exists?(url: pager.options['base_url'])
73
+
74
+ # Create a new search filter
75
+ search_filter = SearchFilter.new
76
+ search_filter.url = filtered_url
77
+
78
+ search_filter.category_id = if pager.params['category_id'].kind_of?(Array)
79
+ pager.params['category_id'].first
80
+ else
81
+ pager.params['category_id']
106
82
  end
107
- f.category = nil
108
- if parent && parent.children && parent.children.count > 0
109
- f.category = {
110
- 'id' => parent.id,
111
- 'name' => parent.name,
112
- 'selected' => parent.id == f.category_id,
113
- 'children' => parent.children.collect { |cat| {
114
- 'id' => cat.id,
115
- 'name' => cat.name,
116
- 'url' => cat.url,
117
- 'selected' => cat.id == f.category_id
118
- }
119
- }
120
- }
83
+
84
+ # Grab the category NOTE: A category id is required
85
+ category = Category.find(search_filter.category_id)
86
+
87
+ # Define the category info
88
+ search_filter.category = Hash.new
89
+ search_filter.category['id'] = category.id
90
+ search_filter.category['name'] = category.name
91
+
92
+ # Define children categories info
93
+ search_filter.category['children'] = category.children.collect do |child_category|
94
+ child = Hash.new
95
+ child['id'] = child_category.id
96
+ child['name'] = child_category.name
97
+ child['url'] = child_category.url
98
+
99
+ child
121
100
  end
122
- pager.params['category_id'] = f.category_id if pager.params['category_id'].nil? || pager.params['category_id'] == ''
123
101
 
124
- f.title_like = pager.params['title_like'] if pager.params['title_like']
125
-
126
- vendor_ids = []
127
- option1 = Caboose::StdClass.new({ 'name' => [], 'values' => [] })
128
- option2 = Caboose::StdClass.new({ 'name' => [], 'values' => [] })
129
- option3 = Caboose::StdClass.new({ 'name' => [], 'values' => [] })
102
+ # Initialize option hashes
103
+ option1 = { 'name' => [], 'values' => [] }
104
+ option2 = { 'name' => [], 'values' => [] }
105
+ option3 = { 'name' => [], 'values' => [] }
106
+
107
+ # Default min an max values
130
108
  min = 0.0
131
109
  max = 1000000.0
132
110
 
133
- prices = [
134
- [ 0, 10],
111
+ # Set price ranges
112
+ price_ranges = [
113
+ [ 1, 10],
135
114
  [ 10, 25],
136
115
  [ 25, 50],
137
116
  [ 50, 75],
@@ -148,49 +127,65 @@ module CabooseStore
148
127
  [ 4000, 5000],
149
128
  [ 7000, 7500],
150
129
  [ 7500, 10000],
151
- [10000, 50000]
152
- ]
153
- price_counts = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
154
-
155
- pager.all_items.each do |p|
156
- vendor_ids << p.vendor_id
157
- option1.name << p.option1
158
- option2.name << p.option2
159
- option3.name << p.option3
160
- p.variants.each do |v|
161
- option1.values << v.option1
162
- option2.values << v.option2
163
- option3.values << v.option3
164
- min = v.price if v.price < min
165
- max = v.price if v.price > max
166
- prices.each_index do |i|
167
- minmax = prices[i]
168
- price_counts[i] = price_counts[i] + 1 if v.price > minmax[0] && v.price < minmax[1]
130
+ [10000, 50000]
131
+ ]
132
+
133
+ # Create an array of the same length as the price ranges to hold a match count
134
+ price_range_matches = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
135
+
136
+ # Array to hold all relevant vendor IDs
137
+ vendor_ids = []
138
+
139
+ # Iterate over pager results for product and variant info
140
+ pager.all_items.each do |product|
141
+ option1['name'] << product.option1
142
+ option2['name'] << product.option2
143
+ option3['name'] << product.option3
144
+
145
+ product.variants.each do |variant|
146
+ option1['values'] << variant.option1.strip if !variant.option1.nil?
147
+ option2['values'] << variant.option2.strip if !variant.option2.nil?
148
+ option3['values'] << variant.option3.strip if !variant.option3.nil?
149
+
150
+ # Iterate over price ranges
151
+ price_ranges.each_with_index do |price_range, index|
152
+ min = price_range.first
153
+ max = price_range.last
154
+
155
+ # Skip to next variant if the price isnt defined or is less than $1
156
+ next if variant.price.nil? || variant.price < 1
157
+
158
+ # Increment price count at index if the varaint is within the price range
159
+ if variant.price > min and variant.price < max
160
+ price_range_matches[index] += 1
161
+ vendor_ids << product.vendor_id
162
+ end
169
163
  end
170
164
  end
171
165
  end
172
166
 
173
- vendor_ids = vendor_ids ? vendor_ids.compact.uniq : nil
174
- f.vendors = vendor_ids && vendor_ids.count > 0 ? vendor_ids.collect { |vid| Vendor.find(vid) } : nil
167
+ # Grab all active vendors
168
+ search_filter.vendors = Vendor.where('id IN (?) AND status = ?', vendor_ids.uniq, 'Active')
175
169
 
176
- option1.name = option1.name ? option1.name.compact.uniq : nil
177
- option2.name = option2.name ? option2.name.compact.uniq : nil
178
- option3.name = option3.name ? option3.name.compact.uniq : nil
170
+ # Remove nil and duplicate values from option name arrays
171
+ option1['name'] = option1['name'].compact.uniq
172
+ option2['name'] = option2['name'].compact.uniq
173
+ option3['name'] = option3['name'].compact.uniq
179
174
 
180
- f.option1 = option1.name && option1.name.count == 1 ? Caboose::StdClass.new({ 'name' => option1.name[0], 'values' => option1.values.compact.uniq.sort }) : nil
181
- f.option2 = option2.name && option2.name.count == 1 ? Caboose::StdClass.new({ 'name' => option2.name[0], 'values' => option2.values.compact.uniq.sort }) : nil
182
- f.option3 = option3.name && option3.name.count == 1 ? Caboose::StdClass.new({ 'name' => option3.name[0], 'values' => option3.values.compact.uniq.sort }) : nil
175
+ # ?? If option name array have exactly 1 value then set the search filter's option values
176
+ search_filter.option1 = if option1['name'].count == 1 then { 'name' => option1['name'][0], 'values' => option1['values'].compact.uniq.sort } else nil end
177
+ search_filter.option2 = if option2['name'].count == 1 then { 'name' => option2['name'][0], 'values' => option2['values'].compact.uniq.sort } else nil end
178
+ search_filter.option3 = if option3['name'].count == 1 then { 'name' => option3['name'][0], 'values' => option3['values'].compact.uniq.sort } else nil end
183
179
 
184
- f.prices = []
185
- price_counts.each_index do |i|
186
- f.prices << prices[i] if price_counts[i] > 0
187
- end
188
- f.prices = nil if f.prices.count == 0
180
+ # Get all price ranges that have matches
181
+ search_filter.prices = price_range_matches.collect.with_index { |matches, index| price_ranges[index] if matches > 0 }.compact
189
182
 
190
- f.save
191
- return SearchFilter.find(f.id)
183
+ # Inject the search filter into the database
184
+ # search_filter.save
192
185
 
186
+ # Finally, return the filter; NOTE: find out of the database so the hashes get serialized correctly
187
+ # SearchFilter.find(search_filter.id)
188
+ return search_filter
193
189
  end
194
-
195
190
  end
196
191
  end
@@ -3,77 +3,79 @@ include ActiveMerchant::Shipping
3
3
 
4
4
  module CabooseStore
5
5
  class ShippingCalculator
6
-
7
- # Calculates the total cost of shipping
8
- # Providers can be ups, fedex, or usps
9
- #
10
- # padded envelope, 5 lbs, 90210 => $7.62
11
- # padded envelope, 20 lbs, 90210 => $13.99
12
- # box1 , 20 lbs, 90210 => $20.00
13
- # box2 , 30 lbs, 90210 => $25.00
14
- def self.rates(order, service_code = nil)
6
+ def self.rates(order)
7
+ return [] if CabooseStore::shipping.nil?
15
8
 
16
- total = 0.0
9
+ total = 0.0
17
10
  weight = 0.0
11
+
18
12
  order.line_items.each do |li|
19
- total = total + (li.variant.shipping_unit_value.nil? ? 0 : li.variant.shipping_unit_value)
20
- weight = weight + li.variant.weight
13
+ total = total + (li.variant.shipping_unit_value.nil? ? 0 : li.variant.shipping_unit_value)
14
+ weight = weight + (li.variant.weight || 0)
21
15
  end
22
-
16
+
23
17
  length = 0
24
18
  width = 0
25
19
  height = 0
26
-
27
- if total <= 5 # padded envelope
20
+
21
+ if total <= 5
28
22
  length = 15.5
29
23
  width = 9.5
30
24
  height = 6
31
- elsif total <= 10 # box1
25
+ elsif total <= 10
32
26
  length = 12
33
27
  width = 8
34
28
  height = 5
35
- else # box2
29
+ else
36
30
  length = 20
37
31
  width = 16
38
- height = 14
32
+ height = 14
39
33
  end
40
-
41
- origin = Location.new(:country => 'US', :state => 'AL', :city => 'Tuscaloosa', :zip => '35405')
42
- destination = Location.new(:country => 'US', :state => order.shipping_address.state, :city => order.shipping_address.city, :postal_code => order.shipping_address.zip)
34
+
35
+ origin = Location.new(
36
+ :country => CabooseStore::shipping[:origin][:country],
37
+ :state => CabooseStore::shipping[:origin][:state],
38
+ :city => CabooseStore::shipping[:origin][:city],
39
+ :zip => CabooseStore::shipping[:origin][:zip]
40
+ )
41
+
42
+ destination = Location.new(
43
+ :country => CabooseStore::shipping[:origin][:country],
44
+ :state => order.shipping_address.state,
45
+ :city => order.shipping_address.city,
46
+ :postal_code => order.shipping_address.zip
47
+ )
48
+
43
49
  packages = [Package.new(weight, [length, width, height], :units => :imperial)]
44
-
50
+
45
51
  ups = UPS.new(
46
- :key => '7CBEA07A8AA3279A',
47
- :login => 'ABBE FINE',
48
- :password => '*TuskWear10*',
49
- :origin_account => 'A102Y2'
50
- #:login => Tuskwear::Application.config.shipping[:ups][:login],
51
- #:password => Tuskwear::Application.config.shipping[:ups][:password],
52
- #:key => Tuskwear::Application.config.shipping[:ups][:key]
52
+ :key => CabooseStore::shipping[:ups][:key],
53
+ :login => CabooseStore::shipping[:ups][:username],
54
+ :password => CabooseStore::shipping[:ups][:password],
55
+ :origin_account => CabooseStore::shipping[:ups][:origin_account]
53
56
  )
54
- response = ups.find_rates(origin, destination, packages)
55
57
 
56
- rates = []
57
- response.rates.each do |r|
58
- next if r.service_code != '03' && r.service_code !='02'
59
- rates << {
60
- 'service_code' => r.service_code,
61
- 'service_name' => r.service_name,
62
- 'total_price' => r.total_price,
63
- 'negotiated_rate' => r.negotiated_rate # - 300
64
- }
65
- end
66
- return rates
67
- end
68
-
69
- # Return the rate for the given service code
70
- def self.rate(order, service_code)
71
- self.rates(order).each do |r|
72
- next if r['service_code'] != service_code
73
- return r
58
+ ups_response = ups.find_rates(origin, destination, packages)
59
+
60
+ rates = ups_response.rates.collect do |rate|
61
+ next if CabooseStore::allowed_shipping_codes && !CabooseStore::allowed_shipping_codes.index(rate.service_code)
62
+
63
+ {
64
+ :service_code => rate.service_code,
65
+ :service_name => rate.service_name,
66
+ :total_price => rate.total_price.to_d / 100,
67
+ :negotiated_rate => rate.negotiated_rate
68
+ }
74
69
  end
75
- return nil
70
+
71
+ return rates.compact
76
72
  end
77
73
 
74
+ def self.rate(order)
75
+ return nil if !order.shipping_code
76
+ self.rates(order).each { |rate| return rate if rate[:service_code] == order.shipping_code }
77
+ return nil
78
+ end
78
79
  end
79
80
  end
81
+
@@ -1,10 +1,7 @@
1
-
2
1
  module CabooseStore
3
2
  class TaxCalculator
4
-
5
- # Calculates the total cost of shipping
6
- # Providers can be ups, fedex, or usps
7
3
  def self.tax_rate(address)
4
+ return 0 if address.state.downcase != 'al'
8
5
  city = address.city.downcase
9
6
  rate = 0.00
10
7
  rate = rate + 0.05 if city == 'brookwood'
@@ -19,8 +16,7 @@ module CabooseStore
19
16
  rate = rate + 0.05 if city == 'vance'
20
17
  rate = rate + 0.05 if city == 'woodstock'
21
18
  rate = rate + 0.04 if address.state.downcase == 'al' || address.state.downcase == 'alabama'
22
- return rate
19
+ return rate.round(2)
23
20
  end
24
-
25
21
  end
26
22
  end
@@ -1,12 +1,9 @@
1
-
2
1
  module CabooseStore
3
- class TaxLine < ActiveRecord::Base
4
-
2
+ class TaxLine < ActiveRecord::Base
5
3
  attr_accessible :id,
6
4
  :title, # The name of the tax, eg. QST or VAT
7
5
  :price, # The amount
8
6
  :rate, # The rate. It will return 0.175 if it is 17.5%
9
7
  :rate_percentage # The tax rate in human readable form. It will return 17.5 if the rate is 0.175
10
-
11
8
  end
12
9
  end
@@ -1,31 +1,88 @@
1
+ #
2
+ # Variant
3
+ #
4
+ # :: Class Methods
5
+ # :: Instance Methods
1
6
 
2
7
  module CabooseStore
3
8
  class Variant < ActiveRecord::Base
4
- self.table_name = "store_variants"
9
+ self.table_name = 'store_variants'
5
10
 
6
11
  belongs_to :product
7
12
  has_many :product_image_variants
8
- has_many :product_images, :through => :product_image_variants
13
+ has_many :product_images, :through => :product_image_variants
9
14
 
10
- attr_accessible :id, # Variant’s unique id.
15
+ attr_accessible :id,
16
+ :alternate_id,
11
17
  :product_id,
12
- :sku, # The variant's SKU.
13
- :barcode, # Returns the barcode value of the variant.
14
- :price, # Variant’s price.
15
- :quantity_in_stock, # How many of this variants are in stock for this shop.
16
- :allow_backorder, # Whether to allow items with no inventory to be added to the cart
17
- :status, # Current status: active, inactive, deleted
18
- :weight, # The weight of the variant. This will always be in metric grams.
19
- :length, # Length of variant in inches
20
- :width, # Width of variant in inches
21
- :height, # Height of variant in inches
22
- :option1, # Returns the value of option1 for given variant
23
- :option2, # If a product has a second option defined, then returns the value of this variant's option2.
24
- :option3, # If a product has a third option defined, then returns the value of this variant's option3.
25
- :requires_shipping, # Returns true if the variant is shippable or false if it is a service or a digital good.
26
- :taxable # Returns true if the variant is taxable or false if it is not.
27
-
28
- # Concatenation of all the variant's option values, joined by " / "
18
+ :barcode, # Returns the barcode value of the variant.
19
+ :price, # Variant’s price.
20
+ :ignore_quantity,
21
+ :quantity,
22
+ :allow_backorder, # Whether to allow items with no inventory to be added to the cart
23
+ :status, # Current status: active, inactive, deleted
24
+ :weight, # The weight of the variant. This will always be in metric grams.
25
+ :length, # Length of variant in inches
26
+ :width, # Width of variant in inches
27
+ :height, # Height of variant in inches
28
+ :option1, # Returns the value of option1 for given variant
29
+ :option2, # If a product has a second option defined, then returns the value of this variant's option2.
30
+ :option3, # If a product has a third option defined, then returns the value of this variant's option3.
31
+ :requires_shipping, # Returns true if the variant is shippable or false if it is a service or a digital good.
32
+ :taxable, # Returns true if the variant is taxable or false if it is not.
33
+ :sku,
34
+ :available,
35
+ :cylinder,
36
+ :shipping_unit_value
37
+
38
+ #
39
+ # Class Methods
40
+ #
41
+
42
+ def self.find_by_options(product_id, option1=nil, option2=nil, option3=nil)
43
+
44
+ # Create the vars that will become the full conditions statement
45
+ where = ['product_id=?']
46
+ values = [product_id.to_i]
47
+
48
+ # Append option values if they exist
49
+
50
+ if option1
51
+ where << 'option1=?'
52
+ values << option1
53
+ end
54
+
55
+ if option2
56
+ where << 'option2=?'
57
+ values << option2
58
+ end
59
+
60
+ if option3
61
+ where << 'option3=?'
62
+ values << option3
63
+ end
64
+
65
+ # Combine all the options into a single conditions statement
66
+ conditions = [ where.join(' AND ') ].concat(values)
67
+
68
+ # Return whatever is found
69
+ return Variant.where(conditions).first
70
+ end
71
+
72
+ #
73
+ # Instance Methods
74
+ #
75
+
76
+ def as_json(options={})
77
+ self.attributes.merge({
78
+ :images => if self.product_images.any?
79
+ self.product_images
80
+ else
81
+ [self.product.product_images.first]
82
+ end
83
+ })
84
+ end
85
+
29
86
  def title
30
87
  return self.options.join(' / ')
31
88
  end
@@ -37,6 +94,5 @@ module CabooseStore
37
94
  arr << self.option3 if self.option3 && self.option3.strip.length > 0
38
95
  return arr
39
96
  end
40
-
41
97
  end
42
98
  end
@@ -1,7 +1,22 @@
1
1
 
2
2
  module CabooseStore
3
3
  class Vendor < ActiveRecord::Base
4
- self.table_name = "store_vendors"
5
- attr_accessible :id, :name
4
+ self.table_name = 'store_vendors'
5
+
6
+ has_many :products
7
+ attr_accessible :id, :name, :status, :sort_order
8
+ after_save :clear_filters
9
+
10
+ def self.active
11
+ where(:status => 'Active')
12
+ end
13
+
14
+ def update_products
15
+ self.products.each { |product| product.update_attribute(:vendor_status, self.status) }
16
+ end
17
+
18
+ def clear_filters
19
+ SearchFilter.delete_all
20
+ end
6
21
  end
7
22
  end
@@ -1,19 +1,4 @@
1
+ <div class="wrapper">
2
+ <div id="cart"></div>
3
+ </div>
1
4
 
2
- <div id='cart'></div>
3
- <%= content_for :caboose_js do %>
4
- <%= javascript_include_tag 'cart' %>
5
- <script type='text/javascript'>
6
-
7
- var modal = false;
8
- $(window).load(function() {
9
- var line_items = <%= raw Caboose.json(line_items(@order)) %>;
10
- var c = new Cart(line_items);
11
- c.print();
12
- if (c.line_items.length > 0)
13
- modal = new CabooseModal(600);
14
- else
15
- modal = new CabooseModal(400, 50);
16
- });
17
-
18
- </script>
19
- <% end %>