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
@@ -1,9 +1,9 @@
1
1
  module Spree
2
2
  class Address < ActiveRecord::Base
3
- belongs_to :country, :class_name => "Spree::Country"
4
- belongs_to :state, :class_name => "Spree::State"
3
+ belongs_to :country
4
+ belongs_to :state
5
5
 
6
- has_many :shipments, :class_name => "Spree::Shipment"
6
+ has_many :shipments
7
7
 
8
8
  validates :firstname, :lastname, :address1, :city, :zipcode, :country, :phone, :presence => true
9
9
  validate :state_validate
@@ -36,15 +36,7 @@ module Spree
36
36
  end
37
37
 
38
38
  def state_text
39
- state.try(:abbr) || state.try(:name) || state_name
40
- end
41
-
42
- def zone
43
- (state && state.zone) || (country && country.zone)
44
- end
45
-
46
- def zones
47
- @zones ||= Zone.match(self)
39
+ state.nil? ? state_name : (state.abbr.blank? ? state.name : state.abbr)
48
40
  end
49
41
 
50
42
  def same_as?(other)
@@ -31,14 +31,6 @@ module Spree
31
31
  validates :label, :presence => true
32
32
  validates :amount, :numericality => true
33
33
 
34
- scope :tax, lambda { where(:originator_type => 'Spree::TaxRate', :adjustable_type => 'Spree::Order') }
35
- scope :price, lambda { where(:adjustable_type => 'Spree::LineItem') }
36
- scope :shipping, lambda { where(:originator_type => 'Spree::ShippingMethod') }
37
- scope :optional, where(:mandatory => false)
38
- scope :eligible, where(:eligible => true)
39
- scope :charge, where("amount >= 0")
40
- scope :credit, where("amount < 0")
41
-
42
34
  after_save :update_adjustable
43
35
  after_destroy :update_adjustable
44
36
 
@@ -79,5 +71,35 @@ module Spree
79
71
  adjustable.update! if adjustable.is_a? Order
80
72
  end
81
73
 
74
+ class << self
75
+ def tax
76
+ where(:originator_type => 'Spree::TaxRate', :adjustable_type => 'Spree::Order')
77
+ end
78
+
79
+ def price
80
+ where(:adjustable_type => 'Spree::LineItem')
81
+ end
82
+
83
+ def shipping
84
+ where(:originator_type => 'Spree::ShippingMethod')
85
+ end
86
+
87
+ def optional
88
+ where(:mandatory => false)
89
+ end
90
+
91
+ def eligible
92
+ where(:eligible => true)
93
+ end
94
+
95
+ def charge
96
+ where('amount >= 0')
97
+ end
98
+
99
+ def credit
100
+ where('amount < 0')
101
+ end
102
+ end
103
+
82
104
  end
83
105
  end
@@ -35,7 +35,7 @@ module Spree
35
35
  preference :alternative_billing_phone, :boolean, :default => false # Request extra phone for bill addr
36
36
  preference :alternative_shipping_phone, :boolean, :default => false # Request extra phone for ship addr
37
37
  preference :always_put_site_name_in_title, :boolean, :default => true
38
- preference :auto_capture, :boolean, :default => false # automatically capture the creditcard (as opposed to just authorize and capture later)
38
+ preference :auto_capture, :boolean, :default => false # automatically capture the credit card (as opposed to just authorize and capture later)
39
39
  preference :cache_static_content, :boolean, :default => true
40
40
  preference :check_for_spree_alerts, :boolean, :default => true
41
41
  preference :checkout_zone, :string, :default => nil # replace with the name of a zone if you would like to limit the countries
@@ -1,6 +1,4 @@
1
1
  require_dependency 'spree/calculator'
2
- # For #to_d method on Ruby 1.8
3
- require 'bigdecimal/util'
4
2
 
5
3
  module Spree
6
4
  class Calculator::PriceSack < Calculator
@@ -19,12 +17,12 @@ module Spree
19
17
  # as object we always get line items, as calculable we have Coupon, ShippingMethod
20
18
  def compute(object)
21
19
  if object.is_a?(Array)
22
- base = object.map { |o| o.respond_to?(:amount) ? o.amount : BigDecimal(o.to_s) }.sum
20
+ base = object.map { |o| o.respond_to?(:amount) ? o.amount : o.to_d }.sum
23
21
  else
24
- base = object.respond_to?(:amount) ? object.amount : BigDecimal(object.to_s)
22
+ base = object.respond_to?(:amount) ? object.amount : object.to_d
25
23
  end
26
24
 
27
- if base < self.preferred_minimal_amount
25
+ if base >= self.preferred_minimal_amount
28
26
  self.preferred_normal_amount
29
27
  else
30
28
  self.preferred_discount_amount
@@ -1,9 +1,6 @@
1
1
  module Spree
2
2
  class Country < ActiveRecord::Base
3
- has_many :states, :order => "name ASC", :class_name => "Spree::State"
4
-
5
- has_one :zone_member, :as => :zoneable, :class_name => "Spree::ZoneMember"
6
- has_one :zone, :through => :zone_member, :class_name => "Spree::Zone"
3
+ has_many :states, :order => "name ASC"
7
4
 
8
5
  validates :name, :iso_name, :presence => true
9
6
 
@@ -1,6 +1,6 @@
1
1
  module Spree
2
- class Creditcard < ActiveRecord::Base
3
- has_many :payments, :as => :source, :class_name => "Spree::Payment"
2
+ class CreditCard < ActiveRecord::Base
3
+ has_many :payments
4
4
 
5
5
  before_save :set_last_digits
6
6
  after_validation :set_card_type
@@ -14,8 +14,6 @@ module Spree
14
14
  attr_accessible :first_name, :last_name, :number, :verification_value, :year,
15
15
  :month, :gateway_customer_profile_id, :gateway_payment_profile_id
16
16
 
17
- scope :with_payment_profile, where('gateway_customer_profile_id IS NOT NULL')
18
-
19
17
  def set_last_digits
20
18
  number.to_s.gsub!(/\s/,'')
21
19
  verification_value.to_s.gsub!(/\s/,'')
@@ -65,6 +63,8 @@ module Spree
65
63
  cc_type
66
64
  end
67
65
 
66
+ scope :with_payment_profile, where('gateway_customer_profile_id IS NOT NULL')
67
+
68
68
  def actions
69
69
  %w{capture void credit}
70
70
  end
@@ -6,11 +6,11 @@ module Spree
6
6
 
7
7
  preference :server, :string, :default => 'test'
8
8
  preference :test_mode, :boolean, :default => true
9
-
9
+
10
10
  attr_accessible :preferred_server, :preferred_test_mode
11
11
 
12
12
  def payment_source_class
13
- Creditcard
13
+ CreditCard
14
14
  end
15
15
 
16
16
  # instantiates the selected gateway and configures with the options stored in the database
@@ -23,29 +23,29 @@ module Spree
23
23
  payment.source.update_attributes(:gateway_customer_profile_id => generate_profile_id(success))
24
24
  end
25
25
 
26
- def authorize(money, creditcard, options = {})
27
- profile_id = creditcard.gateway_customer_profile_id
28
- if VALID_CCS.include? creditcard.number or (profile_id and profile_id.starts_with? 'BGS-')
26
+ def authorize(money, credit_card, options = {})
27
+ profile_id = credit_card.gateway_customer_profile_id
28
+ if VALID_CCS.include? credit_card.number or (profile_id and profile_id.starts_with? 'BGS-')
29
29
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
30
30
  else
31
31
  ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { :message => 'Bogus Gateway: Forced failure' }, :test => true)
32
32
  end
33
33
  end
34
34
 
35
- def purchase(money, creditcard, options = {})
36
- profile_id = creditcard.gateway_customer_profile_id
37
- if VALID_CCS.include? creditcard.number or (profile_id and profile_id.starts_with? 'BGS-')
35
+ def purchase(money, credit_card, options = {})
36
+ profile_id = credit_card.gateway_customer_profile_id
37
+ if VALID_CCS.include? credit_card.number or (profile_id and profile_id.starts_with? 'BGS-')
38
38
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
39
39
  else
40
40
  ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', :message => 'Bogus Gateway: Forced failure', :test => true)
41
41
  end
42
42
  end
43
43
 
44
- def credit(money, creditcard, response_code, options = {})
44
+ def credit(money, credit_card, response_code, options = {})
45
45
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345')
46
46
  end
47
47
 
48
- def capture(authorization, creditcard, gateway_options)
48
+ def capture(authorization, credit_card, gateway_options)
49
49
  if authorization.response_code == '12345'
50
50
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '67890')
51
51
  else
@@ -54,7 +54,7 @@ module Spree
54
54
 
55
55
  end
56
56
 
57
- def void(response_code, creditcard, options = {})
57
+ def void(response_code, credit_card, options = {})
58
58
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345')
59
59
  end
60
60
 
@@ -77,7 +77,7 @@ module Spree
77
77
  prefix = success ? 'BGS' : 'FAIL'
78
78
  while record
79
79
  random = "#{prefix}-#{Array.new(6){rand(6)}.join}"
80
- record = Creditcard.where(:gateway_customer_profile_id => random).first
80
+ record = CreditCard.where(:gateway_customer_profile_id => random).first
81
81
  end
82
82
  random
83
83
  end
@@ -6,16 +6,16 @@ module Spree
6
6
  false
7
7
  end
8
8
 
9
- def authorize(money, creditcard, options = {})
10
- if VALID_CCS.include? creditcard.number
9
+ def authorize(money, credit_card, options = {})
10
+ if VALID_CCS.include? credit_card.number
11
11
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
12
12
  else
13
13
  ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { :message => 'Bogus Gateway: Forced failure' }, :test => true)
14
14
  end
15
15
  end
16
16
 
17
- def purchase(money, creditcard, options = {})
18
- if VALID_CCS.include? creditcard.number
17
+ def purchase(money, credit_card, options = {})
18
+ if VALID_CCS.include? credit_card.number
19
19
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
20
20
  else
21
21
  ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', :message => 'Bogus Gateway: Forced failure', :test => true)
@@ -9,22 +9,13 @@ module Spree
9
9
  :styles => { :mini => '48x48>', :small => '100x100>', :product => '240x240>', :large => '600x600>' },
10
10
  :default_style => :product,
11
11
  :url => '/spree/products/:id/:style/:basename.:extension',
12
- :path => ':rails_root/public/spree/products/:id/:style/:basename.:extension',
13
- :convert_options => { :all => '-strip' }
12
+ :path => ':rails_root/public/spree/products/:id/:style/:basename.:extension'
14
13
  # save the w,h of the original image (from which others can be calculated)
15
14
  # we need to look at the write-queue for images which have not been saved yet
16
15
  after_post_process :find_dimensions
17
16
 
18
- # Load user defined paperclip settings
19
- if Spree::Config[:use_s3]
20
- s3_creds = { :access_key_id => Spree::Config[:s3_access_key], :secret_access_key => Spree::Config[:s3_secret], :bucket => Spree::Config[:s3_bucket] }
21
- Spree::Image.attachment_definitions[:attachment][:storage] = :s3
22
- Spree::Image.attachment_definitions[:attachment][:s3_credentials] = s3_creds
23
- Spree::Image.attachment_definitions[:attachment][:s3_headers] = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
24
- Spree::Image.attachment_definitions[:attachment][:bucket] = Spree::Config[:s3_bucket]
25
- Spree::Image.attachment_definitions[:attachment][:s3_protocol] = Spree::Config[:s3_protocol] unless Spree::Config[:s3_protocol].blank?
26
- Spree::Image.attachment_definitions[:attachment][:s3_host_alias] = Spree::Config[:s3_host_alias] unless Spree::Config[:s3_host_alias].blank?
27
- end
17
+ include Spree::Core::S3Support
18
+ supports_s3 :attachment
28
19
 
29
20
  Spree::Image.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles])
30
21
  Spree::Image.attachment_definitions[:attachment][:path] = Spree::Config[:attachment_path]
@@ -7,6 +7,8 @@ module Spree
7
7
 
8
8
  scope :backorder, where(:state => 'backordered')
9
9
 
10
+ attr_accessible :shipment
11
+
10
12
  # state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
11
13
  state_machine :initial => 'on_hand' do
12
14
  event :fill_backorder do
@@ -96,8 +98,6 @@ module Spree
96
98
 
97
99
  shipment = order.shipments.detect { |shipment| !shipment.shipped? }
98
100
 
99
- attr_accessible :shipment
100
-
101
101
  sold.times { order.inventory_units.create({:variant => variant, :state => 'sold', :shipment => shipment}, :without_protection => true) }
102
102
  back_order.times { order.inventory_units.create({:variant => variant, :state => 'backordered', :shipment => shipment}, :without_protection => true) }
103
103
  end
@@ -107,10 +107,8 @@ module Spree
107
107
  end
108
108
 
109
109
  def restock_variant
110
- if Spree::Config[:track_inventory_levels]
111
- variant.on_hand += 1
112
- variant.save
113
- end
110
+ variant.on_hand = (variant.on_hand + 1)
111
+ variant.save
114
112
  end
115
113
  end
116
114
  end
@@ -1,12 +1,9 @@
1
- # Default implementation of User. This class is intended to be modified by extensions (ex. spree_auth)
1
+ # Default implementation of User. This class is intended to be modified by extensions (ex. spree_auth_devise)
2
2
  module Spree
3
- class User < ActiveRecord::Base
4
- include Core::UserBanners
5
-
3
+ class LegacyUser < ActiveRecord::Base
4
+ self.table_name = 'spree_users'
6
5
  attr_accessible :email, :password, :password_confirmation
7
6
 
8
- has_many :orders
9
-
10
7
  belongs_to :ship_address, :class_name => 'Spree::Address'
11
8
  belongs_to :bill_address, :class_name => 'Spree::Address'
12
9
 
@@ -21,6 +18,10 @@ module Spree
21
18
  create
22
19
  end
23
20
 
21
+ def has_spree_role?(role)
22
+ true
23
+ end
24
+
24
25
  attr_accessor :password
25
26
  attr_accessor :password_confirmation
26
27
  end
@@ -1,11 +1,11 @@
1
1
  module Spree
2
2
  class LineItem < ActiveRecord::Base
3
3
  before_validation :adjust_quantity
4
- belongs_to :order, :class_name => "Spree::Order"
5
- belongs_to :variant, :class_name => "Spree::Variant"
4
+ belongs_to :order
5
+ belongs_to :variant
6
6
 
7
7
  has_one :product, :through => :variant
8
- has_many :adjustments, :as => :adjustable, :class_name => "Spree::Adjustment"
8
+ has_many :adjustments, :as => :adjustable, :dependent => :destroy
9
9
 
10
10
  before_validation :copy_price
11
11
 
@@ -80,7 +80,6 @@ module Spree
80
80
 
81
81
  def update_order
82
82
  # update the order totals, etc.
83
- order.create_tax_charge!
84
83
  order.update!
85
84
  end
86
85
 
@@ -98,7 +97,7 @@ module Spree
98
97
  end
99
98
 
100
99
  def quantity_no_less_than_shipped
101
- already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.select { |i| i.variant == variant }.count }
100
+ already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.count { |i| i.variant == variant } }
102
101
  unless quantity >= already_shipped
103
102
  errors.add(:quantity, I18n.t('validation.cannot_be_less_than_shipped_units'))
104
103
  end
@@ -1,16 +1,14 @@
1
1
  module Spree
2
2
  class OptionType < ActiveRecord::Base
3
- has_many :option_values, :order => :position, :dependent => :destroy, :class_name => "Spree::OptionValue"
4
- has_many :product_option_types, :dependent => :destroy, :class_name => "Spree::ProductOptionType"
5
- has_and_belongs_to_many :prototypes, :join_table => 'spree_option_types_prototypes', :class_name => "Spree::Prototype"
3
+ has_many :option_values, :order => :position, :dependent => :destroy
4
+ has_many :product_option_types, :dependent => :destroy
5
+ has_and_belongs_to_many :prototypes, :join_table => 'spree_option_types_prototypes'
6
6
 
7
- attr_accessible :name, :presentation
7
+ attr_accessible :name, :presentation, :option_values_attributes
8
8
 
9
9
  validates :name, :presentation, :presence => true
10
10
  default_scope :order => "#{self.table_name}.position"
11
11
 
12
- attr_accessible :option_values_attributes
13
-
14
12
  accepts_nested_attributes_for :option_values, :reject_if => lambda { |ov| ov[:name].blank? || ov[:presentation].blank? }, :allow_destroy => true
15
13
  end
16
14
  end
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class OptionValue < ActiveRecord::Base
3
- belongs_to :option_type, :class_name => "Spree::OptionType"
3
+ belongs_to :option_type
4
4
  acts_as_list :scope => :option_type
5
5
  has_and_belongs_to_many :variants, :join_table => 'spree_option_values_variants', :class_name => "Spree::Variant"
6
6
 
@@ -2,24 +2,38 @@ require 'spree/core/validators/email'
2
2
 
3
3
  module Spree
4
4
  class Order < ActiveRecord::Base
5
+ include Checkout
6
+ checkout_flow do
7
+ go_to_state :address
8
+ go_to_state :delivery
9
+ go_to_state :payment, :if => lambda { |order| order.payment_required? }
10
+ go_to_state :confirm, :if => lambda { |order| order.confirmation_required? }
11
+ go_to_state :complete
12
+ remove_transition :from => :delivery, :to => :confirm
13
+ end
14
+
15
+ token_resource
16
+
5
17
  attr_accessible :line_items, :bill_address_attributes, :ship_address_attributes, :payments_attributes,
6
18
  :ship_address, :bill_address, :line_items_attributes, :number,
7
19
  :shipping_method_id, :email, :use_billing, :special_instructions
8
20
 
9
- belongs_to :user, :class_name => "Spree::User"
21
+ if Spree.user_class
22
+ belongs_to :user, :class_name => Spree.user_class.to_s
23
+ else
24
+ belongs_to :user
25
+ end
10
26
 
11
- belongs_to :bill_address, :foreign_key => 'bill_address_id', :class_name => 'Spree::Address'
12
- alias_method :billing_address, :bill_address
13
- alias_method :billing_address=, :bill_address=
27
+ belongs_to :bill_address, :foreign_key => :bill_address_id, :class_name => "Spree::Address"
28
+ alias_attribute :billing_address, :bill_address
14
29
 
15
- belongs_to :ship_address, :foreign_key => 'ship_address_id', :class_name => 'Spree::Address'
16
- alias_method :shipping_address, :ship_address
17
- alias_method :shipping_address=, :ship_address=
30
+ belongs_to :ship_address, :foreign_key => :ship_address_id, :class_name => "Spree::Address"
31
+ alias_attribute :shipping_address, :ship_address
18
32
 
19
- belongs_to :shipping_method, :class_name => "Spree::ShippingMethod"
33
+ belongs_to :shipping_method
20
34
 
21
35
  has_many :state_changes, :as => :stateful
22
- has_many :line_items, :dependent => :destroy, :order => "created_at ASC"
36
+ has_many :line_items, :dependent => :destroy
23
37
  has_many :inventory_units
24
38
  has_many :payments, :dependent => :destroy
25
39
  has_many :shipments, :dependent => :destroy
@@ -34,8 +48,10 @@ module Spree
34
48
 
35
49
  # Needs to happen before save_permalink is called
36
50
  before_validation :generate_order_number, :on => :create
51
+ before_validation :clone_billing_address, :if => :use_billing?
52
+ attr_accessor :use_billing
37
53
 
38
- before_create :create_user
54
+ before_create :link_by_email
39
55
  after_create :create_tax_charge!
40
56
 
41
57
  # TODO: validate the format of the email as well (but we can't rely on authlogic anymore to help with validation)
@@ -48,56 +64,6 @@ module Spree
48
64
  class_attribute :update_hooks
49
65
  self.update_hooks = Set.new
50
66
 
51
- # order state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
52
- state_machine :initial => 'cart', :use_transactions => false do
53
-
54
- event :next do
55
- transition :from => 'cart', :to => 'address'
56
- transition :from => 'address', :to => 'delivery'
57
- transition :from => 'delivery', :to => 'payment', :if => :payment_required?
58
- transition :from => 'delivery', :to => 'complete'
59
- transition :from => 'confirm', :to => 'complete'
60
-
61
- # note: some payment methods will not support a confirm step
62
- transition :from => 'payment', :to => 'confirm',
63
- :if => Proc.new { |order| order.payment_method && order.payment_method.payment_profiles_supported? }
64
-
65
- transition :from => 'payment', :to => 'complete'
66
- end
67
-
68
- event :cancel do
69
- transition :to => 'canceled', :if => :allow_cancel?
70
- end
71
- event :return do
72
- transition :to => 'returned', :from => 'awaiting_return', :unless=>:awaiting_returns?
73
- end
74
- event :resume do
75
- transition :to => 'resumed', :from => 'canceled', :if => :allow_resume?
76
- end
77
- event :authorize_return do
78
- transition :to => 'awaiting_return'
79
- end
80
-
81
- before_transition :to => 'complete' do |order|
82
- begin
83
- order.process_payments!
84
- rescue Core::GatewayError
85
- !!Spree::Config[:allow_checkout_on_gateway_error]
86
- end
87
- end
88
-
89
- before_transition :to => ['delivery'] do |order|
90
- order.shipments.each { |s| s.destroy unless s.shipping_method.available_to_order?(order) }
91
- end
92
-
93
- after_transition :to => 'complete', :do => :finalize!
94
- after_transition :to => 'delivery', :do => :create_tax_charge!
95
- after_transition :to => 'payment', :do => :create_shipment!
96
- after_transition :to => 'resumed', :do => :after_resume
97
- after_transition :to => 'canceled', :do => :after_cancel
98
-
99
- end
100
-
101
67
  def self.by_number(number)
102
68
  where(:number => number)
103
69
  end
@@ -107,7 +73,7 @@ module Spree
107
73
  end
108
74
 
109
75
  def self.by_customer(customer)
110
- joins(:user).where("#{Spree::User.table_name}.email" => customer)
76
+ joins(:user).where("#{Spree.user_class.table_name}.email" => customer)
111
77
  end
112
78
 
113
79
  def self.by_state(state)
@@ -127,17 +93,9 @@ module Spree
127
93
  self.update_hooks.add(hook)
128
94
  end
129
95
 
130
- def checkout_steps
131
- if payment and payment.payment_method.payment_profiles_supported?
132
- %w(address delivery payment confirm complete)
133
- else
134
- %w(address delivery payment complete)
135
- end
136
- end
137
-
138
96
  # For compatiblity with Calculator::PriceSack
139
97
  def amount
140
- line_items.map(&:amount).sum
98
+ line_items.sum(&:amount)
141
99
  end
142
100
 
143
101
  def to_param
@@ -160,9 +118,14 @@ module Spree
160
118
  total.to_f > 0.0
161
119
  end
162
120
 
121
+ # If true, causes the confirmation step to happen during the checkout process
122
+ def confirmation_required?
123
+ payment_method && payment_method.payment_profiles_supported?
124
+ end
125
+
163
126
  # Indicates the number of items in the order
164
127
  def item_count
165
- line_items.map(&:quantity).sum
128
+ line_items.sum(:quantity)
166
129
  end
167
130
 
168
131
  # Indicates whether there are any backordered InventoryUnits associated with the Order.
@@ -243,22 +206,6 @@ module Spree
243
206
  update_hooks.each { |hook| self.send hook }
244
207
  end
245
208
 
246
- def restore_state
247
- # pop the resume event so we can see what the event before that was
248
- state_changes.pop if state_changes.last.name == 'resume'
249
- update_attribute('state', state_changes.last.previous_state)
250
-
251
- if paid?
252
- raise 'do something with inventory'
253
- #Spree::InventoryUnit.assign_opening_inventory(self) if inventory_units.empty?
254
- #shipment.inventory_units = inventory_units
255
- #shipment.ready!
256
- end
257
- end
258
-
259
- before_validation :clone_billing_address, :if => :use_billing?
260
- attr_accessor :use_billing
261
-
262
209
  def clone_billing_address
263
210
  if bill_address and self.ship_address.nil?
264
211
  self.ship_address = bill_address.clone
@@ -279,12 +226,8 @@ module Spree
279
226
  true
280
227
  end
281
228
 
282
- def awaiting_returns?
283
- return_authorizations.any? { |return_authorization| return_authorization.authorized? }
284
- end
285
-
286
229
  def add_variant(variant, quantity = 1)
287
- current_item = contains?(variant)
230
+ current_item = find_line_item_by_variant(variant)
288
231
  if current_item
289
232
  current_item.quantity += quantity
290
233
  current_item.save
@@ -295,23 +238,19 @@ module Spree
295
238
  self.line_items << current_item
296
239
  end
297
240
 
298
- # populate line_items attributes for additional_fields entries
299
- # that have populate => [:line_item]
300
- Variant.additional_fields.select { |f| !f[:populate].nil? && f[:populate].include?(:line_item) }.each do |field|
301
- value = ''
302
-
303
- if field[:only].nil? || field[:only].include?(:variant)
304
- value = variant.send(field[:name].gsub(' ', '_').downcase)
305
- elsif field[:only].include?(:product)
306
- value = variant.product.send(field[:name].gsub(' ', '_').downcase)
307
- end
308
- current_item.update_attribute(field[:name].gsub(' ', '_').downcase, value)
309
- end
310
-
311
241
  self.reload
312
242
  current_item
313
243
  end
314
244
 
245
+ # Associates the specified user with the order.
246
+ def associate_user!(user)
247
+ self.user = user
248
+ self.email = user.email
249
+ # disable validations since they can cause issues when associating
250
+ # an incomplete address during the address step
251
+ save(:validate => false)
252
+ end
253
+
315
254
  # FIXME refactor this method and implement validation using validates_* utilities
316
255
  def generate_order_number
317
256
  record = true
@@ -329,14 +268,18 @@ module Spree
329
268
  end
330
269
 
331
270
  def contains?(variant)
332
- line_items.detect { |line_item| line_item.variant_id == variant.id }
271
+ find_line_item_by_variant(variant).present?
333
272
  end
334
273
 
335
274
  def quantity_of(variant)
336
- line_item = line_items.find { |line_item| line_item.variant_id == variant.id }
275
+ line_item = find_line_item_by_variant(variant)
337
276
  line_item ? line_item.quantity : 0
338
277
  end
339
278
 
279
+ def find_line_item_by_variant(variant)
280
+ line_items.detect { |line_item| line_item.variant_id == variant.id }
281
+ end
282
+
340
283
  def ship_total
341
284
  adjustments.shipping.map(&:amount).sum
342
285
  end
@@ -345,14 +288,16 @@ module Spree
345
288
  adjustments.tax.map(&:amount).sum
346
289
  end
347
290
 
291
+ # Clear shipment when transitioning to delivery step of checkout if the
292
+ # current shipping address is not eligible for the existing shipping method
293
+ def remove_invalid_shipments!
294
+ shipments.each { |s| s.destroy unless s.shipping_method.available_to_order?(self) }
295
+ end
296
+
348
297
  # Creates new tax charges if there are any applicable rates. If prices already
349
298
  # include taxes then price adjustments are created instead.
350
299
  def create_tax_charge!
351
- # destroy any previous adjustments (eveything is recalculated from scratch)
352
- adjustments.tax.each(&:destroy)
353
- price_adjustments.each(&:destroy)
354
-
355
- TaxRate.match(self).each { |rate| rate.adjust(self) }
300
+ Spree::TaxRate.adjust(self)
356
301
  end
357
302
 
358
303
  # Creates a new shipment (adjustment is created by shipment model)
@@ -366,7 +311,6 @@ module Spree
366
311
  :address => self.ship_address,
367
312
  :inventory_units => self.inventory_units}, :without_protection => true)
368
313
  end
369
-
370
314
  end
371
315
 
372
316
  def outstanding_balance
@@ -383,13 +327,9 @@ module Spree
383
327
  end
384
328
  end
385
329
 
386
- def creditcards
387
- creditcard_ids = payments.from_creditcard.map(&:source_id).uniq
388
- Creditcard.scoped(:conditions => { :id => creditcard_ids })
389
- end
390
-
391
- def process_payments!
392
- ret = payments.each(&:process!)
330
+ def credit_cards
331
+ credit_card_ids = payments.from_credit_card.map(&:source_id).uniq
332
+ CreditCard.scoped(:conditions => { :id => credit_card_ids })
393
333
  end
394
334
 
395
335
  # Finalizes an in progress order after checkout is complete.
@@ -405,7 +345,7 @@ module Spree
405
345
  :previous_state => 'cart',
406
346
  :next_state => 'complete',
407
347
  :name => 'order' ,
408
- :user_id => (User.respond_to?(:current) && User.current.try(:id)) || self.user_id
348
+ :user_id => self.user_id
409
349
  }, :without_protection => true)
410
350
  end
411
351
 
@@ -455,6 +395,14 @@ module Spree
455
395
  end
456
396
  end
457
397
 
398
+ def process_payments!
399
+ begin
400
+ payments.each(&:process!)
401
+ rescue Core::GatewayError
402
+ !!Spree::Config[:allow_checkout_on_gateway_error]
403
+ end
404
+ end
405
+
458
406
  def billing_firstname
459
407
  bill_address.try(:firstname)
460
408
  end
@@ -483,10 +431,20 @@ module Spree
483
431
  adjustments.destroy_all
484
432
  end
485
433
 
434
+ # destroy any previous adjustments.
435
+ # Adjustments will be recalculated during order update.
436
+ def clear_adjustments!
437
+ adjustments.tax.each(&:destroy)
438
+ price_adjustments.each(&:destroy)
439
+ end
440
+
441
+ def has_step?(step)
442
+ checkout_steps.include?(step)
443
+ end
444
+
486
445
  private
487
- def create_user
488
- self.email = user.email if self.user and not user.anonymous?
489
- self.user ||= User.anonymous!
446
+ def link_by_email
447
+ self.email = user.email if self.user
490
448
  end
491
449
 
492
450
  # Updates the +shipment_state+ attribute according to the following logic:
@@ -520,7 +478,7 @@ module Spree
520
478
  :previous_state => old_shipment_state,
521
479
  :next_state => self.shipment_state,
522
480
  :name => 'shipment',
523
- :user_id => (User.respond_to?(:current) && User.current && User.current.id) || self.user_id
481
+ :user_id => self.user_id
524
482
  }, :without_protection => true)
525
483
  end
526
484
  end
@@ -550,7 +508,7 @@ module Spree
550
508
  :previous_state => old_payment_state,
551
509
  :next_state => self.payment_state,
552
510
  :name => 'payment',
553
- :user_id => (User.respond_to?(:current) && User.current && User.current.id) || self.user_id
511
+ :user_id => self.user_id
554
512
  }, :without_protection => true)
555
513
  end
556
514
  end
@@ -587,25 +545,25 @@ module Spree
587
545
  end
588
546
 
589
547
  def has_available_shipment
590
- return unless :address == state_name.to_sym
548
+ return unless has_step?("delivery")
549
+ return unless address?
591
550
  return unless ship_address && ship_address.valid?
592
551
  errors.add(:base, :no_shipping_methods_available) if available_shipping_methods.empty?
593
552
  end
594
553
 
595
554
  def has_available_payment
596
- return unless :delivery == state_name.to_sym
555
+ return unless delivery?
597
556
  errors.add(:base, :no_payment_methods_available) if available_payment_methods.empty?
598
557
  end
599
558
 
600
559
  def after_cancel
601
- if shipment_state == 'pending'
602
- self.update_attribute(:payment_state, 'credit_owed')
603
- end
604
-
605
560
  restock_items!
606
561
 
607
562
  #TODO: make_shipments_pending
608
563
  OrderMailer.cancel_email(self).deliver
564
+ unless %w(partial shipped).include?(shipment_state)
565
+ self.payment_state = 'credit_owed'
566
+ end
609
567
  end
610
568
 
611
569
  def restock_items!