spree_core 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/products_helper.rb +3 -3
  3. data/app/models/concerns/spree/user_reporting.rb +2 -2
  4. data/app/models/spree/address.rb +7 -7
  5. data/app/models/spree/credit_card.rb +11 -5
  6. data/app/models/spree/gateway.rb +4 -1
  7. data/app/models/spree/item_adjustments.rb +17 -7
  8. data/app/models/spree/line_item.rb +2 -2
  9. data/app/models/spree/order.rb +35 -19
  10. data/app/models/spree/order/checkout.rb +3 -1
  11. data/app/models/spree/order_updater.rb +8 -2
  12. data/app/models/spree/payment.rb +2 -2
  13. data/app/models/spree/payment/processing.rb +9 -0
  14. data/app/models/spree/payment_method.rb +6 -0
  15. data/app/models/spree/price.rb +2 -2
  16. data/app/models/spree/product.rb +7 -2
  17. data/app/models/spree/promotion/actions/create_item_adjustments.rb +1 -0
  18. data/app/models/spree/promotion/rules/product.rb +4 -2
  19. data/app/models/spree/promotion/rules/user.rb +2 -2
  20. data/app/models/spree/promotion_handler/coupon.rb +6 -1
  21. data/app/models/spree/shipment.rb +0 -1
  22. data/app/models/spree/shipping_rate.rb +11 -9
  23. data/app/models/spree/stock/availability_validator.rb +1 -1
  24. data/app/models/spree/stock/quantifier.rb +1 -9
  25. data/app/models/spree/stock_item.rb +4 -0
  26. data/app/models/spree/tax_rate.rb +9 -8
  27. data/app/models/spree/taxon.rb +3 -0
  28. data/app/models/spree/variant.rb +1 -5
  29. data/config/locales/en.yml +1 -0
  30. data/db/migrate/20130830001159_migrate_old_shipping_calculators.rb +1 -1
  31. data/db/migrate/20140415041315_add_user_id_created_by_id_index_to_order.rb +5 -0
  32. data/lib/generators/spree/dummy/dummy_generator.rb +7 -2
  33. data/lib/spree/core.rb +2 -0
  34. data/lib/spree/core/engine.rb +1 -1
  35. data/lib/spree/core/importer/order.rb +13 -2
  36. data/lib/spree/core/version.rb +1 -1
  37. data/lib/spree/migrations.rb +10 -1
  38. data/lib/spree/money.rb +1 -1
  39. data/lib/spree/testing_support/capybara_ext.rb +1 -1
  40. data/lib/spree/testing_support/factories/address_factory.rb +1 -1
  41. metadata +34 -11
  42. data/vendor/assets/fonts/FontAwesome.otf +0 -0
  43. data/vendor/assets/fonts/fontawesome-webfont.eot +0 -0
  44. data/vendor/assets/fonts/fontawesome-webfont.svg +0 -399
  45. data/vendor/assets/fonts/fontawesome-webfont.ttf +0 -0
  46. data/vendor/assets/fonts/fontawesome-webfont.woff +0 -0
  47. data/vendor/assets/stylesheets/font-awesome.scss +0 -1475
@@ -28,6 +28,7 @@ module Spree
28
28
  def create_adjustment(adjustable, order)
29
29
  amount = self.compute_amount(adjustable)
30
30
  return if amount == 0
31
+ return if promotion.product_ids.present? and !promotion.product_ids.include?(adjustable.product.id)
31
32
  self.adjustments.create!(
32
33
  amount: amount,
33
34
  adjustable: adjustable,
@@ -7,7 +7,7 @@ module Spree
7
7
  class Product < PromotionRule
8
8
  has_and_belongs_to_many :products, class_name: '::Spree::Product', join_table: 'spree_products_promotion_rules', foreign_key: 'promotion_rule_id'
9
9
 
10
- MATCH_POLICIES = %w(any all)
10
+ MATCH_POLICIES = %w(any all none)
11
11
  preference :match_policy, :string, default: MATCH_POLICIES.first
12
12
 
13
13
  # scope/association that is used to test eligibility
@@ -23,8 +23,10 @@ module Spree
23
23
  return true if eligible_products.empty?
24
24
  if preferred_match_policy == 'all'
25
25
  eligible_products.all? {|p| order.products.include?(p) }
26
- else
26
+ elsif preferred_match_policy == 'any'
27
27
  order.products.any? {|p| eligible_products.include?(p) }
28
+ else
29
+ order.products.none? {|p| eligible_products.include?(p) }
28
30
  end
29
31
  end
30
32
 
@@ -2,8 +2,8 @@ module Spree
2
2
  class Promotion
3
3
  module Rules
4
4
  class User < PromotionRule
5
- belongs_to :user, class_name: Spree.user_class
6
- has_and_belongs_to_many :users, class_name: Spree.user_class, join_table: 'spree_promotion_rules_users', foreign_key: 'promotion_rule_id'
5
+ belongs_to :user, class_name: "::#{Spree.user_class.to_s}"
6
+ has_and_belongs_to_many :users, class_name: "::#{Spree.user_class.to_s}", join_table: 'spree_promotion_rules_users', foreign_key: 'promotion_rule_id'
7
7
 
8
8
  def applicable?(promotable)
9
9
  promotable.is_a?(Spree::Order)
@@ -57,7 +57,12 @@ module Spree
57
57
  end
58
58
 
59
59
  def determine_promotion_application_result(result)
60
- detector = lambda { |p| p.source.promotion.code.downcase == order.coupon_code.downcase }
60
+ detector = lambda { |p|
61
+ if p.source.promotion.code
62
+ p.source.promotion.code.downcase == order.coupon_code.downcase
63
+ end
64
+ }
65
+
61
66
  discount = order.line_item_adjustments.promotion.detect(&detector)
62
67
  discount ||= order.shipment_adjustments.promotion.detect(&detector)
63
68
  discount ||= order.adjustments.promotion.detect(&detector)
@@ -336,7 +336,6 @@ module Spree
336
336
  self.cost = 0 unless self.cost
337
337
  end
338
338
 
339
-
340
339
  def update_adjustments
341
340
  if cost_changed? && state != 'shipped'
342
341
  recalculate_adjustments
@@ -19,17 +19,19 @@ module Spree
19
19
  price = display_base_price.to_s
20
20
  if tax_rate
21
21
  tax_amount = calculate_tax_amount
22
- if tax_rate.included_in_price?
23
- if tax_amount > 0
24
- amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
25
- price += " (incl. #{amount})"
22
+ if tax_amount != 0
23
+ if tax_rate.included_in_price?
24
+ if tax_amount > 0
25
+ amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
26
+ price += " (incl. #{amount})"
27
+ else
28
+ amount = "#{display_tax_amount(tax_amount*-1)} #{tax_rate.name}"
29
+ price += " (excl. #{amount})"
30
+ end
26
31
  else
27
- amount = "#{display_tax_amount(tax_amount*-1)} #{tax_rate.name}"
28
- price += " (excl. #{amount})"
32
+ amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
33
+ price += " (+ #{amount})"
29
34
  end
30
- else
31
- amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
32
- price += " (+ #{amount})"
33
35
  end
34
36
  end
35
37
  price
@@ -10,7 +10,7 @@ module Spree
10
10
  quantity = line_item.quantity
11
11
  end
12
12
 
13
- quantifier = Stock::Quantifier.new(line_item.variant_id)
13
+ quantifier = Stock::Quantifier.new(line_item.variant)
14
14
 
15
15
  unless quantifier.can_supply? quantity
16
16
  variant = line_item.variant
@@ -4,7 +4,7 @@ module Spree
4
4
  attr_reader :stock_items
5
5
 
6
6
  def initialize(variant)
7
- @variant = resolve_variant_id(variant)
7
+ @variant = variant
8
8
  @stock_items = Spree::StockItem.joins(:stock_location).where(:variant_id => @variant, Spree::StockLocation.table_name =>{ :active => true})
9
9
  end
10
10
 
@@ -24,14 +24,6 @@ module Spree
24
24
  total_on_hand >= required || backorderable?
25
25
  end
26
26
 
27
- private
28
-
29
- # return variant when passed either variant object or variant id
30
- def resolve_variant_id(variant)
31
- variant = Spree::Variant.find_by_id(variant) unless variant.respond_to?(:should_track_inventory?)
32
- variant
33
- end
34
-
35
27
  end
36
28
  end
37
29
  end
@@ -47,6 +47,10 @@ module Spree
47
47
  self.in_stock? || self.backorderable?
48
48
  end
49
49
 
50
+ def variant
51
+ Spree::Variant.unscoped { super }
52
+ end
53
+
50
54
  private
51
55
  def count_on_hand=(value)
52
56
  write_attribute(:count_on_hand, value)
@@ -25,8 +25,9 @@ module Spree
25
25
 
26
26
  # Gets the array of TaxRates appropriate for the specified order
27
27
  def self.match(order)
28
- return [] unless order.tax_zone
29
- rates = all.select do |rate|
28
+ order_zone = order.tax_zone
29
+ return [] unless order_zone
30
+ rates = includes(zone: { zone_members: :zoneable }).load.select do |rate|
30
31
  # Why "potentially"?
31
32
  # Go see the documentation for that method.
32
33
  rate.potentially_applicable?(order)
@@ -51,7 +52,7 @@ module Spree
51
52
  end
52
53
  end
53
54
 
54
- # Pre-tax amounts must be stored so that we can calculate
55
+ # Pre-tax amounts must be stored so that we can calculate
55
56
  # correct rate amounts in the future. For example:
56
57
  # https://github.com/spree/spree/issues/4318#issuecomment-34723428
57
58
  def self.store_pre_tax_amount(item, rates)
@@ -95,7 +96,7 @@ module Spree
95
96
  rate || 0
96
97
  end
97
98
 
98
-
99
+
99
100
  # Tax rates can *potentially* be applicable to an order.
100
101
  # We do not know if they are/aren't until we attempt to apply these rates to
101
102
  # the items contained within the Order itself.
@@ -103,14 +104,14 @@ module Spree
103
104
  # but then has a tax category that doesn't match against any of the line items
104
105
  # inside of the order, then that tax rate will not be applicable to anything.
105
106
  # For instance:
106
- #
107
+ #
107
108
  # Zones:
108
109
  # - Spain (default tax zone)
109
110
  # - France
110
111
  #
111
112
  # Tax rates: (note: amounts below do not actually reflect real VAT rates)
112
113
  # 21% inclusive - "Clothing" - Spain
113
- # 18% inclusive - "Clothing" - France
114
+ # 18% inclusive - "Clothing" - France
114
115
  # 10% inclusive - "Food" - Spain
115
116
  # 8% inclusive - "Food" - France
116
117
  # 5% inclusive - "Hotels" - Spain
@@ -119,14 +120,14 @@ module Spree
119
120
  # Order has:
120
121
  # Line Item #1 - Tax Category: Clothing
121
122
  # Line Item #2 - Tax Category: Food
122
- #
123
+ #
123
124
  # Tax rates that should be selected:
124
125
  #
125
126
  # 21% inclusive - "Clothing" - Spain
126
127
  # 10% inclusive - "Food" - Spain
127
128
  #
128
129
  # If the order's address changes to one in France, then the tax will be recalculated:
129
- #
130
+ #
130
131
  # 18% inclusive - "Clothing" - France
131
132
  # 8% inclusive - "Food" - France
132
133
  #
@@ -19,6 +19,9 @@ module Spree
19
19
  path: ':rails_root/public/spree/taxons/:id/:style/:basename.:extension',
20
20
  default_url: '/assets/default_taxon.png'
21
21
 
22
+ validates_attachment :icon,
23
+ content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
24
+
22
25
  include Spree::Core::ProductFilters # for detailed defs of filters
23
26
 
24
27
  # indicate which filters should be used for a taxon
@@ -79,15 +79,11 @@ module Spree
79
79
  values.to_sentence({ words_connector: ", ", two_words_connector: ", " })
80
80
  end
81
81
 
82
- def gross_profit
83
- cost_price.nil? ? 0 : (price - cost_price)
84
- end
85
-
86
82
  # use deleted? rather than checking the attribute directly. this
87
83
  # allows extensions to override deleted? if they want to provide
88
84
  # their own definition.
89
85
  def deleted?
90
- deleted_at
86
+ !!deleted_at
91
87
  end
92
88
 
93
89
  # Product may be created with deleted_at already set,
@@ -896,6 +896,7 @@ en:
896
896
  label: Order must contain %{select} of these products
897
897
  match_all: all
898
898
  match_any: at least one
899
+ match_none: none
899
900
  product_source:
900
901
  group: From product group
901
902
  manual: Manually choose
@@ -3,7 +3,7 @@ class MigrateOldShippingCalculators < ActiveRecord::Migration
3
3
  Spree::ShippingMethod.all.each do |shipping_method|
4
4
  old_calculator = shipping_method.calculator
5
5
  next if old_calculator.class < Spree::ShippingCalculator # We don't want to mess with new shipping calculators
6
- new_calculator = eval("Spree::Calculator::Shipping::#{old_calculator.class.name.demodulize}").new
6
+ new_calculator = eval(old_calculator.class.name.sub("::Calculator::", "::Calculator::Shipping::")).new
7
7
  new_calculator.preferences.keys.each do |pref|
8
8
  # Preferences can't be read/set by name, you have to prefix preferred_
9
9
  pref_method = "preferred_#{pref}"
@@ -0,0 +1,5 @@
1
+ class AddUserIdCreatedByIdIndexToOrder < ActiveRecord::Migration
2
+ def change
3
+ add_index :spree_orders, [:user_id, :created_by_id]
4
+ end
5
+ end
@@ -122,7 +122,13 @@ end
122
122
  end
123
123
 
124
124
  def gemfile_path
125
- '../../../../../Gemfile'
125
+ core_gems = ["spree/core", "spree/api", "spree/backend", "spree/frontend"]
126
+
127
+ if core_gems.include?(lib_name)
128
+ '../../../../../Gemfile'
129
+ else
130
+ '../../../../Gemfile'
131
+ end
126
132
  end
127
133
  end
128
134
  end
@@ -131,4 +137,3 @@ module Spree::DummyGeneratorHelper
131
137
  mattr_accessor :inject_extension_requirements
132
138
  self.inject_extension_requirements = false
133
139
  end
134
-
data/lib/spree/core.rb CHANGED
@@ -5,11 +5,13 @@ require 'awesome_nested_set'
5
5
  require 'cancan'
6
6
  require 'kaminari'
7
7
  require 'mail'
8
+ require 'monetize'
8
9
  require 'paperclip'
9
10
  require 'paranoia'
10
11
  require 'ransack'
11
12
  require 'state_machine'
12
13
  require 'friendly_id'
14
+ require 'font-awesome-rails'
13
15
 
14
16
  module Spree
15
17
 
@@ -58,7 +58,7 @@ module Spree
58
58
  app.config.spree.calculators.promotion_actions_create_adjustments = [
59
59
  Spree::Calculator::FlatPercentItemTotal,
60
60
  Spree::Calculator::FlatRate,
61
- Spree::Calculator::FlexiRate,
61
+ Spree::Calculator::FlexiRate
62
62
  ]
63
63
 
64
64
  app.config.spree.calculators.add_class('promotion_actions_create_item_adjustments')
@@ -18,12 +18,21 @@ module Spree
18
18
  create_adjustments_from_params(params.delete(:adjustments_attributes), order)
19
19
  create_payments_from_params(params.delete(:payments_attributes), order)
20
20
 
21
+
21
22
  if(completed_at = params.delete(:completed_at))
22
23
  order.completed_at = completed_at
23
24
  order.state = 'complete'
24
25
  end
25
26
 
27
+ user_id = params.delete(:user_id)
28
+ if user.has_spree_role? "admin"
29
+ order.user_id = user_id
30
+ end
31
+
26
32
  order.update_attributes!(params)
33
+ # Really ensure that the order totals are correct
34
+ order.update_totals
35
+ order.persist_totals
27
36
  order.reload
28
37
  rescue Exception => e
29
38
  order.destroy if order && order.persisted?
@@ -51,8 +60,10 @@ module Spree
51
60
  shipment.save!
52
61
 
53
62
  shipping_method = Spree::ShippingMethod.find_by_name!(s[:shipping_method])
54
- shipment.shipping_rates.create!(:shipping_method => shipping_method,
55
- :cost => s[:cost])
63
+ rate = shipment.shipping_rates.create!(:shipping_method => shipping_method,
64
+ :cost => s[:cost])
65
+ shipment.selected_shipping_rate_id = rate.id
66
+
56
67
  rescue Exception => e
57
68
  raise "Order import shipments: #{e.message} #{s}"
58
69
  end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "2.2.1"
3
+ "2.2.2"
4
4
  end
5
5
  end
@@ -24,7 +24,7 @@ module Spree
24
24
  if File.exists?("config/spree.yml") && File.directory?("db/migrate")
25
25
  engine_in_app = app_migrations.map do |file_name|
26
26
  name, engine = file_name.split(".", 2)
27
- next unless engine == "#{engine_name}.rb"
27
+ next unless match_engine?(engine)
28
28
  name
29
29
  end.compact! || []
30
30
 
@@ -51,5 +51,14 @@ module Spree
51
51
  name.empty? ? next : name
52
52
  end.compact! || []
53
53
  end
54
+
55
+ def match_engine?(engine)
56
+ if engine_name == "spree"
57
+ # Avoid stores upgrading from 1.3 getting wrong warnings
58
+ ["spree.rb", "spree_promo.rb"].include? engine
59
+ else
60
+ engine == "#{engine_name}.rb"
61
+ end
62
+ end
54
63
  end
55
64
  end
data/lib/spree/money.rb CHANGED
@@ -30,7 +30,7 @@ module Spree
30
30
 
31
31
  # Check the first character for a currency symbol, alternatively get it
32
32
  # from the stated currency string
33
- c = if ::Money.assume_from_symbol && i =~ /^(\$|€|£)/
33
+ c = if ::Monetize.assume_from_symbol && i =~ /^(\$|€|£)/
34
34
  case i
35
35
  when /^\$/ then "USD"
36
36
  when /^€/ then "EUR"
@@ -4,7 +4,7 @@ module CapybaraExt
4
4
  end
5
5
 
6
6
  def click_icon(type)
7
- find(".icon-#{type}").click
7
+ find(".fa-#{type}").click
8
8
  end
9
9
 
10
10
  def eventually_fill_in(field, options={})
@@ -6,7 +6,7 @@ FactoryGirl.define do
6
6
  address1 '10 Lovely Street'
7
7
  address2 'Northwest'
8
8
  city 'Herndon'
9
- zipcode '20170'
9
+ zipcode '35005'
10
10
  phone '123-456-7890'
11
11
  alternative_phone '123-456-7899'
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: 0.15.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: monetize
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: paperclip
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +226,14 @@ dependencies:
212
226
  requirements:
213
227
  - - "~>"
214
228
  - !ruby/object:Gem::Version
215
- version: 4.0.3
229
+ version: 4.0.5
216
230
  type: :runtime
217
231
  prerelease: false
218
232
  version_requirements: !ruby/object:Gem::Requirement
219
233
  requirements:
220
234
  - - "~>"
221
235
  - !ruby/object:Gem::Version
222
- version: 4.0.3
236
+ version: 4.0.5
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: ransack
225
239
  requirement: !ruby/object:Gem::Requirement
@@ -276,6 +290,20 @@ dependencies:
276
290
  - - '='
277
291
  - !ruby/object:Gem::Version
278
292
  version: 0.9.2
293
+ - !ruby/object:Gem::Dependency
294
+ name: font-awesome-rails
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - "~>"
298
+ - !ruby/object:Gem::Version
299
+ version: '4.0'
300
+ type: :runtime
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - "~>"
305
+ - !ruby/object:Gem::Version
306
+ version: '4.0'
279
307
  description: The bare bones necessary for Spree.
280
308
  email: sean@spreecommerce.com
281
309
  executables: []
@@ -561,6 +589,7 @@ files:
561
589
  - db/migrate/20140213184916_add_more_indexes.rb
562
590
  - db/migrate/20140219060952_add_considered_risky_to_orders.rb
563
591
  - db/migrate/20140307235515_add_user_id_to_spree_credit_cards.rb
592
+ - db/migrate/20140415041315_add_user_id_created_by_id_index_to_order.rb
564
593
  - db/seeds.rb
565
594
  - lib/generators/spree/custom_user/custom_user_generator.rb
566
595
  - lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt
@@ -671,11 +700,6 @@ files:
671
700
  - lib/spree/testing_support/url_helpers.rb
672
701
  - lib/spree_core.rb
673
702
  - lib/tasks/core.rake
674
- - vendor/assets/fonts/FontAwesome.otf
675
- - vendor/assets/fonts/fontawesome-webfont.eot
676
- - vendor/assets/fonts/fontawesome-webfont.svg
677
- - vendor/assets/fonts/fontawesome-webfont.ttf
678
- - vendor/assets/fonts/fontawesome-webfont.woff
679
703
  - vendor/assets/javascripts/jquery-migrate-1.0.0.js
680
704
  - vendor/assets/javascripts/jquery.payment.js
681
705
  - vendor/assets/javascripts/jquery.validate/localization/messages_et.js
@@ -692,7 +716,6 @@ files:
692
716
  - vendor/assets/javascripts/jquery.validate/localization/messages_zh.js
693
717
  - vendor/assets/javascripts/jquery.validate/localization/messages_zh_TW.js
694
718
  - vendor/assets/javascripts/jsuri.js
695
- - vendor/assets/stylesheets/font-awesome.scss
696
719
  - vendor/assets/stylesheets/normalize.css
697
720
  - vendor/assets/stylesheets/skeleton.css
698
721
  homepage: http://spreecommerce.com
@@ -715,7 +738,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
715
738
  version: '0'
716
739
  requirements: []
717
740
  rubyforge_project:
718
- rubygems_version: 2.2.2
741
+ rubygems_version: 2.2.0
719
742
  signing_key:
720
743
  specification_version: 4
721
744
  summary: The bare bones necessary for Spree.