spree_core 1.1.6 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/app/assets/images/{creditcards → credit_cards}/amex_cid.gif +0 -0
  2. data/app/assets/images/{creditcards/creditcard.gif → credit_cards/credit_card.gif} +0 -0
  3. data/app/assets/images/{creditcards → credit_cards}/discover_cid.gif +0 -0
  4. data/app/assets/images/{creditcards → credit_cards}/icons/american_express.png +0 -0
  5. data/app/assets/images/{creditcards → credit_cards}/icons/cirrus.png +0 -0
  6. data/app/assets/images/{creditcards → credit_cards}/icons/delta.png +0 -0
  7. data/app/assets/images/{creditcards → credit_cards}/icons/dinersclub.png +0 -0
  8. data/app/assets/images/{creditcards → credit_cards}/icons/directdebit.png +0 -0
  9. data/app/assets/images/{creditcards → credit_cards}/icons/discover.png +0 -0
  10. data/app/assets/images/{creditcards → credit_cards}/icons/egold.png +0 -0
  11. data/app/assets/images/{creditcards → credit_cards}/icons/maestro.png +0 -0
  12. data/app/assets/images/{creditcards → credit_cards}/icons/master.png +0 -0
  13. data/app/assets/images/{creditcards → credit_cards}/icons/paypal.png +0 -0
  14. data/app/assets/images/{creditcards → credit_cards}/icons/solo.png +0 -0
  15. data/app/assets/images/{creditcards → credit_cards}/icons/switch.png +0 -0
  16. data/app/assets/images/{creditcards → credit_cards}/icons/visa.png +0 -0
  17. data/app/assets/images/{creditcards → credit_cards}/icons/visaelectron.png +0 -0
  18. data/app/assets/images/{creditcards → credit_cards}/icons/westernunion.png +0 -0
  19. data/app/assets/images/{creditcards → credit_cards}/icons/wirecard.png +0 -0
  20. data/app/assets/images/{creditcards → credit_cards}/icons/worldpay.png +0 -0
  21. data/app/assets/images/{creditcards → credit_cards}/master_cid.jpg +0 -0
  22. data/app/assets/images/{creditcards → credit_cards}/visa_cid.gif +0 -0
  23. data/app/assets/javascripts/admin/admin.js.erb +12 -136
  24. data/app/assets/javascripts/admin/checkouts/edit.js +18 -35
  25. data/app/assets/javascripts/admin/gateway.js +2 -2
  26. data/app/assets/javascripts/admin/images/index.js.coffee +12 -0
  27. data/app/assets/javascripts/admin/images/new.js.coffee +4 -0
  28. data/app/assets/javascripts/admin/orders/edit.js +1 -1
  29. data/app/assets/javascripts/admin/orders/edit_form.js +0 -2
  30. data/app/assets/javascripts/admin/product_autocomplete.js.erb +116 -0
  31. data/app/assets/javascripts/store/cart.js.coffee +7 -0
  32. data/app/assets/javascripts/store/checkout.js.coffee +57 -0
  33. data/app/assets/javascripts/store/product.js.coffee +36 -0
  34. data/app/assets/stylesheets/admin/admin.css.erb +5 -0
  35. data/app/assets/stylesheets/admin/spree_core.css +1 -0
  36. data/app/assets/stylesheets/store/screen.css.scss +15 -1
  37. data/app/assets/stylesheets/store/variables.css.scss +29 -29
  38. data/app/controllers/spree/admin/banners_controller.rb +14 -0
  39. data/app/controllers/spree/admin/base_controller.rb +11 -0
  40. data/app/controllers/spree/admin/images_controller.rb +13 -5
  41. data/app/controllers/spree/admin/line_items_controller.rb +16 -25
  42. data/app/controllers/spree/admin/mail_methods_controller.rb +1 -8
  43. data/app/controllers/spree/admin/option_types_controller.rb +0 -25
  44. data/app/controllers/spree/admin/orders/customer_details_controller.rb +3 -3
  45. data/app/controllers/spree/admin/orders_controller.rb +23 -14
  46. data/app/controllers/spree/admin/payment_methods_controller.rb +1 -7
  47. data/app/controllers/spree/admin/payments_controller.rb +5 -5
  48. data/app/controllers/spree/admin/products_controller.rb +15 -5
  49. data/app/controllers/spree/admin/prototypes_controller.rb +2 -2
  50. data/app/controllers/spree/admin/reports_controller.rb +1 -7
  51. data/app/controllers/spree/admin/resource_controller.rb +130 -130
  52. data/app/controllers/spree/admin/search_controller.rb +47 -0
  53. data/app/controllers/spree/admin/taxons_controller.rb +0 -43
  54. data/app/controllers/spree/base_controller.rb +2 -1
  55. data/app/controllers/spree/checkout_controller.rb +29 -10
  56. data/app/controllers/spree/orders_controller.rb +7 -11
  57. data/app/controllers/spree/products_controller.rb +5 -1
  58. data/app/helpers/spree/account_helper.rb +4 -0
  59. data/app/helpers/spree/admin/base_helper.rb +2 -44
  60. data/app/helpers/spree/admin/navigation_helper.rb +1 -3
  61. data/app/helpers/spree/admin/orders_helper.rb +3 -2
  62. data/app/helpers/spree/admin/products_helper.rb +21 -0
  63. data/app/helpers/spree/base_helper.rb +14 -11
  64. data/app/helpers/spree/checkout_helper.rb +5 -1
  65. data/app/helpers/spree/orders_helper.rb +5 -0
  66. data/app/helpers/spree/products_helper.rb +4 -0
  67. data/app/helpers/spree/trackers_helper.rb +4 -0
  68. data/app/models/spree/ability.rb +70 -0
  69. data/app/models/spree/address.rb +4 -12
  70. data/app/models/spree/adjustment.rb +30 -8
  71. data/app/models/spree/app_configuration.rb +1 -1
  72. data/app/models/spree/calculator/price_sack.rb +3 -5
  73. data/app/models/spree/country.rb +1 -4
  74. data/app/models/spree/{creditcard.rb → credit_card.rb} +4 -4
  75. data/app/models/spree/gateway.rb +2 -2
  76. data/app/models/spree/gateway/bogus.rb +10 -10
  77. data/app/models/spree/gateway/bogus_simple.rb +4 -4
  78. data/app/models/spree/image.rb +3 -12
  79. data/app/models/spree/inventory_unit.rb +4 -6
  80. data/app/models/spree/{user.rb → legacy_user.rb} +7 -6
  81. data/app/models/spree/line_item.rb +4 -5
  82. data/app/models/spree/option_type.rb +4 -6
  83. data/app/models/spree/option_value.rb +1 -1
  84. data/app/models/spree/order.rb +90 -132
  85. data/app/models/spree/order/checkout.rb +124 -0
  86. data/app/models/spree/payment.rb +6 -6
  87. data/app/models/spree/payment/processing.rb +34 -38
  88. data/app/models/spree/payment_method.rb +2 -2
  89. data/app/models/spree/preference.rb +2 -0
  90. data/app/models/spree/preferences/preferable_class_methods.rb +0 -2
  91. data/app/models/spree/preferences/store.rb +3 -21
  92. data/app/models/spree/product.rb +41 -43
  93. data/app/models/spree/product/scopes.rb +9 -25
  94. data/app/models/spree/product_option_type.rb +2 -2
  95. data/app/models/spree/product_property.rb +9 -4
  96. data/app/models/spree/property.rb +1 -1
  97. data/app/models/spree/prototype.rb +2 -2
  98. data/app/models/spree/return_authorization.rb +2 -2
  99. data/app/models/spree/role.rb +1 -1
  100. data/app/models/spree/shipment.rb +6 -5
  101. data/app/models/spree/shipping_method.rb +19 -13
  102. data/app/models/spree/state.rb +2 -5
  103. data/app/models/spree/state_change.rb +1 -1
  104. data/app/models/spree/tax_rate.rb +8 -1
  105. data/app/models/spree/taxon.rb +5 -1
  106. data/app/models/spree/taxonomy.rb +1 -1
  107. data/app/models/spree/tokenized_permission.rb +6 -0
  108. data/app/models/spree/tracker.rb +1 -1
  109. data/app/models/spree/variant.rb +13 -40
  110. data/app/models/spree/zone.rb +15 -14
  111. data/app/models/spree/zone_member.rb +1 -1
  112. data/app/views/spree/admin/image_settings/edit.html.erb +2 -2
  113. data/app/views/spree/admin/images/_form.html.erb +8 -4
  114. data/app/views/spree/admin/images/index.html.erb +1 -1
  115. data/app/views/spree/admin/line_items/create.js.erb +1 -1
  116. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +1 -1
  117. data/app/views/spree/admin/option_types/index.html.erb +1 -1
  118. data/app/views/spree/admin/orders/_add_product.html.erb +1 -1
  119. data/app/views/spree/admin/orders/customer_details/edit.html.erb +1 -1
  120. data/app/views/spree/admin/orders/index.html.erb +4 -4
  121. data/app/views/spree/admin/orders/show.html.erb +1 -1
  122. data/app/views/spree/admin/payments/_form.html.erb +1 -1
  123. data/app/views/spree/admin/payments/new.html.erb +0 -4
  124. data/app/views/spree/admin/payments/source_forms/_gateway.html.erb +1 -1
  125. data/app/views/spree/admin/payments/source_views/_gateway.html.erb +2 -2
  126. data/app/views/spree/admin/products/_form.html.erb +21 -5
  127. data/app/views/spree/admin/products/index.html.erb +2 -2
  128. data/app/views/spree/admin/properties/_form.html.erb +1 -1
  129. data/app/views/spree/admin/properties/index.html.erb +1 -1
  130. data/app/views/spree/admin/return_authorizations/_form.html.erb +33 -17
  131. data/app/views/spree/admin/return_authorizations/edit.html.erb +2 -2
  132. data/app/views/spree/admin/shared/_address_form.html.erb +1 -1
  133. data/app/views/spree/admin/shared/_head.html.erb +12 -2
  134. data/app/views/spree/admin/shared/_order_tabs.html.erb +1 -4
  135. data/app/views/spree/admin/shared/_product_tabs.html.erb +0 -6
  136. data/app/views/spree/admin/shared/_show_resource_links.html.erb +3 -3
  137. data/app/views/spree/admin/shared/_tabs.html.erb +1 -2
  138. data/app/views/spree/admin/shipments/edit.html.erb +2 -2
  139. data/app/views/spree/admin/shipping_methods/_form.html.erb +1 -1
  140. data/app/views/spree/admin/states/_state_list.html.erb +1 -1
  141. data/app/views/spree/admin/tax_rates/index.html.erb +1 -1
  142. data/app/views/spree/admin/taxonomies/_form.html.erb +1 -1
  143. data/app/views/spree/admin/taxons/_form.html.erb +1 -1
  144. data/app/views/spree/admin/taxons/_taxon_table.html.erb +2 -2
  145. data/app/views/spree/admin/variants/_form.html.erb +13 -13
  146. data/app/views/spree/admin/variants/index.html.erb +1 -7
  147. data/app/views/spree/checkout/_address.html.erb +10 -4
  148. data/app/views/spree/checkout/edit.html.erb +0 -1
  149. data/app/views/spree/checkout/payment/_gateway.html.erb +5 -5
  150. data/app/views/spree/checkout/registration.html.erb +2 -2
  151. data/app/views/spree/content/cvv.html.erb +6 -6
  152. data/app/views/spree/layouts/spree_application.html.erb +4 -48
  153. data/app/views/spree/order_mailer/cancel_email.text.erb +5 -5
  154. data/app/views/spree/order_mailer/confirm_email.text.erb +6 -7
  155. data/app/views/spree/orders/_adjustments.html.erb +14 -0
  156. data/app/views/spree/orders/_form.html.erb +1 -0
  157. data/app/views/spree/orders/show.html.erb +3 -3
  158. data/app/views/spree/products/_thumbnails.html.erb +1 -1
  159. data/app/views/spree/products/index.html.erb +1 -1
  160. data/app/views/spree/shared/_footer.html.erb +6 -0
  161. data/app/views/spree/shared/_google_analytics.html.erb +15 -16
  162. data/app/views/spree/shared/_head.html.erb +3 -9
  163. data/app/views/spree/shared/_header.html.erb +5 -0
  164. data/app/views/spree/shared/_main_nav_bar.html.erb +6 -0
  165. data/app/views/spree/shared/_nav_bar.html.erb +7 -3
  166. data/app/views/spree/shared/_order_details.html.erb +14 -11
  167. data/app/views/spree/shared/_sidebar.html.erb +3 -0
  168. data/app/views/spree/shared/unauthorized.html.erb +0 -0
  169. data/app/views/spree/shipment_mailer/shipped_email.text.erb +7 -7
  170. data/app/views/spree/taxons/show.html.erb +1 -1
  171. data/config/initializers/check_for_orphaned_preferences.rb +1 -1
  172. data/config/initializers/spree.rb +0 -12
  173. data/config/initializers/user_class_extensions.rb +25 -0
  174. data/config/initializers/workarounds_for_ruby19.rb +72 -0
  175. data/config/locales/en.yml +11 -24
  176. data/config/routes.rb +7 -37
  177. data/db/migrate/20090823005402_spree_zero_nine_zero.rb +14 -12
  178. data/db/migrate/20091015153048_add_openid_field_to_users.rb +9 -7
  179. data/db/migrate/20100209144531_polymorphic_payments.rb +5 -5
  180. data/db/migrate/20100214212536_assign_creditcard_txns_to_payment.rb +4 -4
  181. data/db/migrate/20100528185820_add_index_on_users_persistence_token.rb +3 -1
  182. data/db/migrate/20100811163637_add_guest_flag.rb +3 -1
  183. data/db/migrate/20100901171814_change_guest_flag_to_anonymous.rb +3 -1
  184. data/db/migrate/20101026184959_generate_anonymous_users.rb +3 -3
  185. data/db/migrate/20101103212716_drop_anonymous_field_for_user.rb +3 -1
  186. data/db/migrate/20111007143030_namespace_top_level_models.rb +18 -1
  187. data/db/migrate/20120315064358_migrate_images_from_products_to_variants.rb +6 -4
  188. data/db/migrate/20120509055454_create_tokenized_permissions_table.rb +16 -0
  189. data/db/migrate/20120530012000_rename_creditcards_to_credit_cards.rb +11 -0
  190. data/db/migrate/20120604203654_remove_credit_total_from_orders.rb +5 -0
  191. data/lib/generators/spree/custom_user/custom_user_generator.rb +53 -0
  192. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +28 -0
  193. data/lib/generators/spree/custom_user/templates/initializer.rb.tt +1 -0
  194. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -0
  195. data/lib/generators/spree/dummy/dummy_generator.rb +3 -0
  196. data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +1 -0
  197. data/lib/generators/spree/install/templates/app/assets/javascripts/admin/all.js +0 -1
  198. data/lib/generators/spree/install/templates/app/assets/javascripts/store/all.js +0 -1
  199. data/lib/generators/spree/install/templates/app/assets/stylesheets/admin/all.css +0 -1
  200. data/lib/generators/spree/install/templates/app/assets/stylesheets/store/all.css +0 -1
  201. data/lib/generators/spree/install/templates/config/initializers/spree.rb +2 -0
  202. data/lib/spree/core.rb +15 -2
  203. data/lib/spree/core/controller_helpers.rb +123 -62
  204. data/lib/spree/core/current_order.rb +5 -0
  205. data/lib/spree/core/engine.rb +1 -1
  206. data/lib/spree/core/mail_settings.rb +1 -2
  207. data/lib/spree/core/permalinks.rb +1 -5
  208. data/lib/spree/core/preference_rescue.rb +8 -4
  209. data/lib/spree/core/relation_serialization.rb +9 -0
  210. data/lib/spree/core/respond_with.rb +1 -1
  211. data/lib/spree/core/s3_support.rb +25 -0
  212. data/lib/spree/core/search/base.rb +2 -5
  213. data/lib/spree/core/ssl_requirement.rb +2 -2
  214. data/lib/spree/core/store_helpers.rb +1 -2
  215. data/lib/spree/core/testing_support/controller_requests.rb +1 -0
  216. data/lib/spree/core/testing_support/env.rb +2 -0
  217. data/lib/spree/core/testing_support/factories/{creditcard_factory.rb → credit_card_factory.rb} +3 -3
  218. data/lib/spree/core/testing_support/factories/payment_factory.rb +1 -1
  219. data/lib/spree/core/testing_support/factories/product_factory.rb +4 -4
  220. data/lib/spree/core/testing_support/factories/user_factory.rb +3 -3
  221. data/lib/spree/core/testing_support/factories/zone_factory.rb +2 -3
  222. data/lib/spree/core/token_resource.rb +27 -0
  223. data/lib/spree/core/version.rb +1 -1
  224. data/lib/spree/product_filters.rb +12 -13
  225. data/lib/tasks/core.rake +1 -1
  226. metadata +146 -154
  227. data/app/assets/images/noimage/large.png +0 -0
  228. data/app/assets/javascripts/admin/images/index.js +0 -10
  229. data/app/assets/javascripts/admin/images/new.js +0 -5
  230. data/app/assets/javascripts/admin/products.js +0 -2
  231. data/app/assets/javascripts/store/cart.js +0 -11
  232. data/app/assets/javascripts/store/checkout.js +0 -78
  233. data/app/assets/javascripts/store/product.js +0 -49
  234. data/app/controllers/spree/admin/users_controller.rb +0 -68
  235. data/app/views/spree/admin/option_types/_available.html.erb +0 -28
  236. data/app/views/spree/admin/option_types/_selected.html.erb +0 -26
  237. data/app/views/spree/admin/option_types/available.js.erb +0 -2
  238. data/app/views/spree/admin/option_types/select.js.erb +0 -3
  239. data/app/views/spree/admin/option_types/selected.html.erb +0 -6
  240. data/app/views/spree/admin/orders/history.html.erb +0 -29
  241. data/app/views/spree/admin/products/_option_types.html.erb +0 -40
  242. data/app/views/spree/admin/shared/_additional_field.html.erb +0 -5
  243. data/app/views/spree/admin/shared/_routes.html.erb +0 -8
  244. data/app/views/spree/admin/shared/_translations.html.erb +0 -17
  245. data/app/views/spree/admin/taxons/available.js.erb +0 -26
  246. data/app/views/spree/admin/taxons/remove.html.erb +0 -1
  247. data/app/views/spree/admin/taxons/select.js.erb +0 -2
  248. data/app/views/spree/admin/taxons/selected.html.erb +0 -42
  249. data/app/views/spree/admin/users/_form.html.erb +0 -19
  250. data/app/views/spree/admin/users/edit.html.erb +0 -14
  251. data/app/views/spree/admin/users/index.html.erb +0 -48
  252. data/app/views/spree/admin/users/new.html.erb +0 -14
  253. data/app/views/spree/admin/users/show.html.erb +0 -21
  254. data/app/views/spree/shared/_store_menu.html.erb +0 -2
  255. data/config/initializers/rails_5868.rb +0 -8
  256. data/db/migrate/20120605211305_make_users_email_index_unique.rb +0 -10
  257. data/db/migrate/20121017010007_remove_not_null_constraint_from_products_on_hand.rb +0 -11
  258. data/db/sample/users.rb +0 -61
  259. data/lib/generators/spree/sandbox/sandbox_generator.rb +0 -36
  260. data/lib/generators/spree/sandbox/templates/rails/routes.rb +0 -7
  261. data/lib/spree/core/ext/array.rb +0 -14
  262. data/lib/spree/core/ext/hash.rb +0 -75
  263. data/lib/spree/core/ext/string.rb +0 -10
  264. data/lib/tasks/install.rake +0 -18
@@ -0,0 +1 @@
1
+ # Spree.user_class = "User"
@@ -8,7 +8,6 @@
8
8
  //= require jquery_ujs
9
9
  <% if options[:lib_name] == 'spree' %>
10
10
  //= require admin/spree_core
11
- //= require admin/spree_auth
12
11
  //= require admin/spree_promo
13
12
  <% else %>
14
13
  //= require admin/<%= options[:lib_name].gsub("/", "_") %>
@@ -8,7 +8,6 @@
8
8
  //= require jquery_ujs
9
9
  <% if options[:lib_name] == 'spree' %>
10
10
  //= require store/spree_core
11
- //= require store/spree_auth
12
11
  //= require store/spree_promo
13
12
  <% else %>
14
13
  //= require store/<%= options[:lib_name].gsub("/", "_") %>
@@ -5,7 +5,6 @@
5
5
  *
6
6
  <% if options[:lib_name] == 'spree' %>
7
7
  *= require admin/spree_core
8
- *= require admin/spree_auth
9
8
  *= require admin/spree_promo
10
9
  <% else %>
11
10
  *= require admin/<%= options[:lib_name].gsub("/", "_") %>
@@ -5,7 +5,6 @@
5
5
  *
6
6
  <% if options[:lib_name] == 'spree' %>
7
7
  *= require store/spree_core
8
- *= require store/spree_auth
9
8
  *= require store/spree_promo
10
9
  <% else %>
11
10
  *= require store/<%= options[:lib_name].gsub("/", "_") %>
@@ -10,3 +10,5 @@ Spree.config do |config|
10
10
  # Uncomment to override the default site name.
11
11
  # config.site_name = "Spree Demo Site"
12
12
  end
13
+
14
+ Spree.user_class = "Spree::LegacyUser"
data/lib/spree/core.rb CHANGED
@@ -37,8 +37,21 @@ require 'active_merchant'
37
37
  require 'ransack'
38
38
  require 'jquery-rails'
39
39
  require 'deface'
40
+ require 'cancan'
41
+ require 'select2-rails'
40
42
 
41
43
  module Spree
44
+
45
+ mattr_accessor :user_class
46
+
47
+ def self.user_class
48
+ if @@user_class.is_a?(Class)
49
+ raise "Spree.user_class MUST be a String object, not a Class object."
50
+ elsif @@user_class.is_a?(String)
51
+ @@user_class.constantize
52
+ end
53
+ end
54
+
42
55
  module Core
43
56
  end
44
57
 
@@ -58,7 +71,6 @@ module Spree
58
71
  end
59
72
 
60
73
  require 'spree/core/ext/active_record'
61
- require 'spree/core/ext/hash'
62
74
 
63
75
  require 'spree/core/delegate_belongs_to'
64
76
 
@@ -74,6 +86,8 @@ require 'spree/core/mail_interceptor'
74
86
  require 'spree/core/middleware/redirect_legacy_product_url'
75
87
  require 'spree/core/middleware/seo_assist'
76
88
  require 'spree/core/permalinks'
89
+ require 'spree/core/token_resource'
90
+ require 'spree/core/s3_support'
77
91
 
78
92
  silence_warnings do
79
93
  require 'spree/core/authorize_net_cim_hack'
@@ -83,7 +97,6 @@ require 'spree/core/version'
83
97
 
84
98
  require 'spree/core/engine'
85
99
  require 'generators/spree/dummy/dummy_generator'
86
- require 'generators/spree/sandbox/sandbox_generator'
87
100
 
88
101
  ActiveRecord::Base.class_eval do
89
102
  include Spree::Core::CalculatedAdjustments
@@ -1,27 +1,40 @@
1
+ # This module exists so that controllers that don't inherit from Spree::BaseController
2
+ # Can still inherit the important bits of functionality and use the Spree layout by default.
1
3
  module Spree
2
4
  module Core
3
5
  module ControllerHelpers
4
- def self.included(receiver)
5
- receiver.send :layout, :get_layout
6
- receiver.send :before_filter, 'instantiate_controller_and_action_names'
7
- receiver.send :before_filter, 'set_user_language'
8
- receiver.send :helper_method, 'title'
9
- receiver.send :helper_method, 'title='
10
- receiver.send :helper_method, 'accurate_title'
11
- receiver.send :helper_method, 'get_taxonomies'
12
- receiver.send :helper_method, 'current_order'
13
- receiver.send :include, SslRequirement
14
- receiver.send :include, Spree::Core::CurrentOrder
15
- end
6
+ def self.included(base)
7
+ base.class_eval do
8
+ include Spree::Core::CurrentOrder
9
+ include Spree::Core::RespondWith
10
+ include SslRequirement
16
11
 
17
- def access_forbidden
18
- render :text => 'Access Forbidden', :layout => true, :status => 401
19
- end
12
+ helper_method :title
13
+ helper_method :title=
14
+ helper_method :accurate_title
15
+ helper_method :current_order
16
+ helper_method :try_spree_current_user
17
+
18
+ before_filter :set_user_language
19
+ before_filter :set_current_order
20
+
21
+ rescue_from CanCan::AccessDenied do |exception|
22
+ return unauthorized
23
+ end
20
24
 
25
+ layout :get_layout
26
+ end
27
+ end
21
28
  # can be used in views as well as controllers.
22
29
  # e.g. <% title = 'This is a custom title for this view' %>
23
30
  attr_writer :title
24
31
 
32
+ # proxy method to *possible* spree_current_user method
33
+ # Authentication extensions (such as spree_auth_devise) are meant to provide spree_current_user
34
+ def try_spree_current_user
35
+ respond_to?(:spree_current_user) ? spree_current_user : nil
36
+ end
37
+
25
38
  def title
26
39
  title_string = @title.present? ? @title : accurate_title
27
40
  if title_string.present?
@@ -37,69 +50,117 @@ module Spree
37
50
 
38
51
  protected
39
52
 
40
- def default_title
41
- Spree::Config[:site_name]
53
+ def set_current_order
54
+ if user = try_spree_current_user
55
+ last_incomplete_order = user.last_incomplete_spree_order
56
+ if session[:order_id].nil? && last_incomplete_order
57
+ session[:order_id] = last_incomplete_order.id
58
+ elsif current_order && last_incomplete_order && current_order != last_incomplete_order
59
+ current_order.merge!(last_incomplete_order)
60
+ end
42
61
  end
62
+ end
43
63
 
44
- # this is a hook for subclasses to provide title
45
- def accurate_title
46
- Spree::Config[:default_seo_title]
47
- end
64
+ # Needs to be overriden so that we use Spree's Ability rather than anyone else's.
65
+ def current_ability
66
+ @current_ability ||= Spree::Ability.new(try_spree_current_user)
67
+ end
48
68
 
49
- def render_404(exception = nil)
50
- respond_to do |type|
51
- type.html { render :status => :not_found, :file => "#{::Rails.root}/public/404", :formats => [:html], :layout => nil}
52
- type.all { render :status => :not_found, :nothing => true }
69
+ def store_location
70
+ # disallow return to login, logout, signup pages
71
+ authentication_routes = [:spree_signup_path, :spree_login_path, :spree_logout_path]
72
+ disallowed_urls = []
73
+ authentication_routes.each do |route|
74
+ if respond_to?(route)
75
+ disallowed_urls << send(route)
53
76
  end
54
77
  end
55
78
 
56
- # Convenience method for firing instrumentation events with the default payload hash
57
- def fire_event(name, extra_payload = {})
58
- ActiveSupport::Notifications.instrument(name, default_notification_payload.merge(extra_payload))
79
+ disallowed_urls.map!{ |url| url[/\/\w+$/] }
80
+ unless disallowed_urls.include?(request.fullpath)
81
+ session['user_return_to'] = request.fullpath.gsub('//', '/')
59
82
  end
83
+ end
84
+ # Redirect as appropriate when an access request fails. The default action is to redirect to the login screen.
85
+ # Override this method in your controllers if you want to have special behavior in case the user is not authorized
86
+ # to access the requested action. For example, a popup window might simply close itself.
87
+ def unauthorized
88
+ respond_to do |format|
89
+ format.html do
90
+ if try_spree_current_user
91
+ flash.now[:error] = t(:authorization_failure)
92
+ render 'spree/shared/unauthorized', :layout => '/spree/layouts/spree_application', :status => 401
93
+ else
94
+ store_location
95
+ url = respond_to?(:spree_login_path) ? spree_login_path : root_path
96
+ redirect_to url
97
+ end
98
+ end
99
+ format.xml do
100
+ request_http_basic_authentication 'Web Password'
101
+ end
102
+ format.json do
103
+ render :text => "Not Authorized \n", :status => 401
104
+ end
105
+ end
106
+ end
60
107
 
61
- # Creates the hash that is sent as the payload for all notifications. Specific notifications will
62
- # add additional keys as appropriate. Override this method if you need additional data when
63
- # responding to a notification
64
- def default_notification_payload
65
- {:user => (respond_to?(:current_user) && current_user), :order => current_order}
108
+
109
+ def default_title
110
+ Spree::Config[:site_name]
111
+ end
112
+
113
+ # this is a hook for subclasses to provide title
114
+ def accurate_title
115
+ Spree::Config[:default_seo_title]
116
+ end
117
+
118
+ def render_404(exception = nil)
119
+ respond_to do |type|
120
+ type.html { render :status => :not_found, :file => "#{::Rails.root}/public/404", :formats => [:html], :layout => nil}
121
+ type.all { render :status => :not_found, :nothing => true }
66
122
  end
123
+ end
124
+
125
+ # Convenience method for firing instrumentation events with the default payload hash
126
+ def fire_event(name, extra_payload = {})
127
+ ActiveSupport::Notifications.instrument(name, default_notification_payload.merge(extra_payload))
128
+ end
129
+
130
+ # Creates the hash that is sent as the payload for all notifications. Specific notifications will
131
+ # add additional keys as appropriate. Override this method if you need additional data when
132
+ # responding to a notification
133
+ def default_notification_payload
134
+ {:user => try_spree_current_user, :order => current_order}
135
+ end
67
136
 
68
137
  private
69
138
 
70
- def redirect_back_or_default(default)
71
- redirect_to(session["user_return_to"] || default)
72
- session["user_return_to"] = nil
73
- end
139
+ def redirect_back_or_default(default)
140
+ redirect_to(session["user_return_to"] || default)
141
+ session["user_return_to"] = nil
142
+ end
74
143
 
75
- def instantiate_controller_and_action_names
76
- @current_action = action_name
77
- @current_controller = controller_name
78
- end
144
+ def set_user_language
145
+ locale = session[:locale]
146
+ locale ||= Spree::Config[:default_locale] unless Spree::Config[:default_locale].blank?
147
+ locale ||= Rails.application.config.i18n.default_locale
148
+ locale ||= I18n.default_locale unless I18n.available_locales.include?(locale.to_sym)
149
+ I18n.locale = locale.to_sym
150
+ end
79
151
 
80
- def associate_user
81
- return unless current_user and current_order
82
- current_order.associate_user!(current_user)
83
- session[:guest_token] = nil
84
- end
152
+ # Returns which layout to render.
153
+ #
154
+ # You can set the layout you want to render inside your Spree configuration with the +:layout+ option.
155
+ #
156
+ # Default layout is: +app/views/spree/layouts/spree_application+
157
+ #
158
+ def get_layout
159
+ layout ||= Spree::Config[:layout]
160
+ end
85
161
 
86
- def set_user_language
87
- locale = session[:locale]
88
- locale ||= Spree::Config[:default_locale] unless Spree::Config[:default_locale].blank?
89
- locale ||= Rails.application.config.i18n.default_locale
90
- locale ||= I18n.default_locale unless I18n.available_locales.map(&:to_s).include?(locale)
91
- I18n.locale = locale
92
- end
93
162
 
94
- # Returns which layout to render.
95
- #
96
- # You can set the layout you want to render inside your Spree configuration with the +:layout+ option.
97
- #
98
- # Default layout is: +app/views/spree/layouts/spree_application+
99
- #
100
- def get_layout
101
- layout ||= Spree::Config[:layout]
102
- end
103
163
  end
104
164
  end
105
165
  end
166
+
@@ -1,6 +1,11 @@
1
1
  module Spree
2
2
  module Core
3
3
  module CurrentOrder
4
+ def self.included(base)
5
+ base.class_eval do
6
+ helper_method :current_order
7
+ end
8
+ end
4
9
 
5
10
  # This should be overridden by an auth-related extension which would then have the
6
11
  # opportunity to associate the new order with the # current user before saving.
@@ -10,6 +10,7 @@ module Spree
10
10
  config.autoload_paths += %W(#{config.root}/lib)
11
11
 
12
12
  def self.activate
13
+ Spree::Order.define_state_machine!
13
14
  end
14
15
 
15
16
  config.to_prepare &method(:activate).to_proc
@@ -22,7 +23,6 @@ module Spree
22
23
  activator.activate(payload)
23
24
  end
24
25
  end
25
-
26
26
  end
27
27
 
28
28
  # We need to reload the routes here due to how Spree sets them up.
@@ -21,8 +21,7 @@ module Spree
21
21
  mail_server_settings[:password] = mail_method.preferred_smtp_password
22
22
  end
23
23
 
24
- tls = mail_method.preferred_secure_connection_type == 'TLS'
25
- mail_server_settings[:enable_starttls_auto] = tls
24
+ mail_server_settings[:enable_starttls_auto] = (mail_method.preferred_secure_connection_type == 'TLS')
26
25
 
27
26
  ActionMailer::Base.smtp_settings = mail_server_settings
28
27
  ActionMailer::Base.perform_deliveries = true
@@ -35,12 +35,8 @@ module Spree
35
35
 
36
36
  def permalink_order
37
37
  order = permalink_options[:order]
38
-
39
- if order
40
- "#{order} ASC,"
41
- end
38
+ "#{order} ASC," if order
42
39
  end
43
-
44
40
  end
45
41
 
46
42
  def save_permalink
@@ -10,10 +10,14 @@ module Spree
10
10
  OldPrefs.where(:key => nil).each do |old_pref|
11
11
  next unless owner = (old_pref.owner rescue nil)
12
12
  unless old_pref.owner_type == "Spree::Activator" || old_pref.owner_type == "Spree::Configuration"
13
- old_pref.key = [owner.class.name, old_pref.name, owner.id].join('::').underscore
14
- old_pref.value_type = owner.preference_type(old_pref.name)
15
- puts "Migrating Preference: #{old_pref.key}"
16
- old_pref.save
13
+ begin
14
+ old_pref.key = [owner.class.name, old_pref.name, owner.id].join('::').underscore
15
+ old_pref.value_type = owner.preference_type(old_pref.name)
16
+ puts "Migrating Preference: #{old_pref.key}"
17
+ old_pref.save
18
+ rescue NoMethodError => ex
19
+ puts ex.message
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ module Core
3
+ module RelationSerialization
4
+ def serializable_hash(options = nil)
5
+ self.map { |a| a.serializable_hash(options) }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -59,7 +59,7 @@ module Spree
59
59
  options = {action_name.to_sym => {format_name.to_sym => {:success => format_value}}}
60
60
  end
61
61
 
62
- self.spree_responders.rmerge!(self.name.to_sym => options)
62
+ self.spree_responders.deep_merge!(self.name.to_sym => options)
63
63
  end
64
64
  end
65
65
  end
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ module Core
3
+ # This module exists to reduce duplication in S3 settings between
4
+ # the Image and Taxon models in Spree
5
+ module S3Support
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ def self.supports_s3(field)
10
+ # Load user defined paperclip settings
11
+ config = Spree::Config
12
+ if config[:use_s3]
13
+ s3_creds = { :access_key_id => config[:s3_access_key], :secret_access_key => config[:s3_secret], :bucket => config[:s3_bucket] }
14
+ self.attachment_definitions[field][:storage] = :s3
15
+ self.attachment_definitions[field][:s3_credentials] = s3_creds
16
+ self.attachment_definitions[field][:s3_headers] = ActiveSupport::JSON.decode(config[:s3_headers])
17
+ self.attachment_definitions[field][:bucket] = config[:s3_bucket]
18
+ self.attachment_definitions[field][:s3_protocol] = config[:s3_protocol] unless config[:s3_protocol].blank?
19
+ self.attachment_definitions[field][:s3_host_alias] = config[:s3_host_alias] unless config[:s3_host_alias].blank?
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -28,7 +28,7 @@ module Spree
28
28
  def get_base_scope
29
29
  base_scope = Spree::Product.active
30
30
  base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
31
- base_scope = get_products_conditions_for(base_scope, keywords)
31
+ base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
32
32
  base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
33
33
  base_scope = add_search_scopes(base_scope)
34
34
  base_scope
@@ -48,10 +48,7 @@ module Spree
48
48
 
49
49
  # method should return new scope based on base_scope
50
50
  def get_products_conditions_for(base_scope, query)
51
- unless query.blank?
52
- base_scope = base_scope.like_any([:name, :description], query.split)
53
- end
54
- base_scope
51
+ base_scope.like_any([:name, :description], query.split)
55
52
  end
56
53
 
57
54
  def prepare(params)