spree_core 3.7.0.rc2 → 3.7.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7124c86a59c0fdd43a117c2765d9d7253de04054cef1c787934ce48abf06c9c
4
- data.tar.gz: 3c00c9709cd38461a3aeeff347a2377482766c54501d3a91bf8cc429d043a52c
3
+ metadata.gz: 4d67e4411295bf73afd62309af2b92174e0cbf53d5fde6cb708556176ca7e061
4
+ data.tar.gz: 779f22575add68337aa6e33ecff55452776c125a3f587d4cf481743d294ab9a5
5
5
  SHA512:
6
- metadata.gz: 33c2354b25887911fef568f618c9d0316cfbda57bb0839ab2b3172e7a8f72ba798b8fce7bc7e2354ca2c913444647b2b44c885cd60a605196279ada234fd3242
7
- data.tar.gz: d62478a37f518d87cf21a7caec39d9a12314c1532bfa7cba161a5c1945077588ddec70ff741ba77445bd9c7290021853809accc423abf0f4c606ce9b1904607c
6
+ metadata.gz: 47b6cf3807d3cf870548cb82aae5ceaf7d9befe5e41a784ff63cb319126c5aa4c58a250a12b2de2666f65b3d7b850e9a996173cb1160d36caa483372c35d2bbd
7
+ data.tar.gz: 513adfbb880c88d13db7aaf1b60bb1d624195c030e6205279fea2f82b4cc2d6fd7303189d8c826927c27584052eda38321753b032b9c31d6e021bcd16cfb5dc9
@@ -5,7 +5,7 @@ module Spree
5
5
  order.line_items.detect do |line_item|
6
6
  next unless line_item.variant_id == variant.id
7
7
 
8
- CompareLineItems.new.call(order: order, line_item: line_item, options: options).value
8
+ Spree::Dependencies.cart_compare_line_items_service.constantize.call(order: order, line_item: line_item, options: options).value
9
9
  end
10
10
  end
11
11
  end
@@ -1,12 +1,12 @@
1
1
  module Spree
2
2
  module BaseHelper
3
3
  def available_countries
4
- checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone])
4
+ checkout_zone = Spree::Zone.find_by(name: Spree::Config[:checkout_zone])
5
5
 
6
6
  countries = if checkout_zone && checkout_zone.kind == 'country'
7
7
  checkout_zone.country_list
8
8
  else
9
- Country.all
9
+ Spree::Country.all
10
10
  end
11
11
 
12
12
  countries.collect do |country|
@@ -0,0 +1,73 @@
1
+ module Spree
2
+ class AppDependencies
3
+ include Spree::DependenciesHelper
4
+
5
+ INJECTION_POINTS = [
6
+ :ability_class,
7
+ :cart_create_service, :cart_add_item_service, :cart_remove_item_service,
8
+ :cart_remove_line_item_service, :cart_set_item_quantity_service, :cart_recalculate_service,
9
+ :cart_update_service, :checkout_next_service, :checkout_advance_service, :checkout_update_service,
10
+ :checkout_complete_service, :checkout_add_store_credit_service,
11
+ :checkout_remove_store_credit_service, :checkout_get_shipping_rates_service,
12
+ :coupon_handler, :country_finder, :current_order_finder, :credit_card_finder,
13
+ :completed_order_finder, :order_sorter, :cart_compare_line_items_service, :collection_paginator, :products_sorter,
14
+ :products_finder, :taxon_finder, :line_item_by_variant_finder
15
+ ].freeze
16
+
17
+ attr_accessor *INJECTION_POINTS
18
+
19
+ def initialize
20
+ set_default_abitily
21
+ set_default_services
22
+ set_default_finders
23
+ end
24
+
25
+ private
26
+
27
+ def set_default_abitily
28
+ @ability_class = 'Spree::Ability'
29
+ end
30
+
31
+ def set_default_services
32
+ # cart
33
+ @cart_compare_line_items_service = 'Spree::CompareLineItems'
34
+ @cart_create_service = 'Spree::Cart::Create'
35
+ @cart_add_item_service = 'Spree::Cart::AddItem'
36
+ @cart_update_service = 'Spree::Cart::Update'
37
+ @cart_recalculate_service = 'Spree::Cart::Recalculate'
38
+ @cart_remove_item_service = 'Spree::Cart::RemoveItem'
39
+ @cart_remove_line_item_service = 'Spree::Cart::RemoveLineItem'
40
+ @cart_set_item_quantity_service = 'Spree::Cart::SetQuantity'
41
+
42
+ # checkout
43
+ @checkout_next_service = 'Spree::Checkout::Next'
44
+ @checkout_advance_service = 'Spree::Checkout::Advance'
45
+ @checkout_update_service = 'Spree::Checkout::Update'
46
+ @checkout_complete_service = 'Spree::Checkout::Complete'
47
+ @checkout_add_store_credit_service = 'Spree::Checkout::AddStoreCredit'
48
+ @checkout_remove_store_credit_service = 'Spree::Checkout::RemoveStoreCredit'
49
+ @checkout_get_shipping_rates_service = 'Spree::Checkout::GetShippingRates'
50
+
51
+ # sorter
52
+ @order_sorter = 'Spree::Orders::Sort'
53
+ @products_sorter = 'Spree::Products::Sort'
54
+
55
+ # paginator
56
+ @collection_paginator = 'Spree::Shared::Paginate'
57
+
58
+ # coupons
59
+ # TODO: we should split this service into 2 seperate - Add and Remove
60
+ @coupon_handler = 'Spree::PromotionHandler::Coupon'
61
+ end
62
+
63
+ def set_default_finders
64
+ @country_finder = 'Spree::Countries::Find'
65
+ @current_order_finder = 'Spree::Orders::FindCurrent'
66
+ @completed_order_finder = 'Spree::Orders::FindComplete'
67
+ @credit_card_finder = 'Spree::CreditCards::Find'
68
+ @products_finder = 'Spree::Products::Find'
69
+ @taxon_finder = 'Spree::Taxons::Find'
70
+ @line_item_by_variant_finder = 'Spree::LineItems::FindByVariant'
71
+ end
72
+ end
73
+ end
@@ -335,7 +335,7 @@ module Spree
335
335
  EOS
336
336
  return true unless options
337
337
 
338
- CompareLineItems.new.call(order: self, line_item: line_item, options: options).value
338
+ Spree::Dependencies.cart_compare_line_items_service.constantize.new.call(order: self, line_item: line_item, options: options).value
339
339
  end
340
340
 
341
341
  # Creates new tax charges if there are any applicable rates. If prices already
@@ -8,20 +8,29 @@ module Spree
8
8
 
9
9
  def add(variant, quantity = 1, options = {})
10
10
  ActiveSupport::Deprecation.warn(<<-EOS, caller)
11
- OrderContents#add method is deprecated and will be removed in Spree 4.0. Please use Spree::Cart::AddItem service
11
+ OrderContents#add method is deprecated and will be removed in Spree 4.0.
12
+ Please use Spree::Dependencies.cart_add_item_service
12
13
  to add items to cart.
13
14
  EOS
14
15
 
15
- Spree::Cart::AddItem.call(order: order, variant: variant, quantity: quantity, options: options).value
16
+ Spree::Dependencies.cart_add_item_service.constantize.call(order: order,
17
+ variant: variant,
18
+ quantity: quantity,
19
+ options: options).value
16
20
  end
17
21
 
18
22
  def remove(variant, quantity = 1, options = {})
19
23
  ActiveSupport::Deprecation.warn(<<-EOS, caller)
20
- OrderContents#remove method is deprecated and will be removed in Spree 4.0. Please use Spree::Cart::RemoveItem
24
+ OrderContents#remove method is deprecated and will be removed in Spree 4.0.
25
+ Please use Spree::Dependencies.cart_remove_item_service
21
26
  service to remove item from cart.
22
27
  EOS
23
28
 
24
- Spree::Cart::RemoveItem.call(order: order, variant: variant, quantity: quantity, options: options).value
29
+ # change this dependencies to Spree::Cart::RemoveItem
30
+ Spree::Dependencies.cart_remove_item_service.constantize.call(order: order,
31
+ variant: variant,
32
+ quantity: quantity,
33
+ options: options).value
25
34
  end
26
35
 
27
36
  def remove_line_item(line_item, options = {})
@@ -34,11 +43,12 @@ module Spree
34
43
 
35
44
  def update_cart(params)
36
45
  ActiveSupport::Deprecation.warn(<<-EOS, caller)
37
- OrderContents#update_cart method is deprecated and will be removed in Spree 4.0. Please use Spree::Cart::Update
46
+ OrderContents#update_cart method is deprecated and will be removed in Spree 4.0.
47
+ Spree::Dependencies.cart_update_service
38
48
  service to update cart.
39
49
  EOS
40
50
 
41
- Spree::Cart::Update.call(order: order, params: params).value
51
+ Spree::Dependencies.cart_update_service.constantize.call(order: order, params: params).value
42
52
  end
43
53
  end
44
54
  end
@@ -29,7 +29,9 @@ module Spree
29
29
  def find_matching_line_item(other_order_line_item)
30
30
  order.line_items.detect do |my_li|
31
31
  my_li.variant == other_order_line_item.variant &&
32
- CompareLineItems.new.call(order: order, line_item: my_li, options: other_order_line_item.serializable_hash).value
32
+ Spree::Dependencies.cart_compare_line_items_service.constantize.new.call(order: order,
33
+ line_item: my_li,
34
+ options: other_order_line_item.serializable_hash).value
33
35
  end
34
36
  end
35
37
 
@@ -42,10 +42,12 @@ module Spree
42
42
  action_taken = false
43
43
  promotion_action_line_items.each do |item|
44
44
  current_quantity = order.quantity_of(item.variant)
45
- if current_quantity < item.quantity && item_available?(item)
46
- line_item = Spree::Cart::AddItem.call(order: order, variant: item.variant, quantity: item.quantity - current_quantity).value
47
- action_taken = true if line_item.try(:valid?)
48
- end
45
+ next unless current_quantity < item.quantity && item_available?(item)
46
+
47
+ line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: order,
48
+ variant: item.variant,
49
+ quantity: item.quantity - current_quantity).value
50
+ action_taken = true if line_item.try(:valid?)
49
51
  end
50
52
  action_taken
51
53
  end
@@ -63,7 +65,9 @@ module Spree
63
65
  line_item = order.find_line_item_by_variant(item.variant)
64
66
  next unless line_item.present?
65
67
 
66
- Spree::Cart::RemoveItem.call(order: order, variant: item.variant, quantity: (item.quantity || 1))
68
+ Spree::Dependencies.cart_remove_item_service.constantize.call(order: order,
69
+ variant: item.variant,
70
+ quantity: (item.quantity || 1))
67
71
  action_taken = true
68
72
  end
69
73
 
@@ -76,7 +76,7 @@ module Spree
76
76
  line_item = order.find_line_item_by_variant(item.variant)
77
77
  next if line_item.blank?
78
78
 
79
- order.contents.remove(item.variant, item.quantity)
79
+ Spree::Dependencies.cart_remove_item_service(order: order, item: item.variant, quantity: item.quantity)
80
80
  end
81
81
  end
82
82
 
@@ -6,7 +6,7 @@ module Spree
6
6
  def call(order:, variant:, quantity: nil, options: {})
7
7
  ApplicationRecord.transaction do
8
8
  run :add_to_line_item
9
- run Spree::Cart::Recalculate
9
+ run Spree::Dependencies.cart_recalculate_service.constantize
10
10
  end
11
11
  end
12
12
 
@@ -16,7 +16,7 @@ module Spree
16
16
  options ||= {}
17
17
  quantity ||= 1
18
18
 
19
- line_item = Spree::LineItems::FindByVariant.new.execute(order: order, variant: variant, options: options)
19
+ line_item = Spree::Dependencies.line_item_by_variant_finder.constantize.new.execute(order: order, variant: variant, options: options)
20
20
 
21
21
  line_item_created = line_item.nil?
22
22
  if line_item.nil?
@@ -10,7 +10,7 @@ module Spree
10
10
  user: user,
11
11
  store: store,
12
12
  currency: currency,
13
- token: GenerateToken.new.call(Spree::Order)
13
+ token: Spree::GenerateToken.new.call(Spree::Order)
14
14
  }
15
15
 
16
16
  order = Spree::Order.create!(default_params.merge(order_params))
@@ -9,7 +9,9 @@ module Spree
9
9
 
10
10
  ActiveRecord::Base.transaction do
11
11
  line_item = remove_from_line_item(order: order, variant: variant, quantity: quantity, options: options)
12
- Spree::Cart::Recalculate.new.call(line_item: line_item, order: order, options: options)
12
+ Spree::Dependencies.cart_recalculate_service.constantize.call(line_item: line_item,
13
+ order: order,
14
+ options: options)
13
15
  success(line_item)
14
16
  end
15
17
  end
@@ -17,7 +19,7 @@ module Spree
17
19
  private
18
20
 
19
21
  def remove_from_line_item(order:, variant:, quantity:, options:)
20
- line_item = Spree::LineItems::FindByVariant.new.execute(order: order, variant: variant, options: options)
22
+ line_item = Spree::Dependencies.line_item_by_variant_finder.constantize.new.execute(order: order, variant: variant, options: options)
21
23
 
22
24
  raise ActiveRecord::RecordNotFound if line_item.nil?
23
25
 
@@ -7,7 +7,9 @@ module Spree
7
7
  options ||= {}
8
8
  ActiveRecord::Base.transaction do
9
9
  line_item.destroy!
10
- Spree::Cart::Recalculate.new.call(order: order, line_item: line_item, options: options)
10
+ Spree::Dependencies.cart_recalculate_service.constantize.new.call(order: order,
11
+ line_item: line_item,
12
+ options: options)
11
13
  end
12
14
  success(line_item)
13
15
  end
@@ -6,7 +6,7 @@ module Spree
6
6
  def call(order:, line_item:, quantity: nil)
7
7
  ActiveRecord::Base.transaction do
8
8
  run :change_item_quantity
9
- run Spree::Cart::Recalculate
9
+ run Spree::Dependencies.cart_recalculate_service.constantize
10
10
  end
11
11
  end
12
12
 
@@ -4,7 +4,7 @@ module Spree
4
4
  prepend Spree::ServiceModule::Base
5
5
 
6
6
  def call(order:)
7
- Spree::Checkout::Next.call(order: order) until cannot_make_transition?(order)
7
+ Spree::Dependencies.checkout_next_service.constantize.call(order: order) until cannot_make_transition?(order)
8
8
  success(order)
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ module Spree
4
4
  prepend Spree::ServiceModule::Base
5
5
 
6
6
  def call(order:)
7
- Spree::Checkout::Next.call(order: order) until cannot_make_transition?(order)
7
+ Spree::Dependencies.checkout_next_service.constantize.call(order: order) until cannot_make_transition?(order)
8
8
 
9
9
  if order.reload.complete?
10
10
  success(order)
@@ -15,4 +15,16 @@ Spree.config do |config|
15
15
  # config.track_inventory_levels = false
16
16
  end
17
17
 
18
- Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : options[:user_class]).inspect %>
18
+ # Configure Spree Dependencies
19
+ #
20
+ # Note: If a dependency is set here it will NOT be stored within the cache & database upon initialization.
21
+ # Just removing an entry from this initializer will make the dependency value go away.
22
+ #
23
+ Spree.dependencies do |dependencies|
24
+ # Example:
25
+ # Uncomment to change the default Service handling adding Items to Cart
26
+ # dependencies.cart_add_item_service = 'MyNewAwesomeService'
27
+ end
28
+
29
+
30
+ Spree.user_class = <%= (options[:user_class].blank? ? 'Spree::LegacyUser' : options[:user_class]).inspect %>
@@ -16,7 +16,7 @@ module Spree
16
16
 
17
17
  # Needs to be overriden so that we use Spree's Ability rather than anyone else's.
18
18
  def current_ability
19
- @current_ability ||= Spree::Ability.new(try_spree_current_user)
19
+ @current_ability ||= Spree::Dependencies.ability_class.constantize.new(try_spree_current_user)
20
20
  end
21
21
 
22
22
  def redirect_back_or_default(default)
@@ -1,7 +1,14 @@
1
1
  module Spree
2
2
  module Core
3
3
  class Engine < ::Rails::Engine
4
- Environment = Struct.new(:calculators, :preferences, :payment_methods, :adjusters, :stock_splitters, :promotions, :line_item_comparison_hooks)
4
+ Environment = Struct.new(:calculators,
5
+ :preferences,
6
+ :dependencies,
7
+ :payment_methods,
8
+ :adjusters,
9
+ :stock_splitters,
10
+ :promotions,
11
+ :line_item_comparison_hooks)
5
12
  SpreeCalculators = Struct.new(:shipping_methods, :tax_rates, :promotion_actions_create_adjustments, :promotion_actions_create_item_adjustments)
6
13
  PromoEnvironment = Struct.new(:rules, :actions)
7
14
  isolate_namespace Spree
@@ -12,8 +19,9 @@ module Spree
12
19
  end
13
20
 
14
21
  initializer 'spree.environment', before: :load_config_initializers do |app|
15
- app.config.spree = Environment.new(SpreeCalculators.new, Spree::AppConfiguration.new)
22
+ app.config.spree = Environment.new(SpreeCalculators.new, Spree::AppConfiguration.new, Spree::AppDependencies.new)
16
23
  Spree::Config = app.config.spree.preferences
24
+ Spree::Dependencies = app.config.spree.dependencies
17
25
  end
18
26
 
19
27
  initializer 'spree.register.calculators' do |app|
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- '3.7.0.rc2'
3
+ '3.7.0.rc3'
4
4
  end
5
5
  end
data/lib/spree/core.rb CHANGED
@@ -59,6 +59,20 @@ module Spree
59
59
  yield(Spree::Config)
60
60
  end
61
61
 
62
+ # Used to set dependencies for Spree.
63
+ #
64
+ # Example:
65
+ #
66
+ # Spree.dependencies do |dependency|
67
+ # dependency.cart_add_item_service = MyCustomAddToCart
68
+ # end
69
+ #
70
+ # This method is defined within the core gem on purpose.
71
+ # Some people may only wish to use the Core part of Spree.
72
+ def self.dependencies
73
+ yield(Spree::Dependencies)
74
+ end
75
+
62
76
  module Core
63
77
  autoload :ProductFilters, 'spree/core/product_filters'
64
78
  autoload :TokenGenerator, 'spree/core/token_generator'
@@ -79,6 +93,7 @@ require 'spree/localized_number'
79
93
  require 'spree/money'
80
94
  require 'spree/permitted_attributes'
81
95
  require 'spree/service_module'
96
+ require 'spree/dependencies_helper'
82
97
 
83
98
  require 'spree/core/importer'
84
99
  require 'spree/core/query_filters'
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module DependenciesHelper
3
+ def current_values
4
+ values = []
5
+ self.class::INJECTION_POINTS.each do |injection_point|
6
+ values << { injection_point.to_s => instance_variable_get("@#{injection_point}") }
7
+ end
8
+ values
9
+ end
10
+ end
11
+ end
@@ -135,7 +135,9 @@ module CapybaraExt
135
135
  def spree_accept_alert
136
136
  yield
137
137
  rescue Selenium::WebDriver::Error::UnhandledAlertError
138
- page.driver.browser.switch_to.alert.accept
138
+ Selenium::WebDriver::Wait.new(timeout: 5)
139
+ .until { page.driver.browser.switch_to.alert }
140
+ .accept
139
141
  end
140
142
 
141
143
  def disable_html5_validation
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: 3.7.0.rc2
4
+ version: 3.7.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-22 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -419,6 +419,7 @@ files:
419
419
  - app/models/spree/adjustable/promotion_accumulator.rb
420
420
  - app/models/spree/adjustment.rb
421
421
  - app/models/spree/app_configuration.rb
422
+ - app/models/spree/app_dependencies.rb
422
423
  - app/models/spree/asset.rb
423
424
  - app/models/spree/asset/support/active_storage.rb
424
425
  - app/models/spree/base.rb
@@ -958,6 +959,7 @@ files:
958
959
  - lib/spree/core/search/base.rb
959
960
  - lib/spree/core/token_generator.rb
960
961
  - lib/spree/core/version.rb
962
+ - lib/spree/dependencies_helper.rb
961
963
  - lib/spree/i18n.rb
962
964
  - lib/spree/i18n/base.rb
963
965
  - lib/spree/i18n/initializer.rb
@@ -1066,8 +1068,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1066
1068
  - !ruby/object:Gem::Version
1067
1069
  version: 1.8.23
1068
1070
  requirements: []
1069
- rubyforge_project:
1070
- rubygems_version: 2.7.8
1071
+ rubygems_version: 3.0.2
1071
1072
  signing_key:
1072
1073
  specification_version: 4
1073
1074
  summary: The bare bones necessary for Spree.