solidus_core 2.10.0.beta1 → 2.10.5
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.
- checksums.yaml +4 -4
- data/app/helpers/spree/base_helper.rb +4 -4
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/spree/address.rb +11 -15
- data/app/models/spree/adjustment.rb +11 -0
- data/app/models/spree/calculator/price_sack.rb +1 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
- data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
- data/app/models/spree/calculator/tiered_percent.rb +6 -6
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/credit_card.rb +2 -2
- data/app/models/spree/inventory_unit.rb +1 -19
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/order.rb +3 -2
- data/app/models/spree/order/checkout.rb +1 -1
- data/app/models/spree/order/payments.rb +2 -2
- data/app/models/spree/order_capturing.rb +2 -2
- data/app/models/spree/order_taxation.rb +2 -2
- data/app/models/spree/payment.rb +4 -41
- data/app/models/spree/payment/processing.rb +2 -2
- data/app/models/spree/payment_method.rb +2 -2
- data/app/models/spree/product.rb +3 -3
- data/app/models/spree/product/scopes.rb +9 -8
- data/app/models/spree/promotion.rb +27 -12
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/option_value.rb +2 -2
- data/app/models/spree/promotion/rules/product.rb +3 -3
- data/app/models/spree/promotion_action.rb +1 -1
- data/app/models/spree/promotion_chooser.rb +2 -2
- data/app/models/spree/promotion_code.rb +9 -8
- data/app/models/spree/promotion_code/batch_builder.rb +3 -3
- data/app/models/spree/promotion_rule.rb +1 -1
- data/app/models/spree/refund.rb +2 -2
- data/app/models/spree/reimbursement.rb +3 -11
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
- data/app/models/spree/return_authorization.rb +1 -7
- data/app/models/spree/return_item.rb +3 -42
- data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
- data/app/models/spree/shipment.rb +4 -38
- data/app/models/spree/shipping_calculator.rb +0 -4
- data/app/models/spree/shipping_method.rb +1 -1
- data/app/models/spree/state.rb +1 -1
- data/app/models/spree/stock/differentiator.rb +1 -1
- data/app/models/spree/stock/package.rb +1 -1
- data/app/models/spree/stock_item.rb +1 -1
- data/app/models/spree/stock_quantities.rb +13 -12
- data/app/models/spree/tax_calculator/default.rb +0 -4
- data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
- data/app/models/spree/tax_rate.rb +4 -0
- data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
- data/app/models/spree/user_last_url_storer.rb +46 -0
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
- data/app/models/spree/variant.rb +9 -9
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/zone.rb +1 -1
- data/config/initializers/money.rb +2 -0
- data/config/locales/en.yml +12 -0
- data/lib/generators/spree/install/install_generator.rb +3 -0
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
- data/lib/spree/app_configuration.rb +18 -3
- data/lib/spree/core.rb +12 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -13
- data/lib/spree/core/controller_helpers/strong_parameters.rb +21 -7
- data/lib/spree/core/engine.rb +2 -2
- data/lib/spree/core/environment_extension.rb +9 -0
- data/lib/spree/core/importer/order.rb +27 -26
- data/lib/spree/core/product_filters.rb +15 -15
- data/lib/spree/core/role_configuration.rb +2 -2
- data/lib/spree/core/search/variant.rb +1 -1
- data/lib/spree/core/state_machines.rb +78 -0
- data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
- data/lib/spree/core/state_machines/payment.rb +61 -0
- data/lib/spree/core/state_machines/reimbursement.rb +33 -0
- data/lib/spree/core/state_machines/return_authorization.rb +32 -0
- data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
- data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
- data/lib/spree/core/state_machines/shipment.rb +58 -0
- data/lib/spree/core/stock_configuration.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -8
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/money.rb +2 -2
- data/lib/spree/permission_sets/user_management.rb +3 -0
- data/lib/spree/permitted_attributes.rb +78 -9
- data/lib/spree/preferences/static_model_preferences.rb +2 -2
- data/lib/spree/testing_support/dummy_app.rb +4 -1
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
- data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +4 -1
- data/solidus_core.gemspec +4 -4
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +8 -1
- data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
- data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
- data/spec/lib/spree/core/validators/email_spec.rb +18 -18
- data/spec/lib/spree/permitted_attributes_spec.rb +41 -0
- data/spec/models/spree/ability_spec.rb +1 -1
- data/spec/models/spree/address_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
- data/spec/models/spree/carton_spec.rb +8 -0
- data/spec/models/spree/classification_spec.rb +21 -9
- data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
- data/spec/models/spree/concerns/user_methods_spec.rb +2 -1
- data/spec/models/spree/order_merger_spec.rb +3 -3
- data/spec/models/spree/order_spec.rb +8 -15
- data/spec/models/spree/order_updater_spec.rb +4 -3
- data/spec/models/spree/payment_create_spec.rb +4 -14
- data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
- data/spec/models/spree/preference_spec.rb +4 -4
- data/spec/models/spree/preferences/preferable_spec.rb +3 -3
- data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/taxon_spec.rb +1 -0
- data/spec/models/spree/promotion_rule_spec.rb +6 -6
- data/spec/models/spree/promotion_spec.rb +73 -52
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
- data/spec/models/spree/returns_calculator_spec.rb +2 -2
- data/spec/models/spree/shipping_calculator_spec.rb +1 -13
- data/spec/models/spree/shipping_method_spec.rb +32 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
- data/spec/models/spree/stock/differentiator_spec.rb +2 -2
- data/spec/models/spree/stock/estimator_spec.rb +3 -3
- data/spec/models/spree/stock/package_spec.rb +28 -28
- data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
- data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
- data/spec/models/spree/stock_quantities_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +1 -1
- data/spec/models/spree/tax_rate_spec.rb +1 -0
- data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
- data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
- data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
- metadata +41 -35
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
- data/spec/models/spree/order/updating_spec.rb +0 -18
|
@@ -58,6 +58,9 @@ module Spree
|
|
|
58
58
|
|
|
59
59
|
def setup_assets
|
|
60
60
|
@lib_name = 'spree'
|
|
61
|
+
|
|
62
|
+
empty_directory 'app/assets/images'
|
|
63
|
+
|
|
61
64
|
%w{javascripts stylesheets images}.each do |path|
|
|
62
65
|
empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test?
|
|
63
66
|
empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test?
|
|
@@ -93,3 +93,11 @@ Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : opti
|
|
|
93
93
|
# just uncomment the following code and change it as you need.
|
|
94
94
|
#
|
|
95
95
|
# Spree::Model.whitelisted_ransackable_attributes << 'field'
|
|
96
|
+
|
|
97
|
+
# Rules for avoiding to store the current path into session for redirects
|
|
98
|
+
# When at least one rule is matched, the request path will not be stored
|
|
99
|
+
# in session.
|
|
100
|
+
# You can add your custom rules by uncommenting this line and changing
|
|
101
|
+
# the class name:
|
|
102
|
+
#
|
|
103
|
+
# Spree::UserLastUrlStorer.rules << 'Spree::UserLastUrlStorer::Rules::AuthenticationRule'
|
|
@@ -292,6 +292,14 @@ module Spree
|
|
|
292
292
|
|
|
293
293
|
class_name_attribute :variant_search_class, default: 'Spree::Core::Search::Variant'
|
|
294
294
|
|
|
295
|
+
# Allows implementing custom vat prices generation
|
|
296
|
+
# @!attribute [rw] variant_vat_prices_generator_class
|
|
297
|
+
# @see Spree::Variant::VatPriceGenerator
|
|
298
|
+
# @return [Class] an object that conforms to the API of
|
|
299
|
+
# the standard variant vat prices generator class
|
|
300
|
+
# Spree::Variant::VatPriceGenerator.
|
|
301
|
+
class_name_attribute :variant_vat_prices_generator_class, default: 'Spree::Variant::VatPriceGenerator'
|
|
302
|
+
|
|
295
303
|
# promotion_chooser_class allows extensions to provide their own PromotionChooser
|
|
296
304
|
class_name_attribute :promotion_chooser_class, default: 'Spree::PromotionChooser'
|
|
297
305
|
|
|
@@ -306,7 +314,6 @@ module Spree
|
|
|
306
314
|
# @!attribute [rw] shipping_rate_tax_calculator_class
|
|
307
315
|
# @return [Class] a class with the same public interfaces as
|
|
308
316
|
# Spree::TaxCalculator::ShippingRate
|
|
309
|
-
# @api experimental
|
|
310
317
|
class_name_attribute :shipping_rate_tax_calculator_class, default: 'Spree::TaxCalculator::ShippingRate'
|
|
311
318
|
|
|
312
319
|
# Allows providing your own Mailer for order mailer.
|
|
@@ -384,7 +391,6 @@ module Spree
|
|
|
384
391
|
# @!attribute [rw] tax_adjuster_class
|
|
385
392
|
# @return [Class] a class with the same public interfaces as
|
|
386
393
|
# Spree::Tax::OrderAdjuster
|
|
387
|
-
# @api experimental
|
|
388
394
|
class_name_attribute :tax_adjuster_class, default: 'Spree::Tax::OrderAdjuster'
|
|
389
395
|
|
|
390
396
|
# Allows providing your own class for calculating taxes on an order.
|
|
@@ -392,7 +398,6 @@ module Spree
|
|
|
392
398
|
# @!attribute [rw] tax_calculator_class
|
|
393
399
|
# @return [Class] a class with the same public interfaces as
|
|
394
400
|
# Spree::TaxCalculator::Default
|
|
395
|
-
# @api experimental
|
|
396
401
|
class_name_attribute :tax_calculator_class, default: 'Spree::TaxCalculator::Default'
|
|
397
402
|
|
|
398
403
|
# Allows providing your own class for choosing which store to use.
|
|
@@ -454,6 +459,10 @@ module Spree
|
|
|
454
459
|
@order_number_generator ||= Spree::Order::NumberGenerator.new
|
|
455
460
|
end
|
|
456
461
|
|
|
462
|
+
def state_machines
|
|
463
|
+
@state_machines ||= Spree::Core::StateMachines.new
|
|
464
|
+
end
|
|
465
|
+
|
|
457
466
|
def static_model_preferences
|
|
458
467
|
@static_model_preferences ||= Spree::Preferences::StaticModelPreferences.new
|
|
459
468
|
end
|
|
@@ -473,6 +482,12 @@ module Spree
|
|
|
473
482
|
@events_configuration ||= Spree::Event::Configuration.new
|
|
474
483
|
end
|
|
475
484
|
|
|
485
|
+
def user_last_url_storer_rules
|
|
486
|
+
@user_last_url_storer_rules ||= ::Spree::Core::ClassConstantizer::Set.new.tap do |set|
|
|
487
|
+
set << 'Spree::UserLastUrlStorer::Rules::AuthenticationRule'
|
|
488
|
+
end
|
|
489
|
+
end
|
|
490
|
+
|
|
476
491
|
def environment
|
|
477
492
|
@environment ||= Spree::Core::Environment.new(self).tap do |env|
|
|
478
493
|
env.calculators.promotion_actions_create_adjustments = %w[
|
data/lib/spree/core.rb
CHANGED
|
@@ -53,6 +53,17 @@ module Spree
|
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
if Gem::Version.new(Rails.version) < Gem::Version.new('5.2')
|
|
57
|
+
warn <<~HEREDOC
|
|
58
|
+
Rails 5.1 (EOL) is deprecated and will not be supported anymore from the next Solidus version.
|
|
59
|
+
Please, upgrade to a more recent Rails version.
|
|
60
|
+
|
|
61
|
+
Read more on upgrading from Rails 5.1 to Rails 5.2 here:
|
|
62
|
+
https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-5-1-to-rails-5-2
|
|
63
|
+
|
|
64
|
+
HEREDOC
|
|
65
|
+
end
|
|
66
|
+
|
|
56
67
|
require 'spree/core/version'
|
|
57
68
|
|
|
58
69
|
require 'spree/core/active_merchant_dependencies'
|
|
@@ -85,6 +96,7 @@ require 'spree/core/controller_helpers/search'
|
|
|
85
96
|
require 'spree/core/controller_helpers/store'
|
|
86
97
|
require 'spree/core/controller_helpers/strong_parameters'
|
|
87
98
|
require 'spree/core/role_configuration'
|
|
99
|
+
require 'spree/core/state_machines'
|
|
88
100
|
require 'spree/core/stock_configuration'
|
|
89
101
|
require 'spree/core/validators/email'
|
|
90
102
|
require 'spree/permission_sets'
|
|
@@ -50,19 +50,7 @@ module Spree
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def store_location
|
|
53
|
-
|
|
54
|
-
authentication_routes = [:spree_signup_path, :spree_login_path, :spree_logout_path]
|
|
55
|
-
disallowed_urls = []
|
|
56
|
-
authentication_routes.each do |route|
|
|
57
|
-
if respond_to?(route)
|
|
58
|
-
disallowed_urls << send(route)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
disallowed_urls.map!{ |url| url[/\/\w+$/] }
|
|
63
|
-
unless disallowed_urls.include?(request.fullpath)
|
|
64
|
-
session['spree_user_return_to'] = request.fullpath.gsub('//', '/')
|
|
65
|
-
end
|
|
53
|
+
Spree::UserLastUrlStorer.new(self).store_location
|
|
66
54
|
end
|
|
67
55
|
|
|
68
56
|
# proxy method to *possible* spree_current_user method
|
|
@@ -31,16 +31,30 @@ module Spree
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def permitted_checkout_attributes
|
|
34
|
-
permitted_attributes.checkout_attributes
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
permitted_attributes.checkout_attributes
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def permitted_checkout_address_attributes
|
|
38
|
+
permitted_attributes.checkout_address_attributes
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def permitted_checkout_delivery_attributes
|
|
42
|
+
permitted_attributes.checkout_delivery_attributes
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def permitted_checkout_payment_attributes
|
|
46
|
+
permitted_attributes.checkout_payment_attributes
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def permitted_checkout_confirm_attributes
|
|
50
|
+
permitted_attributes.checkout_confirm_attributes
|
|
40
51
|
end
|
|
41
52
|
|
|
42
53
|
def permitted_order_attributes
|
|
43
|
-
|
|
54
|
+
permitted_checkout_address_attributes +
|
|
55
|
+
permitted_checkout_delivery_attributes +
|
|
56
|
+
permitted_checkout_payment_attributes +
|
|
57
|
+
permitted_checkout_confirm_attributes + [
|
|
44
58
|
line_items_attributes: permitted_line_item_attributes
|
|
45
59
|
]
|
|
46
60
|
end
|
data/lib/spree/core/engine.rb
CHANGED
|
@@ -11,8 +11,8 @@ module Spree
|
|
|
11
11
|
isolate_namespace Spree
|
|
12
12
|
engine_name 'spree'
|
|
13
13
|
|
|
14
|
-
config.generators do |
|
|
15
|
-
|
|
14
|
+
config.generators do |generator|
|
|
15
|
+
generator.test_framework :rspec
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
initializer "spree.environment", before: :load_config_initializers do |app|
|
|
@@ -22,6 +22,15 @@ module Spree
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
|
+
|
|
26
|
+
def add_class(name)
|
|
27
|
+
Spree::Deprecation.warn(
|
|
28
|
+
'This method is deprecated. ' \
|
|
29
|
+
"Please use `#{self.class}.add_class_set(#{name.inspect})` instead.",
|
|
30
|
+
caller,
|
|
31
|
+
)
|
|
32
|
+
singleton_class.send(:add_class_set, name)
|
|
33
|
+
end
|
|
25
34
|
end
|
|
26
35
|
end
|
|
27
36
|
end
|
|
@@ -53,17 +53,17 @@ module Spree
|
|
|
53
53
|
def self.create_shipments_from_params(shipments_hash, order)
|
|
54
54
|
return [] unless shipments_hash
|
|
55
55
|
|
|
56
|
-
shipments_hash.each do |
|
|
56
|
+
shipments_hash.each do |target|
|
|
57
57
|
shipment = Shipment.new
|
|
58
|
-
shipment.tracking =
|
|
59
|
-
shipment.stock_location = Spree::StockLocation.find_by(admin_name:
|
|
58
|
+
shipment.tracking = target[:tracking]
|
|
59
|
+
shipment.stock_location = Spree::StockLocation.find_by(admin_name: target[:stock_location]) || Spree::StockLocation.find_by!(name: target[:stock_location])
|
|
60
60
|
|
|
61
|
-
inventory_units =
|
|
62
|
-
inventory_units.each do |
|
|
63
|
-
ensure_variant_id_from_params(
|
|
61
|
+
inventory_units = target[:inventory_units] || []
|
|
62
|
+
inventory_units.each do |inventory_unit|
|
|
63
|
+
ensure_variant_id_from_params(inventory_unit)
|
|
64
64
|
|
|
65
|
-
unless line_item = order.line_items.find_by(variant_id:
|
|
66
|
-
line_item = order.contents.add(Spree::Variant.find(
|
|
65
|
+
unless line_item = order.line_items.find_by(variant_id: inventory_unit[:variant_id])
|
|
66
|
+
line_item = order.contents.add(Spree::Variant.find(inventory_unit[:variant_id]), 1)
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
# Spree expects a Inventory Unit to always reference a line
|
|
@@ -71,14 +71,14 @@ module Spree
|
|
|
71
71
|
# trying to view these units. Note the Importer might not be
|
|
72
72
|
# able to find the line item if line_item.variant_id |= iu.variant_id
|
|
73
73
|
shipment.inventory_units.new(
|
|
74
|
-
variant_id:
|
|
74
|
+
variant_id: inventory_unit[:variant_id],
|
|
75
75
|
line_item: line_item
|
|
76
76
|
)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# Mark shipped if it should be.
|
|
80
|
-
if
|
|
81
|
-
shipment.shipped_at =
|
|
80
|
+
if target[:shipped_at].present?
|
|
81
|
+
shipment.shipped_at = target[:shipped_at]
|
|
82
82
|
shipment.state = 'shipped'
|
|
83
83
|
shipment.inventory_units.each do |unit|
|
|
84
84
|
unit.state = 'shipped'
|
|
@@ -88,9 +88,9 @@ module Spree
|
|
|
88
88
|
order.shipments << shipment
|
|
89
89
|
shipment.save!
|
|
90
90
|
|
|
91
|
-
shipping_method = Spree::ShippingMethod.find_by(name:
|
|
91
|
+
shipping_method = Spree::ShippingMethod.find_by(name: target[:shipping_method]) || Spree::ShippingMethod.find_by!(admin_name: target[:shipping_method])
|
|
92
92
|
rate = shipment.shipping_rates.create!(shipping_method: shipping_method,
|
|
93
|
-
cost:
|
|
93
|
+
cost: target[:cost])
|
|
94
94
|
shipment.selected_shipping_rate_id = rate.id
|
|
95
95
|
shipment.update_amounts
|
|
96
96
|
end
|
|
@@ -98,9 +98,9 @@ module Spree
|
|
|
98
98
|
|
|
99
99
|
def self.create_line_items_from_params(line_items_hash, order)
|
|
100
100
|
return {} unless line_items_hash
|
|
101
|
-
line_items_hash.each_key do |
|
|
102
|
-
extra_params = line_items_hash[
|
|
103
|
-
line_item = ensure_variant_id_from_params(line_items_hash[
|
|
101
|
+
line_items_hash.each_key do |key|
|
|
102
|
+
extra_params = line_items_hash[key].except(:variant_id, :quantity, :sku)
|
|
103
|
+
line_item = ensure_variant_id_from_params(line_items_hash[key])
|
|
104
104
|
line_item = order.contents.add(Spree::Variant.find(line_item[:variant_id]), line_item[:quantity])
|
|
105
105
|
# Raise any errors with saving to prevent import succeeding with line items failing silently.
|
|
106
106
|
if extra_params.present?
|
|
@@ -113,11 +113,11 @@ module Spree
|
|
|
113
113
|
|
|
114
114
|
def self.create_adjustments_from_params(adjustments, order)
|
|
115
115
|
return [] unless adjustments
|
|
116
|
-
adjustments.each do |
|
|
116
|
+
adjustments.each do |target|
|
|
117
117
|
adjustment = order.adjustments.build(
|
|
118
118
|
order: order,
|
|
119
|
-
amount:
|
|
120
|
-
label:
|
|
119
|
+
amount: target[:amount].to_d,
|
|
120
|
+
label: target[:label]
|
|
121
121
|
)
|
|
122
122
|
adjustment.save!
|
|
123
123
|
adjustment.finalize!
|
|
@@ -126,14 +126,15 @@ module Spree
|
|
|
126
126
|
|
|
127
127
|
def self.create_payments_from_params(payments_hash, order)
|
|
128
128
|
return [] unless payments_hash
|
|
129
|
-
payments_hash.each do |
|
|
129
|
+
payments_hash.each do |target|
|
|
130
130
|
payment = order.payments.build order: order
|
|
131
|
-
payment.amount =
|
|
131
|
+
payment.amount = target[:amount].to_f
|
|
132
132
|
# Order API should be using state as that's the normal payment field.
|
|
133
133
|
# spree_wombat serializes payment state as status so imported orders should fall back to status field.
|
|
134
|
-
payment.state =
|
|
135
|
-
payment.payment_method = Spree::PaymentMethod.find_by!(name:
|
|
136
|
-
|
|
134
|
+
payment.state = target[:state] || target[:status] || 'completed'
|
|
135
|
+
payment.payment_method = Spree::PaymentMethod.find_by!(name: target[:payment_method])
|
|
136
|
+
source_attributes = target[:source] || target[:source_attributes]
|
|
137
|
+
payment.source = create_source_payment_from_params(source_attributes, payment) if source_attributes
|
|
137
138
|
payment.save!
|
|
138
139
|
end
|
|
139
140
|
end
|
|
@@ -170,8 +171,8 @@ module Spree
|
|
|
170
171
|
search[:iso_name] = iso_name.upcase
|
|
171
172
|
elsif iso = address[:country]['iso']
|
|
172
173
|
search[:iso] = iso.upcase
|
|
173
|
-
elsif
|
|
174
|
-
search[:iso3] =
|
|
174
|
+
elsif iso_three = address[:country]['iso3']
|
|
175
|
+
search[:iso3] = iso_three.upcase
|
|
175
176
|
end
|
|
176
177
|
|
|
177
178
|
address.delete(:country)
|
|
@@ -55,7 +55,7 @@ module Spree
|
|
|
55
55
|
# below scope would be something like ["$10 - $15", "$15 - $18", "$18 - $20"]
|
|
56
56
|
#
|
|
57
57
|
Spree::Product.add_search_scope :price_range_any do |*opts|
|
|
58
|
-
conds = opts.map { |
|
|
58
|
+
conds = opts.map { |element| Spree::Core::ProductFilters.price_filter[:conds][element] }.reject(&:nil?)
|
|
59
59
|
scope = conds.shift
|
|
60
60
|
conds.each do |new_scope|
|
|
61
61
|
scope = scope.or(new_scope)
|
|
@@ -68,17 +68,17 @@ module Spree
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def self.price_filter
|
|
71
|
-
|
|
72
|
-
conds = [[I18n.t('spree.under_price', price: format_price(10)),
|
|
73
|
-
["#{format_price(10)} - #{format_price(15)}",
|
|
74
|
-
["#{format_price(15)} - #{format_price(18)}",
|
|
75
|
-
["#{format_price(18)} - #{format_price(20)}",
|
|
76
|
-
[I18n.t('spree.or_over_price', price: format_price(20)),
|
|
71
|
+
value = Spree::Price.arel_table
|
|
72
|
+
conds = [[I18n.t('spree.under_price', price: format_price(10)), value[:amount].lteq(10)],
|
|
73
|
+
["#{format_price(10)} - #{format_price(15)}", value[:amount].in(10..15)],
|
|
74
|
+
["#{format_price(15)} - #{format_price(18)}", value[:amount].in(15..18)],
|
|
75
|
+
["#{format_price(18)} - #{format_price(20)}", value[:amount].in(18..20)],
|
|
76
|
+
[I18n.t('spree.or_over_price', price: format_price(20)), value[:amount].gteq(20)]]
|
|
77
77
|
{
|
|
78
78
|
name: I18n.t('spree.price_range'),
|
|
79
79
|
scope: :price_range_any,
|
|
80
80
|
conds: Hash[*conds.flatten],
|
|
81
|
-
labels: conds.map { |
|
|
81
|
+
labels: conds.map { |key, _value| [key, key] }
|
|
82
82
|
}
|
|
83
83
|
end
|
|
84
84
|
|
|
@@ -95,7 +95,7 @@ module Spree
|
|
|
95
95
|
# being blank: note that this relies on with_property doing a left outer join
|
|
96
96
|
# rather than an inner join.
|
|
97
97
|
Spree::Product.add_search_scope :brand_any do |*opts|
|
|
98
|
-
conds = opts.map { |
|
|
98
|
+
conds = opts.map { |value| ProductFilters.brand_filter[:conds][value] }.reject(&:nil?)
|
|
99
99
|
scope = conds.shift
|
|
100
100
|
conds.each do |new_scope|
|
|
101
101
|
scope = scope.or(new_scope)
|
|
@@ -107,12 +107,12 @@ module Spree
|
|
|
107
107
|
brand_property = Spree::Property.find_by(name: 'brand')
|
|
108
108
|
brands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []
|
|
109
109
|
pp = Spree::ProductProperty.arel_table
|
|
110
|
-
conds = Hash[*brands.map { |
|
|
110
|
+
conds = Hash[*brands.map { |brand| [brand, pp[:value].eq(brand)] }.flatten]
|
|
111
111
|
{
|
|
112
112
|
name: 'Brands',
|
|
113
113
|
scope: :brand_any,
|
|
114
114
|
conds: conds,
|
|
115
|
-
labels: brands.sort.map { |
|
|
115
|
+
labels: brands.sort.map { |key| [key, key] }
|
|
116
116
|
}
|
|
117
117
|
end
|
|
118
118
|
|
|
@@ -149,7 +149,7 @@ module Spree
|
|
|
149
149
|
{
|
|
150
150
|
name: 'Applicable Brands',
|
|
151
151
|
scope: :selective_brand_any,
|
|
152
|
-
labels: brands.sort.map { |
|
|
152
|
+
labels: brands.sort.map { |key| [key, key] }
|
|
153
153
|
}
|
|
154
154
|
end
|
|
155
155
|
|
|
@@ -171,7 +171,7 @@ module Spree
|
|
|
171
171
|
{
|
|
172
172
|
name: 'Taxons under ' + taxon.name,
|
|
173
173
|
scope: :taxons_id_in_tree_any,
|
|
174
|
-
labels: taxon.children.sort_by(&:position).map { |
|
|
174
|
+
labels: taxon.children.sort_by(&:position).map { |element| [element.name, element.id] },
|
|
175
175
|
conds: nil
|
|
176
176
|
}
|
|
177
177
|
end
|
|
@@ -184,11 +184,11 @@ module Spree
|
|
|
184
184
|
# idea: expand the format to allow nesting of labels?
|
|
185
185
|
def self.all_taxons
|
|
186
186
|
Spree::Deprecation.warn "all_taxons is deprecated in solidus_core. Please add it to your own application to continue using it."
|
|
187
|
-
taxons = Spree::Taxonomy.all.map { |
|
|
187
|
+
taxons = Spree::Taxonomy.all.map { |element| [element.root] + element.root.descendants }.flatten
|
|
188
188
|
{
|
|
189
189
|
name: 'All taxons',
|
|
190
190
|
scope: :taxons_id_equals_any,
|
|
191
|
-
labels: taxons.sort_by(&:name).map { |
|
|
191
|
+
labels: taxons.sort_by(&:name).map { |element| [element.name, element.id] },
|
|
192
192
|
conds: nil # not needed
|
|
193
193
|
}
|
|
194
194
|
end
|
|
@@ -69,8 +69,8 @@ module Spree
|
|
|
69
69
|
# Not public due to the fact this class is a Singleton
|
|
70
70
|
# @!visibility private
|
|
71
71
|
def initialize
|
|
72
|
-
@roles = Hash.new do |
|
|
73
|
-
|
|
72
|
+
@roles = Hash.new do |hash, name|
|
|
73
|
+
hash[name] = Role.new(name, Set.new)
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
attr_writer :reimbursement,
|
|
7
|
+
:return_authorization,
|
|
8
|
+
:return_item_acceptance,
|
|
9
|
+
:return_item_reception,
|
|
10
|
+
:payment,
|
|
11
|
+
:inventory_unit,
|
|
12
|
+
:shipment
|
|
13
|
+
|
|
14
|
+
def return_authorization
|
|
15
|
+
@return_authorization ||= begin
|
|
16
|
+
require 'spree/core/state_machines/return_authorization'
|
|
17
|
+
'Spree::Core::StateMachines::ReturnAuthorization'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@return_authorization.constantize
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def return_item_reception
|
|
24
|
+
@return_item_reception_status ||= begin
|
|
25
|
+
require 'spree/core/state_machines/return_item/reception_status'
|
|
26
|
+
'Spree::Core::StateMachines::ReturnItem::ReceptionStatus'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@return_item_reception_status.constantize
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def return_item_acceptance
|
|
33
|
+
@return_item_acceptance_status ||= begin
|
|
34
|
+
require 'spree/core/state_machines/return_item/acceptance_status'
|
|
35
|
+
'Spree::Core::StateMachines::ReturnItem::AcceptanceStatus'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
@return_item_acceptance_status.constantize
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def payment
|
|
42
|
+
@payment ||= begin
|
|
43
|
+
require 'spree/core/state_machines/payment'
|
|
44
|
+
'Spree::Core::StateMachines::Payment'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@payment.constantize
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def inventory_unit
|
|
51
|
+
@inventory_unit ||= begin
|
|
52
|
+
require 'spree/core/state_machines/inventory_unit'
|
|
53
|
+
'Spree::Core::StateMachines::InventoryUnit'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
@inventory_unit.constantize
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def shipment
|
|
60
|
+
@shipment ||= begin
|
|
61
|
+
require 'spree/core/state_machines/shipment'
|
|
62
|
+
'Spree::Core::StateMachines::Shipment'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
@shipment.constantize
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def reimbursement
|
|
69
|
+
@reimbursement ||= begin
|
|
70
|
+
require 'spree/core/state_machines/reimbursement'
|
|
71
|
+
'Spree::Core::StateMachines::Reimbursement'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
@reimbursement.constantize
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|