spree_core 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +26 -0
  3. data/app/helpers/spree/taxons_helper.rb +2 -2
  4. data/app/models/concerns/spree/user_api_authentication.rb +13 -0
  5. data/app/models/concerns/spree/user_reporting.rb +27 -0
  6. data/app/models/spree/adjustment.rb +3 -2
  7. data/app/models/spree/app_configuration.rb +1 -0
  8. data/app/models/spree/calculator/default_tax.rb +5 -1
  9. data/app/models/spree/calculator.rb +2 -2
  10. data/app/models/spree/credit_card.rb +11 -5
  11. data/app/models/spree/gateway.rb +25 -0
  12. data/app/models/spree/item_adjustments.rb +2 -0
  13. data/app/models/spree/legacy_user.rb +2 -3
  14. data/app/models/spree/line_item.rb +7 -0
  15. data/app/models/spree/order/checkout.rb +19 -7
  16. data/app/models/spree/order/currency_updater.rb +40 -0
  17. data/app/models/spree/order.rb +19 -3
  18. data/app/models/spree/order_updater.rb +1 -1
  19. data/app/models/spree/payment.rb +5 -2
  20. data/app/models/spree/payment_method.rb +1 -0
  21. data/app/models/spree/product/scopes.rb +13 -17
  22. data/app/models/spree/product.rb +10 -2
  23. data/app/models/spree/promotion/actions/free_shipping.rb +4 -2
  24. data/app/models/spree/promotion/rules/product.rb +0 -9
  25. data/app/models/spree/promotion.rb +1 -1
  26. data/app/models/spree/shipment.rb +19 -14
  27. data/app/models/spree/shipping_method.rb +2 -2
  28. data/app/models/spree/shipping_rate.rb +15 -9
  29. data/app/models/spree/stock/estimator.rb +4 -1
  30. data/app/models/spree/stock_location.rb +1 -0
  31. data/app/models/spree/tax_rate.rb +81 -7
  32. data/config/initializers/user_class_extensions.rb +3 -0
  33. data/config/locales/en.yml +26 -0
  34. data/db/default/spree/countries.rb +2 -1
  35. data/db/migrate/20130213191427_create_default_stock.rb +3 -3
  36. data/db/migrate/20130417120035_update_adjustment_states.rb +2 -2
  37. data/db/migrate/20130417123427_add_shipping_rates_to_shipments.rb +1 -1
  38. data/db/migrate/20130509115210_add_number_to_stock_transfer.rb +1 -1
  39. data/db/migrate/20130802022321_migrate_tax_categories_to_line_items.rb +5 -7
  40. data/db/migrate/20140307235515_add_user_id_to_spree_credit_cards.rb +13 -0
  41. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -6
  42. data/lib/spree/core/controller_helpers/auth.rb +10 -1
  43. data/lib/spree/core/controller_helpers/order.rb +1 -1
  44. data/lib/spree/core/controller_helpers/respond_with.rb +6 -1
  45. data/lib/spree/core/importer/order.rb +168 -0
  46. data/lib/spree/core/importer.rb +8 -0
  47. data/lib/spree/core/product_duplicator.rb +1 -1
  48. data/lib/spree/core/user_address.rb +2 -0
  49. data/lib/spree/core/user_payment_source.rb +20 -0
  50. data/lib/spree/core/version.rb +1 -1
  51. data/lib/spree/core.rb +4 -0
  52. data/lib/spree/migrations.rb +1 -1
  53. data/lib/spree/permitted_attributes.rb +1 -1
  54. data/lib/spree/testing_support/capybara_ext.rb +23 -1
  55. data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -6
  56. data/lib/spree/testing_support/factories/order_factory.rb +8 -8
  57. data/lib/spree/testing_support/factories/shipping_method_factory.rb +3 -1
  58. data/lib/spree/testing_support/factories/user_factory.rb +5 -0
  59. metadata +11 -3
@@ -6,7 +6,7 @@ module Spree
6
6
  belongs_to :address, class_name: 'Spree::Address', inverse_of: :shipments
7
7
  belongs_to :stock_location, class_name: 'Spree::StockLocation'
8
8
 
9
- has_many :shipping_rates, dependent: :delete_all
9
+ has_many :shipping_rates, -> { order('cost ASC') }, dependent: :delete_all
10
10
  has_many :shipping_methods, through: :shipping_rates
11
11
  has_many :state_changes, as: :stateful
12
12
  has_many :inventory_units, dependent: :delete_all, inverse_of: :shipment
@@ -94,7 +94,7 @@ module Spree
94
94
  end
95
95
 
96
96
  def add_shipping_method(shipping_method, selected = false)
97
- shipping_rates.create(shipping_method: shipping_method, selected: selected)
97
+ shipping_rates.create(shipping_method: shipping_method, selected: selected, cost: cost)
98
98
  end
99
99
 
100
100
  def selected_shipping_rate
@@ -167,6 +167,10 @@ module Spree
167
167
  Spree::Money.new(discounted_cost, { currency: currency })
168
168
  end
169
169
 
170
+ def display_final_price
171
+ Spree::Money.new(final_price, { currency: currency })
172
+ end
173
+
170
174
  def display_item_cost
171
175
  Spree::Money.new(item_cost, { currency: currency })
172
176
  end
@@ -178,12 +182,16 @@ module Spree
178
182
  ManifestItem = Struct.new(:line_item, :variant, :quantity, :states)
179
183
 
180
184
  def manifest
181
- inventory_units.group_by(&:variant).map do |variant, units|
182
- units.group_by(&:line_item).map do |line_item, units|
185
+ # Grouping by the ID means that we don't have to call out to the association accessor
186
+ # This makes the grouping by faster because it results in less SQL cache hits.
187
+ inventory_units.group_by(&:variant_id).map do |variant_id, units|
188
+ units.group_by(&:line_item_id).map do |line_item_id, units|
183
189
 
184
190
  states = {}
185
191
  units.group_by(&:state).each { |state, iu| states[state] = iu.count }
186
192
 
193
+ line_item = units.first.line_item
194
+ variant = units.first.variant
187
195
  ManifestItem.new(line_item, variant, units.length, states)
188
196
  end
189
197
  end.flatten
@@ -269,17 +277,14 @@ module Spree
269
277
  )
270
278
  end
271
279
 
272
- def persist_cost
273
- self.cost = selected_shipping_rate.cost
274
- update_amounts
275
- end
276
-
277
280
  def update_amounts
278
- self.update_columns(
279
- cost: selected_shipping_rate.cost,
280
- adjustment_total: adjustments.map(&:update!).compact.sum,
281
- updated_at: Time.now,
282
- )
281
+ if selected_shipping_rate
282
+ self.update_columns(
283
+ cost: selected_shipping_rate.cost,
284
+ adjustment_total: adjustments.additional.map(&:update!).compact.sum,
285
+ updated_at: Time.now,
286
+ )
287
+ end
283
288
  end
284
289
 
285
290
  private
@@ -1,15 +1,15 @@
1
1
  module Spree
2
2
  class ShippingMethod < ActiveRecord::Base
3
+ acts_as_paranoid
3
4
  include Spree::Core::CalculatedAdjustments
4
5
  DISPLAY = [:both, :front_end, :back_end]
5
6
 
6
7
  default_scope -> { where(deleted_at: nil) }
7
8
 
8
- has_many :adjustments, as: :source
9
- has_many :shipments
10
9
  has_many :shipping_method_categories, :dependent => :destroy
11
10
  has_many :shipping_categories, through: :shipping_method_categories
12
11
  has_many :shipping_rates, inverse_of: :shipping_method
12
+ has_many :shipments, :through => :shipping_rates
13
13
 
14
14
  has_and_belongs_to_many :zones, :join_table => 'spree_shipping_methods_zones',
15
15
  :class_name => 'Spree::Zone',
@@ -4,11 +4,6 @@ module Spree
4
4
  belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
5
5
  belongs_to :tax_rate, class_name: 'Spree::TaxRate'
6
6
 
7
- scope :with_shipping_method,
8
- -> { includes(:shipping_method).
9
- references(:shipping_method).
10
- order("cost ASC") }
11
-
12
7
  delegate :order, :currency, to: :shipment
13
8
  delegate :name, to: :shipping_method
14
9
 
@@ -16,17 +11,24 @@ module Spree
16
11
  Spree::Money.new(cost, currency: currency)
17
12
  end
18
13
 
19
- def display_tax_amount
20
- Spree::Money.new(tax_rate.calculator.compute_shipping_rate(self), currency: currency)
14
+ def calculate_tax_amount
15
+ tax_rate.calculator.compute_shipping_rate(self)
21
16
  end
22
17
 
23
18
  def display_price
24
19
  price = display_base_price.to_s
25
20
  if tax_rate
26
- amount = "#{display_tax_amount} #{tax_rate.name}"
21
+ tax_amount = calculate_tax_amount
27
22
  if tax_rate.included_in_price?
28
- price += " (incl. #{amount})"
23
+ if tax_amount > 0
24
+ amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
25
+ price += " (incl. #{amount})"
26
+ else
27
+ amount = "#{display_tax_amount(tax_amount*-1)} #{tax_rate.name}"
28
+ price += " (excl. #{amount})"
29
+ end
29
30
  else
31
+ amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
30
32
  price += " (+ #{amount})"
31
33
  end
32
34
  end
@@ -34,6 +36,10 @@ module Spree
34
36
  end
35
37
  alias_method :display_cost, :display_price
36
38
 
39
+ def display_tax_amount(tax_amount)
40
+ Spree::Money.new(tax_amount, currency: currency)
41
+ end
42
+
37
43
  def shipping_method
38
44
  Spree::ShippingMethod.unscoped { super }
39
45
  end
@@ -32,7 +32,10 @@ module Spree
32
32
  tax_category = shipping_method.tax_category
33
33
  if tax_category
34
34
  tax_rate = tax_category.tax_rates.detect do |rate|
35
- rate.zone == package.order.tax_zone
35
+ # If the rate's zone matches the order's zone, a positive adjustment will be applied.
36
+ # If the rate is from the default tax zone, then a negative adjustment will be applied.
37
+ # See the tests in shipping_rate_spec.rb for an example of this.d
38
+ rate.zone == package.order.tax_zone || rate.zone.default_tax?
36
39
  end
37
40
  end
38
41
 
@@ -1,5 +1,6 @@
1
1
  module Spree
2
2
  class StockLocation < ActiveRecord::Base
3
+ has_many :shipments
3
4
  has_many :stock_items, dependent: :delete_all
4
5
  has_many :stock_movements, through: :stock_items
5
6
 
@@ -26,9 +26,28 @@ module Spree
26
26
  # Gets the array of TaxRates appropriate for the specified order
27
27
  def self.match(order)
28
28
  return [] unless order.tax_zone
29
- all.select do |rate|
30
- (!rate.included_in_price && (rate.zone == order.tax_zone || rate.zone.contains?(order.tax_zone) || (order.tax_address.nil? && rate.zone.default_tax))) ||
31
- rate.included_in_price
29
+ rates = all.select do |rate|
30
+ # Why "potentially"?
31
+ # Go see the documentation for that method.
32
+ rate.potentially_applicable?(order)
33
+ end
34
+
35
+ # Imagine with me this scenario:
36
+ # You are living in Spain and you have a store which ships to France.
37
+ # Spain is therefore your default tax rate.
38
+ # When you ship to Spain, you want the Spanish rate to apply.
39
+ # When you ship to France, you want the French rate to apply.
40
+ #
41
+ # Normally, Spree would notice that you have two potentially applicable
42
+ # tax rates for one particular item.
43
+ # When you ship to Spain, only the Spanish one will apply.
44
+ # When you ship to France, you'll see a Spanish refund AND a French tax.
45
+ # This little bit of code at the end stops the Spanish refund from appearing.
46
+ #
47
+ # For further discussion, see #4397 and #4327.
48
+ rates.delete_if do |rate|
49
+ rate.included_in_price? &&
50
+ (rates - [rate]).map(&:tax_category).include?(rate.tax_category)
32
51
  end
33
52
  end
34
53
 
@@ -48,6 +67,7 @@ module Spree
48
67
  end
49
68
  end
50
69
 
70
+ # This method is best described by the documentation on #potentially_applicable?
51
71
  def self.adjust(order, items)
52
72
  rates = self.match(order)
53
73
  tax_categories = rates.map(&:tax_category)
@@ -75,13 +95,62 @@ module Spree
75
95
  rate || 0
76
96
  end
77
97
 
98
+
99
+ # Tax rates can *potentially* be applicable to an order.
100
+ # We do not know if they are/aren't until we attempt to apply these rates to
101
+ # the items contained within the Order itself.
102
+ # For instance, if a rate passes the criteria outlined in this method,
103
+ # but then has a tax category that doesn't match against any of the line items
104
+ # inside of the order, then that tax rate will not be applicable to anything.
105
+ # For instance:
106
+ #
107
+ # Zones:
108
+ # - Spain (default tax zone)
109
+ # - France
110
+ #
111
+ # Tax rates: (note: amounts below do not actually reflect real VAT rates)
112
+ # 21% inclusive - "Clothing" - Spain
113
+ # 18% inclusive - "Clothing" - France
114
+ # 10% inclusive - "Food" - Spain
115
+ # 8% inclusive - "Food" - France
116
+ # 5% inclusive - "Hotels" - Spain
117
+ # 2% inclusive - "Hotels" - France
118
+ #
119
+ # Order has:
120
+ # Line Item #1 - Tax Category: Clothing
121
+ # Line Item #2 - Tax Category: Food
122
+ #
123
+ # Tax rates that should be selected:
124
+ #
125
+ # 21% inclusive - "Clothing" - Spain
126
+ # 10% inclusive - "Food" - Spain
127
+ #
128
+ # If the order's address changes to one in France, then the tax will be recalculated:
129
+ #
130
+ # 18% inclusive - "Clothing" - France
131
+ # 8% inclusive - "Food" - France
132
+ #
133
+ # Note here that the "Hotels" tax rates will not be used at all.
134
+ # This is because there are no items which have the tax category of "Hotels".
135
+ #
136
+ # Under no circumstances should negative adjustments be applied for the Spanish tax rates.
137
+ #
138
+ # Those rates should never come into play at all and only the French rates should apply.
139
+ def potentially_applicable?(order)
140
+ # If the rate's zone matches the order's tax zone, then it's applicable.
141
+ self.zone == order.tax_zone ||
142
+ # If the rate's zone *contains* the order's tax zone, then it's applicable.
143
+ self.zone.contains?(order.tax_zone) ||
144
+ # 1) The rate's zone is the default zone, then it's always applicable.
145
+ (self.included_in_price? && self.zone.default_tax)
146
+ end
147
+
78
148
  # Creates necessary tax adjustments for the order.
79
149
  def adjust(order, item)
80
- amount = calculator.compute(item)
150
+ amount = compute_amount(item)
81
151
  return if amount == 0
82
152
 
83
- included = included_in_price &&
84
- Zone.default_tax.contains?(item.order.tax_zone)
153
+ included = included_in_price && default_zone_or_zone_match?(item)
85
154
 
86
155
  if amount < 0
87
156
  label = Spree.t(:refund) + ' ' + create_label
@@ -99,7 +168,7 @@ module Spree
99
168
  # This method is used by Adjustment#update to recalculate the cost.
100
169
  def compute_amount(item)
101
170
  if included_in_price
102
- if Zone.default_tax.contains? item.order.tax_zone
171
+ if default_zone_or_zone_match?(item)
103
172
  calculator.compute(item)
104
173
  else
105
174
  # In this case, it's a refund.
@@ -110,6 +179,11 @@ module Spree
110
179
  end
111
180
  end
112
181
 
182
+ def default_zone_or_zone_match?(item)
183
+ Zone.default_tax.contains?(item.order.tax_zone) ||
184
+ item.order.tax_zone == self.zone
185
+ end
186
+
113
187
  private
114
188
 
115
189
  def create_label
@@ -1,6 +1,9 @@
1
1
  Spree::Core::Engine.config.to_prepare do
2
2
  if Spree.user_class
3
3
  Spree.user_class.class_eval do
4
+
5
+ include Spree::UserReporting
6
+ include Spree::UserApiAuthentication
4
7
  has_and_belongs_to_many :spree_roles,
5
8
  :join_table => 'spree_roles_users',
6
9
  :foreign_key => "user_id",
@@ -189,6 +189,9 @@ en:
189
189
  spree/state:
190
190
  one: State
191
191
  other: States
192
+ spree/stock_movement:
193
+ one: Stock Movement
194
+ other: Stock Movements
192
195
  spree/stock_location:
193
196
  one: Stock Location
194
197
  other: Stock Locations
@@ -229,6 +232,10 @@ en:
229
232
  attributes:
230
233
  base:
231
234
  card_expired: "Card has expired"
235
+ spree/line_item:
236
+ attributes:
237
+ currency:
238
+ must_match_order_currency: "Must match order currency"
232
239
  devise:
233
240
  confirmations:
234
241
  confirmed: Your account was successfully confirmed. You are now signed in.
@@ -339,6 +346,15 @@ en:
339
346
  taxonomies: Taxonomies
340
347
  taxons: Taxons
341
348
  users: Users
349
+ user:
350
+ account: Account
351
+ addresses: Addresses
352
+ items: Items
353
+ items_purchased: Items Purchased
354
+ order_history: Order History
355
+ order_num: "Order #"
356
+ orders: Orders
357
+ user_information: User Information
342
358
  administration: Administration
343
359
  agree_to_privacy_policy: Agree to Privacy Policy
344
360
  agree_to_terms_of_service: Agree to Terms of Service
@@ -370,6 +386,7 @@ en:
370
386
  authorization_failure: Authorization Failure
371
387
  auto_capture: Auto Capture
372
388
  available_on: Available On
389
+ average_order_value: Average Order Value
373
390
  avs_response: AVS Response
374
391
  back: Back
375
392
  back_end: Backend
@@ -430,6 +447,7 @@ en:
430
447
  choose_a_taxon_to_sort_products_for: "Choose a taxon to sort products for"
431
448
  choose_currency: Choose Currency
432
449
  choose_dashboard_locale: Choose Dashboard Locale
450
+ choose_location: Choose location
433
451
  city: City
434
452
  clone: Clone
435
453
  close: Close
@@ -571,6 +589,7 @@ en:
571
589
  count_on_hand_setter: Cannot set count_on_hand manually, as it is set automatically by the recalculate_count_on_hand callback. Please use `update_column(:count_on_hand, value)` instead.
572
590
  expiration: Expiration
573
591
  extension: Extension
592
+ existing_shipments: Existing shipments
574
593
  failed_payment_attempts: Failed Payment Attempts
575
594
  filename: Filename
576
595
  fill_in_customer_info: Please fill in customer info
@@ -624,6 +643,7 @@ en:
624
643
  intercept_email_address: Intercept Email Address
625
644
  intercept_email_instructions: Override email recipient and replace with this address.
626
645
  internal_name: Internal Name
646
+ invalid_credit_card: Invalid credit card.
627
647
  invalid_payment_provider: Invalid payment provider.
628
648
  invalid_promotion_action: Invalid promotion action.
629
649
  invalid_promotion_rule: Invalid promotion rule.
@@ -646,6 +666,7 @@ en:
646
666
  last_name: Last Name
647
667
  last_name_begins_with: Last Name Begins With
648
668
  learn_more: Learn More
669
+ lifetime_stats: Lifetime Stats
649
670
  line_item_adjustments: "Line item adjustments"
650
671
  list: List
651
672
  listing_countries: Listing Countries
@@ -686,6 +707,7 @@ en:
686
707
  all: All
687
708
  none: None
688
709
  max_items: Max Items
710
+ member_since: Member Since
689
711
  meta_description: Meta Description
690
712
  meta_keywords: Meta Keywords
691
713
  metadata: Metadata
@@ -715,6 +737,7 @@ en:
715
737
  new_return_authorization: New Return Authorization
716
738
  new_shipping_category: New Shipping Category
717
739
  new_shipping_method: New Shipping Method
740
+ new_shipment_at_location: New shipment at location
718
741
  new_state: New State
719
742
  new_stock_location: New Stock Location
720
743
  new_stock_movement: New Stock Movement
@@ -755,6 +778,7 @@ en:
755
778
  product_not_deleted: Product could not be deleted
756
779
  variant_deleted: Variant has been deleted
757
780
  variant_not_deleted: Variant could not be deleted
781
+ num_orders: "# Orders"
758
782
  on_hand: On Hand
759
783
  open: Open
760
784
  open_all_adjustments: Open All Adjustments
@@ -1055,6 +1079,7 @@ en:
1055
1079
  stock_location: Stock Location
1056
1080
  stock_location_info: Stock location info
1057
1081
  stock_locations: Stock Locations
1082
+ stock_locations_need_a_default_country: You must create a default country before creating a stock location.
1058
1083
  stock_management: Stock Management
1059
1084
  stock_management_requires_a_stock_location: Please create a stock location in order to manage stock.
1060
1085
  stock_movements: Stock Movements
@@ -1104,6 +1129,7 @@ en:
1104
1129
  to_add_variants_you_must_first_define: To add variants, you must first define
1105
1130
  total: Total
1106
1131
  total_price: Total price
1132
+ total_sales: Total Sales
1107
1133
  track_inventory: Track Inventory
1108
1134
  tracking: Tracking
1109
1135
  tracking_number: Tracking Number
@@ -225,6 +225,7 @@ Spree::Country.create!([
225
225
  { name: "Macedonia", iso3: "MKD", iso: "MK", iso_name: "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF", numcode: "807" },
226
226
  { name: "New Zealand", iso3: "NZL", iso: "NZ", iso_name: "NEW ZEALAND", numcode: "554" },
227
227
  { name: "Saint Kitts and Nevis", iso3: "KNA", iso: "KN", iso_name: "SAINT KITTS AND NEVIS", numcode: "659", states_required: true },
228
- { name: "Serbia", iso3: "SRB", iso: "RS", "iso_name" => "SERBIA", numcode: "999" }
228
+ { name: "Serbia", iso3: "SRB", iso: "RS", "iso_name" => "SERBIA", numcode: "999" },
229
+ { name: "Montenegro", iso3: "MNE", iso: "ME", iso_name: "MONTENEGRO", numcode: "499" }
229
230
  ])
230
231
  Spree::Config[:default_country_id] = Spree::Country.find_by(name: "United States").id
@@ -5,11 +5,11 @@ class CreateDefaultStock < ActiveRecord::Migration
5
5
  location = Spree::StockLocation.new(name: 'default')
6
6
  location.save(validate: false)
7
7
 
8
- Spree::Variant.all.each do |variant|
8
+ Spree::Variant.find_each do |variant|
9
9
  stock_item = Spree::StockItem.unscoped.build(stock_location: location, variant: variant)
10
10
  stock_item.send(:count_on_hand=, variant.count_on_hand)
11
11
  # Avoid running default_scope defined by acts_as_paranoid, related to #3805,
12
- # validations would run a query with a delete_at column tha might not be present yet
12
+ # validations would run a query with a delete_at column that might not be present yet
13
13
  stock_item.save! validate: false
14
14
  end
15
15
 
@@ -19,7 +19,7 @@ class CreateDefaultStock < ActiveRecord::Migration
19
19
  def down
20
20
  add_column :spree_variants, :count_on_hand, :integer
21
21
 
22
- Spree::StockItem.all.each do |stock_item|
22
+ Spree::StockItem.find_each do |stock_item|
23
23
  stock_item.variant.update_column :count_on_hand, stock_item.count_on_hand
24
24
  end
25
25
 
@@ -1,10 +1,10 @@
1
1
  class UpdateAdjustmentStates < ActiveRecord::Migration
2
2
  def up
3
- Spree::Order.complete.each do |order|
3
+ Spree::Order.complete.find_each do |order|
4
4
  order.adjustments.update_all(:state => 'closed')
5
5
  end
6
6
 
7
- Spree::Shipment.shipped.each do |shipment|
7
+ Spree::Shipment.shipped.includes(:adjustment).find_each do |shipment|
8
8
  shipment.adjustment.update_column(:state, 'finalized') if shipment.adjustment
9
9
  end
10
10
 
@@ -1,6 +1,6 @@
1
1
  class AddShippingRatesToShipments < ActiveRecord::Migration
2
2
  def up
3
- Spree::Shipment.all.each do |shipment|
3
+ Spree::Shipment.find_each do |shipment|
4
4
  shipment.shipping_rates.create(:shipping_method_id => shipment.shipping_method_id,
5
5
  :cost => shipment.cost,
6
6
  :selected => true)
@@ -6,7 +6,7 @@ class AddNumberToStockTransfer < ActiveRecord::Migration
6
6
  rename_column :spree_stock_transfers, :reference_number, :reference
7
7
  add_column :spree_stock_transfers, :number, :string
8
8
 
9
- Spree::StockTransfer.all.each do |transfer|
9
+ Spree::StockTransfer.find_each do |transfer|
10
10
  transfer.send(:generate_stock_transfer_number)
11
11
  transfer.save!
12
12
  end
@@ -1,12 +1,10 @@
1
1
  class MigrateTaxCategoriesToLineItems < ActiveRecord::Migration
2
2
  def change
3
- Spree::LineItem.includes(:variant => { :product => :tax_category }).find_in_batches do |line_items|
4
- line_items.each do |line_item|
5
- next if line_item.variant.nil?
6
- next if line_item.variant.product.nil?
7
- next if line_item.product.nil?
8
- line_item.update_column(:tax_category_id, line_item.product.tax_category_id)
9
- end
3
+ Spree::LineItem.find_each do |line_item|
4
+ next if line_item.variant.nil?
5
+ next if line_item.variant.product.nil?
6
+ next if line_item.product.nil?
7
+ line_item.update_column(:tax_category_id, line_item.product.tax_category_id)
10
8
  end
11
9
  end
12
10
  end
@@ -0,0 +1,13 @@
1
+ class AddUserIdToSpreeCreditCards < ActiveRecord::Migration
2
+ def change
3
+ unless Spree::CreditCard.column_names.include? "user_id"
4
+ add_column :spree_credit_cards, :user_id, :integer
5
+ add_index :spree_credit_cards, :user_id
6
+ end
7
+
8
+ unless Spree::CreditCard.column_names.include? "payment_method_id"
9
+ add_column :spree_credit_cards, :payment_method_id, :integer
10
+ add_index :spree_credit_cards, :payment_method_id
11
+ end
12
+ end
13
+ end
@@ -16,21 +16,21 @@ production:
16
16
  <% when 'mysql' %>
17
17
  development:
18
18
  adapter: mysql2
19
- database: <%= database_prefix %>spree_development
19
+ database: <%= database_prefix %><%= options[:lib_name] %>_spree_development
20
20
  encoding: utf8
21
21
  test:
22
22
  adapter: mysql2
23
- database: <%= database_prefix %>spree_test
23
+ database: <%= database_prefix %><%= options[:lib_name] %>_spree_test
24
24
  encoding: utf8
25
25
  production:
26
26
  adapter: mysql2
27
- database: <%= database_prefix %>spree_production
27
+ database: <%= database_prefix %><%= options[:lib_name] %>_spree_production
28
28
  encoding: utf8
29
29
  <% when 'postgres' %>
30
30
  <% db_host = ENV['DB_HOST'] -%>
31
31
  development:
32
32
  adapter: postgresql
33
- database: <%= database_prefix %>spree_development
33
+ database: <%= database_prefix %><%= options[:lib_name] %>_spree_development
34
34
  username: postgres
35
35
  min_messages: warning
36
36
  <% unless db_host.blank? %>
@@ -38,7 +38,7 @@ development:
38
38
  <% end %>
39
39
  test:
40
40
  adapter: postgresql
41
- database: <%= database_prefix %>spree_test
41
+ database: <%= database_prefix %><%= options[:lib_name] %>_spree_test
42
42
  username: postgres
43
43
  min_messages: warning
44
44
  <% unless db_host.blank? %>
@@ -46,7 +46,7 @@ test:
46
46
  <% end %>
47
47
  production:
48
48
  adapter: postgresql
49
- database: <%= database_prefix %>spree_production
49
+ database: <%= database_prefix %><%= options[:lib_name] %>_spree_production
50
50
  username: postgres
51
51
  min_messages: warning
52
52
  <% unless db_host.blank? %>
@@ -53,7 +53,16 @@ module Spree
53
53
  # proxy method to *possible* spree_current_user method
54
54
  # Authentication extensions (such as spree_auth_devise) are meant to provide spree_current_user
55
55
  def try_spree_current_user
56
- respond_to?(:spree_current_user) ? spree_current_user : nil
56
+ # This one will be defined by apps looking to hook into Spree
57
+ # As per authentication_helpers.rb
58
+ if respond_to?(:spree_current_user)
59
+ spree_current_user
60
+ # This one will be defined by Devise
61
+ elsif respond_to?(:current_spree_user)
62
+ current_spree_user
63
+ else
64
+ nil
65
+ end
57
66
  end
58
67
 
59
68
  def redirect_back_or_default(default)
@@ -73,7 +73,7 @@ module Spree
73
73
  end
74
74
 
75
75
  def ip_address
76
- request.env['HTTP_X_REAL_IP'] || request.env['REMOTE_ADDR']
76
+ request.remote_ip
77
77
  end
78
78
  end
79
79
  end
@@ -1,3 +1,5 @@
1
+ require 'spree/responder'
2
+
1
3
  module ActionController
2
4
  class Base
3
5
  def respond_with(*resources, &block)
@@ -17,7 +19,8 @@ module ActionController
17
19
  # The action name is needed for processing
18
20
  options.merge!(:action_name => action_name.to_sym)
19
21
  # If responder is not specified then pass in Spree::Responder
20
- (options.delete(:responder) || Spree::Responder).call(self, resources, options)
22
+ responder = options.delete(:responder) || self.responder
23
+ responder.call(self, resources, options)
21
24
  end
22
25
  end
23
26
  end
@@ -33,6 +36,8 @@ module Spree
33
36
  included do
34
37
  cattr_accessor :spree_responders
35
38
  self.spree_responders = {}
39
+
40
+ self.responder = Spree::Responder
36
41
  end
37
42
 
38
43
  module ClassMethods