solidus_core 2.11.10 → 3.3.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.
- checksums.yaml +4 -4
- data/Rakefile +6 -2
- data/app/assets/javascripts/spree.js.erb +0 -51
- data/app/controllers/spree/base_controller.rb +1 -1
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/helpers/spree/products_helper.rb +2 -2
- data/app/helpers/spree/store_helper.rb +0 -11
- data/app/mailers/spree/carton_mailer.rb +1 -5
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- data/app/models/concerns/spree/adjustment_source.rb +0 -15
- data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
- data/app/models/concerns/spree/default_price.rb +39 -10
- data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
- data/app/models/concerns/spree/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +10 -37
- data/app/models/concerns/spree/user_methods.rb +38 -13
- data/app/models/spree/ability.rb +0 -37
- data/app/models/spree/address/name.rb +2 -20
- data/app/models/spree/address.rb +8 -186
- data/app/models/spree/adjustment.rb +7 -33
- data/app/models/spree/base.rb +0 -53
- data/app/models/spree/calculator/flat_fee.rb +21 -0
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -7
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/country.rb +2 -7
- data/app/models/spree/credit_card.rb +1 -28
- data/app/models/spree/customer_return.rb +5 -7
- data/app/models/spree/image/active_storage_attachment.rb +2 -7
- data/app/models/spree/image/paperclip_attachment.rb +2 -2
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +6 -49
- data/app/models/spree/log_entry.rb +74 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +10 -1
- data/app/models/spree/order/number_generator.rb +7 -1
- data/app/models/spree/order.rb +82 -170
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_contents.rb +2 -1
- data/app/models/spree/order_inventory.rb +1 -1
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_promotion.rb +1 -1
- data/app/models/spree/order_shipping.rb +6 -9
- data/app/models/spree/order_taxation.rb +6 -4
- data/app/models/spree/order_updater.rb +17 -16
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment/processing.rb +58 -55
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
- data/app/models/spree/payment_method.rb +26 -110
- data/app/models/spree/price.rb +3 -3
- data/app/models/spree/product/scopes.rb +24 -33
- data/app/models/spree/product.rb +15 -42
- data/app/models/spree/product_property.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
- data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
- data/app/models/spree/promotion/rules/item_total.rb +50 -6
- data/app/models/spree/promotion/rules/product.rb +20 -8
- data/app/models/spree/promotion/rules/store.rb +4 -0
- data/app/models/spree/promotion/rules/taxon.rb +6 -15
- data/app/models/spree/promotion/rules/user.rb +4 -0
- data/app/models/spree/promotion.rb +39 -32
- data/app/models/spree/promotion_action.rb +6 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_code.rb +11 -7
- data/app/models/spree/promotion_handler/cart.rb +26 -6
- data/app/models/spree/promotion_rule.rb +5 -0
- data/app/models/spree/property.rb +1 -1
- data/app/models/spree/refund.rb +8 -52
- data/app/models/spree/reimbursement.rb +5 -43
- data/app/models/spree/reimbursement_performer.rb +2 -8
- data/app/models/spree/reimbursement_type/credit.rb +1 -4
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
- data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
- data/app/models/spree/return_authorization.rb +2 -5
- data/app/models/spree/return_item.rb +4 -24
- data/app/models/spree/shipment.rb +3 -56
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/shipping_rate_tax.rb +1 -1
- data/app/models/spree/state.rb +1 -5
- data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
- data/app/models/spree/stock/availability.rb +11 -3
- data/app/models/spree/stock/quantifier.rb +12 -8
- data/app/models/spree/stock/simple_coordinator.rb +8 -26
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +2 -8
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit.rb +14 -1
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/store_credit_prioritizer.rb +17 -0
- data/app/models/spree/tax/item_tax.rb +3 -2
- data/app/models/spree/tax/order_tax.rb +3 -1
- data/app/models/spree/tax/tax_helpers.rb +2 -2
- data/app/models/spree/tax/tax_location.rb +4 -7
- data/app/models/spree/tax_calculator/default.rb +31 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
- data/app/models/spree/tax_rate.rb +9 -27
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
- data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
- data/app/models/spree/taxon.rb +1 -12
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
- data/app/models/spree/variant/price_selector.rb +34 -4
- data/app/models/spree/variant.rb +52 -66
- data/app/models/spree/zone.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +4 -0
- data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
- data/config/i18n-tasks.yml +134 -0
- data/config/locales/en.yml +406 -263
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
- data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
- data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
- data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
- data/db/seeds.rb +4 -1
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
- data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
- data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
- data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
- data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
- data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
- data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
- data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
- data/lib/generators/solidus/install/install_generator.rb +247 -149
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
- data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
- data/lib/generators/solidus/update/update_generator.rb +112 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
- data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
- data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
- data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/spree/app_configuration.rb +134 -64
- data/lib/spree/bus.rb +20 -0
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +10 -15
- data/lib/spree/core/controller_helpers/current_host.rb +5 -3
- data/lib/spree/core/controller_helpers/order.rb +12 -32
- data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
- data/lib/spree/core/controller_helpers/pricing.rb +0 -8
- data/lib/spree/core/controller_helpers/search.rb +1 -1
- data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +54 -50
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +1 -41
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +18 -35
- data/lib/spree/core/state_machines/order.rb +2 -2
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/stock_configuration.rb +18 -0
- data/lib/spree/core/validators/email.rb +5 -3
- data/lib/spree/core/version.rb +5 -1
- data/lib/spree/core/versioned_value.rb +75 -0
- data/lib/spree/core.rb +40 -11
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/event/configuration.rb +0 -5
- data/lib/spree/event/subscriber.rb +0 -18
- data/lib/spree/event/subscriber_registry.rb +7 -7
- data/lib/spree/event.rb +1 -32
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/migrations.rb +13 -11
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permission_sets/default_customer.rb +8 -1
- data/lib/spree/permitted_attributes.rb +17 -59
- data/lib/spree/preferences/configuration.rb +84 -0
- data/lib/spree/preferences/preferable.rb +13 -0
- data/lib/spree/preferences/preferable_class_methods.rb +37 -4
- data/lib/spree/preferences/preference_differentiator.rb +29 -0
- data/lib/spree/preferences/static_model_preferences.rb +25 -10
- data/lib/spree/rails_compatibility.rb +106 -0
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/bus_helpers.rb +101 -0
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/common_rake.rb +71 -23
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/database.yml +42 -22
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +47 -34
- data/lib/spree/testing_support/factories/address_factory.rb +9 -6
- data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
- data/lib/spree/testing_support/factories/country_factory.rb +1 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +8 -5
- data/lib/spree/testing_support/factories/product_factory.rb +4 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/factories/state_factory.rb +8 -2
- data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
- data/lib/spree/testing_support/factories/user_factory.rb +6 -0
- data/lib/spree/testing_support/factory_bot.rb +2 -2
- data/lib/spree/testing_support/order_walkthrough.rb +6 -8
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/spree/testing_support/silence_deprecations.rb +9 -0
- data/lib/tasks/colorado_delivery_fee.rake +28 -0
- data/lib/tasks/payment_method.rake +29 -0
- data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
- data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
- data/solidus_core.gemspec +14 -7
- metadata +127 -78
- data/app/mailers/spree/test_mailer.rb +0 -13
- data/app/models/concerns/spree/user_payment_source.rb +0 -26
- data/app/models/spree/calculator/free_shipping.rb +0 -22
- data/app/models/spree/calculator/percent_per_item.rb +0 -51
- data/app/models/spree/calculator/price_sack.rb +0 -28
- data/app/models/spree/gateway/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- data/app/models/spree/gateway.rb +0 -14
- data/app/models/spree/order/checkout.rb +0 -244
- data/app/models/spree/order_capturing.rb +0 -50
- data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
- data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
- data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
- data/lib/generators/spree/install/install_generator.rb +0 -15
- data/lib/solidus/migrations/rename_gateways.rb +0 -41
- data/lib/spree/core/current_store.rb +0 -24
- data/lib/spree/paranoia_deprecations.rb +0 -41
- data/lib/spree/promo/environment.rb +0 -12
- data/lib/spree/testing_support/bar_ability.rb +0 -19
- data/lib/tasks/core.rake +0 -104
- data/lib/tasks/email.rake +0 -12
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
- data/lib/tasks/migrations/migrate_address_names.rake +0 -158
- data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
- data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
- data/lib/tasks/migrations/rename_gateways.rake +0 -23
- data/lib/tasks/order_capturing.rake +0 -27
- data/lib/tasks/upgrade.rake +0 -13
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
# Get the on_hand stock quantities
|
20
20
|
# @return [Hash<Integer=>Spree::StockQuantities>] A map of stock_location_ids to the stock quantities available in that location
|
21
21
|
def on_hand_by_stock_location_id
|
22
|
-
counts_on_hand.to_a.group_by do |(_, stock_location_id), _|
|
22
|
+
quantities_by_location_id = counts_on_hand.to_a.group_by do |(_, stock_location_id), _|
|
23
23
|
stock_location_id
|
24
24
|
end.transform_values do |values|
|
25
25
|
Spree::StockQuantities.new(
|
@@ -31,12 +31,13 @@ module Spree
|
|
31
31
|
end.to_h
|
32
32
|
)
|
33
33
|
end
|
34
|
+
restore_location_order(quantities_by_location_id)
|
34
35
|
end
|
35
36
|
|
36
|
-
# Get the
|
37
|
+
# Get the backorderable stock quantities
|
37
38
|
# @return [Hash<Integer=>Spree::StockQuantities>] A map of stock_location_ids to the stock quantities available in that location
|
38
39
|
def backorderable_by_stock_location_id
|
39
|
-
backorderables.group_by(&:second).transform_values do |variant_ids|
|
40
|
+
quantities_by_location_id = backorderables.group_by(&:second).transform_values do |variant_ids|
|
40
41
|
Spree::StockQuantities.new(
|
41
42
|
variant_ids.map do |variant_id, _|
|
42
43
|
variant = @variant_map[variant_id]
|
@@ -44,6 +45,7 @@ module Spree
|
|
44
45
|
end.to_h
|
45
46
|
)
|
46
47
|
end
|
48
|
+
restore_location_order(quantities_by_location_id)
|
47
49
|
end
|
48
50
|
|
49
51
|
private
|
@@ -67,6 +69,12 @@ module Spree
|
|
67
69
|
where(variant_id: @variants).
|
68
70
|
where(stock_location_id: @stock_locations)
|
69
71
|
end
|
72
|
+
|
73
|
+
def restore_location_order(quantities_by_location_id)
|
74
|
+
sorted_location_ids = @stock_locations.map(&:id)
|
75
|
+
|
76
|
+
quantities_by_location_id.sort_by { |key, _value| sorted_location_ids.index(key) }.to_h
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
72
80
|
end
|
@@ -6,14 +6,18 @@ module Spree
|
|
6
6
|
attr_reader :stock_items
|
7
7
|
|
8
8
|
# @param [Variant] variant The variant to check inventory for.
|
9
|
-
# @param [StockLocation, Integer]
|
10
|
-
|
9
|
+
# @param [StockLocation, Integer] stock_location_or_id
|
10
|
+
# The stock_location or stock location ID to check inventory in.
|
11
|
+
# If unspecified it will check inventory in all available StockLocations
|
12
|
+
def initialize(variant, stock_location_or_id = nil)
|
11
13
|
@variant = variant
|
12
|
-
@stock_items =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
@stock_items = variant.stock_items.select do |stock_item|
|
15
|
+
if stock_location_or_id
|
16
|
+
stock_item.stock_location == stock_location_or_id ||
|
17
|
+
stock_item.stock_location_id == stock_location_or_id
|
18
|
+
else
|
19
|
+
stock_item.stock_location.active?
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
@@ -23,7 +27,7 @@ module Spree
|
|
23
27
|
# inventory is not tracked on the variant.
|
24
28
|
def total_on_hand
|
25
29
|
if @variant.should_track_inventory?
|
26
|
-
stock_items.sum(
|
30
|
+
stock_items.sum(&:count_on_hand)
|
27
31
|
else
|
28
32
|
Float::INFINITY
|
29
33
|
end
|
@@ -24,7 +24,8 @@ module Spree
|
|
24
24
|
|
25
25
|
def initialize(order, inventory_units = nil)
|
26
26
|
@order = order
|
27
|
-
@inventory_units =
|
27
|
+
@inventory_units =
|
28
|
+
inventory_units || Spree::Config.stock.inventory_unit_builder_class.new(order).units
|
28
29
|
@splitters = Spree::Config.environment.stock_splitters
|
29
30
|
|
30
31
|
filtered_stock_locations = Spree::Config.stock.location_filter_class.new(Spree::StockLocation.all, @order).filter
|
@@ -73,11 +74,16 @@ module Spree
|
|
73
74
|
packages = split_packages(packages)
|
74
75
|
|
75
76
|
# Turn the Stock::Packages into a Shipment with rates
|
76
|
-
packages.map do |package|
|
77
|
+
shipments = packages.map do |package|
|
77
78
|
shipment = package.shipment = package.to_shipment
|
78
79
|
shipment.shipping_rates = Spree::Config.stock.estimator_class.new.shipping_rates(package)
|
79
80
|
shipment
|
80
81
|
end
|
82
|
+
|
83
|
+
# Make sure we don't add the proposed shipments to the order
|
84
|
+
order.shipments = order.shipments - shipments
|
85
|
+
|
86
|
+
shipments
|
81
87
|
end
|
82
88
|
|
83
89
|
def split_packages(initial_packages)
|
@@ -87,30 +93,6 @@ module Spree
|
|
87
93
|
end
|
88
94
|
end
|
89
95
|
|
90
|
-
def allocate_inventory(availability_by_location)
|
91
|
-
sorted_availability = sort_availability(availability_by_location)
|
92
|
-
|
93
|
-
sorted_availability.transform_values do |available|
|
94
|
-
# Find the desired inventory which is available at this location
|
95
|
-
packaged = available & @desired
|
96
|
-
# Remove found inventory from desired
|
97
|
-
@desired -= packaged
|
98
|
-
packaged
|
99
|
-
end
|
100
|
-
end
|
101
|
-
deprecate allocate_inventory: 'allocate_inventory is deprecated. Please write your own allocator defining' \
|
102
|
-
'a Spree::Stock::Allocator::Base subclass', deprecator: Spree::Deprecation
|
103
|
-
|
104
|
-
def sort_availability(availability)
|
105
|
-
sorted_availability = availability.sort_by do |stock_location_id, _|
|
106
|
-
@stock_locations.find_index do |stock_location|
|
107
|
-
stock_location.id == stock_location_id
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
Hash[sorted_availability]
|
112
|
-
end
|
113
|
-
|
114
96
|
def get_units(quantities)
|
115
97
|
# Change our raw quantities back into inventory units
|
116
98
|
quantities.flat_map do |variant, quantity|
|
@@ -6,13 +6,8 @@ module Spree
|
|
6
6
|
class Base
|
7
7
|
attr_reader :stock_location, :next_splitter
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
@stock_location = stock_location_or_packer
|
12
|
-
else
|
13
|
-
Spree::Deprecation.warn("Initializing Splitters with a Packer is DEPRECATED. Pass a StockLocation instead.")
|
14
|
-
@stock_location = stock_location_or_packer.stock_location
|
15
|
-
end
|
9
|
+
def initialize(stock_location, next_splitter = nil)
|
10
|
+
@stock_location = stock_location
|
16
11
|
@next_splitter = next_splitter
|
17
12
|
end
|
18
13
|
|
@@ -20,7 +20,7 @@ module Spree
|
|
20
20
|
after_save :conditional_variant_touch, if: :saved_changes?
|
21
21
|
after_touch { variant.touch }
|
22
22
|
|
23
|
-
self.
|
23
|
+
self.allowed_ransackable_attributes = ['count_on_hand', 'stock_location_id']
|
24
24
|
|
25
25
|
# @return [Array<Spree::InventoryUnit>] the backordered inventory units
|
26
26
|
# associated with this stock item
|
@@ -110,13 +110,7 @@ module Spree
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def inventory_cache_threshold
|
113
|
-
|
114
|
-
@cache_threshold ||= if Spree::Config.binary_inventory_cache
|
115
|
-
Spree::Deprecation.warn "Spree::Config.binary_inventory_cache=true is DEPRECATED. Instead use Spree::Config.inventory_cache_threshold=1"
|
116
|
-
1
|
117
|
-
else
|
118
|
-
Spree::Config.inventory_cache_threshold
|
119
|
-
end
|
113
|
+
@cache_threshold ||= Spree::Config.inventory_cache_threshold
|
120
114
|
end
|
121
115
|
end
|
122
116
|
end
|
@@ -26,12 +26,12 @@ module Spree
|
|
26
26
|
validates_uniqueness_of :code, allow_blank: true, case_sensitive: false
|
27
27
|
|
28
28
|
scope :active, -> { where(active: true) }
|
29
|
-
scope :order_default, -> { order(default: :desc,
|
29
|
+
scope :order_default, -> { order(default: :desc, position: :asc) }
|
30
30
|
|
31
31
|
after_create :create_stock_items, if: :propagate_all_variants?
|
32
32
|
after_save :ensure_one_default
|
33
33
|
|
34
|
-
self.
|
34
|
+
self.allowed_ransackable_attributes = %w[name]
|
35
35
|
|
36
36
|
def state_text
|
37
37
|
state.try(:abbr) || state.try(:name) || state_name
|
@@ -13,8 +13,8 @@ module Spree
|
|
13
13
|
|
14
14
|
scope :recent, -> { order(created_at: :desc) }
|
15
15
|
|
16
|
-
self.
|
17
|
-
self.
|
16
|
+
self.allowed_ransackable_associations = %w[variant]
|
17
|
+
self.allowed_ransackable_attributes = ['quantity']
|
18
18
|
|
19
19
|
def readonly?
|
20
20
|
!new_record?
|
data/app/models/spree/store.rb
CHANGED
@@ -25,12 +25,6 @@ module Spree
|
|
25
25
|
before_save :ensure_default_exists_and_is_unique
|
26
26
|
before_destroy :validate_not_default
|
27
27
|
|
28
|
-
scope :by_url, lambda { |url| where("url like ?", "%#{url}%") }
|
29
|
-
|
30
|
-
class << self
|
31
|
-
deprecate by_url: "Spree::Store.by_url is DEPRECATED", deprecator: Spree::Deprecation
|
32
|
-
end
|
33
|
-
|
34
28
|
def available_locales
|
35
29
|
locales = super()
|
36
30
|
if locales
|
@@ -49,12 +43,6 @@ module Spree
|
|
49
43
|
end
|
50
44
|
end
|
51
45
|
|
52
|
-
def self.current(store_key)
|
53
|
-
Spree::Deprecation.warn "Spree::Store.current is DEPRECATED"
|
54
|
-
current_store = Store.find_by(code: store_key) || Store.by_url(store_key).first if store_key
|
55
|
-
current_store || Store.default
|
56
|
-
end
|
57
|
-
|
58
46
|
def self.default
|
59
47
|
where(default: true).first || new
|
60
48
|
end
|
@@ -40,6 +40,14 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
40
40
|
extend Spree::DisplayMoney
|
41
41
|
money_methods :amount, :amount_used, :amount_authorized
|
42
42
|
|
43
|
+
# Sets this store credit's amount to a new value,
|
44
|
+
# parsing it as a localized number if the new value is a string.
|
45
|
+
#
|
46
|
+
# @param number [String, #to_d] a new amount
|
47
|
+
def amount=(number)
|
48
|
+
self[:amount] = Spree::LocalizedNumber.parse(number)
|
49
|
+
end
|
50
|
+
|
43
51
|
def amount_remaining
|
44
52
|
return 0.0.to_d if invalidated?
|
45
53
|
amount - amount_used - amount_authorized
|
@@ -150,7 +158,12 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
150
158
|
end
|
151
159
|
|
152
160
|
def generate_authorization_code
|
153
|
-
|
161
|
+
[
|
162
|
+
id,
|
163
|
+
'SC',
|
164
|
+
Time.current.utc.strftime('%Y%m%d%H%M%S%6N'),
|
165
|
+
SecureRandom.uuid
|
166
|
+
].join('-')
|
154
167
|
end
|
155
168
|
|
156
169
|
def editable?
|
@@ -7,39 +7,7 @@ class Spree::StoreCreditCategory < Spree::Base
|
|
7
7
|
class_attribute :non_expiring_credit_types
|
8
8
|
self.non_expiring_credit_types = [Spree::StoreCreditType::NON_EXPIRING]
|
9
9
|
|
10
|
-
# @deprecated
|
11
|
-
class_attribute :reimbursement_category_name
|
12
|
-
self.reimbursement_category_name = I18n.t('spree.store_credit_category.default')
|
13
|
-
|
14
|
-
# @deprecated
|
15
|
-
def self.reimbursement_category(reimbursement)
|
16
|
-
reimbursement.store_credit_category
|
17
|
-
end
|
18
|
-
|
19
10
|
def non_expiring?
|
20
11
|
self.class.non_expiring_credit_types.include? name
|
21
12
|
end
|
22
|
-
|
23
|
-
public_instance_methods.grep(/^reimbursement_category_name/).each do |method|
|
24
|
-
deprecate(
|
25
|
-
method => 'Use Spree::Reimbursement#store_credit_category.name instead',
|
26
|
-
deprecator: Spree::Deprecation
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
class << self
|
31
|
-
public_instance_methods.grep(/^reimbursement_category_name/).each do |method|
|
32
|
-
deprecate(
|
33
|
-
method => 'Use Spree::Reimbursement.store_credit_category.name instead',
|
34
|
-
deprecator: Spree::Deprecation
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
public_instance_methods.grep(/^reimbursement_category$/).each do |method|
|
39
|
-
deprecate(
|
40
|
-
method => 'Use Spree::Reimbursement.store_credit_category instead',
|
41
|
-
deprecator: Spree::Deprecation
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
13
|
end
|
@@ -5,9 +5,10 @@ module Spree
|
|
5
5
|
# Simple object used to hold tax data for an item.
|
6
6
|
#
|
7
7
|
# This generic object will hold the amount of tax that should be applied to
|
8
|
-
# an item. (Either a {Spree::LineItem} or a {Spree::Shipment}.)
|
8
|
+
# an item. (Either a {Spree::Order}, a {Spree::LineItem} or a {Spree::Shipment}.)
|
9
9
|
#
|
10
|
-
# @attr_reader [Integer] item_id the {Spree::LineItem} or {Spree::Shipment} ID
|
10
|
+
# @attr_reader [Integer] item_id the {Spree::LineItem} or {Spree::Shipment} ID.
|
11
|
+
# Or blank if an order-level tax.
|
11
12
|
# @attr_reader [String] label information about the taxes
|
12
13
|
# @attr_reader [Spree::TaxRate] tax_rate will be used as the source for tax
|
13
14
|
# adjustments
|
@@ -8,13 +8,15 @@ module Spree
|
|
8
8
|
# adjustments on an order.
|
9
9
|
#
|
10
10
|
# @attr_reader [Integer] order_id the {Spree::Order} these taxes apply to
|
11
|
+
# @attr_reader [Array<Spree::Tax::ItemTax>] order_taxes an array of tax
|
12
|
+
# data for the order
|
11
13
|
# @attr_reader [Array<Spree::Tax::ItemTax>] line_item_taxes an array of
|
12
14
|
# tax data for order's line items
|
13
15
|
# @attr_reader [Array<Spree::Tax::ItemTax>] shipment_taxes an array of
|
14
16
|
# tax data for the order's shipments
|
15
17
|
class OrderTax
|
16
18
|
include ActiveModel::Model
|
17
|
-
attr_accessor :order_id, :line_item_taxes, :shipment_taxes
|
19
|
+
attr_accessor :order_id, :order_taxes, :line_item_taxes, :shipment_taxes
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -6,9 +6,9 @@ module Spree
|
|
6
6
|
private
|
7
7
|
|
8
8
|
def rates_for_item(item)
|
9
|
-
@
|
9
|
+
@rates_for_item ||= Spree::TaxRate.item_level.for_address(item.order.tax_address)
|
10
10
|
|
11
|
-
@
|
11
|
+
@rates_for_item.select do |rate|
|
12
12
|
rate.active? && rate.tax_categories.map(&:id).include?(item.tax_category_id)
|
13
13
|
end
|
14
14
|
end
|
@@ -8,7 +8,7 @@ module Spree
|
|
8
8
|
# @attr_reader [Integer] country_id the ID of a Spree::Country object
|
9
9
|
# @attr_reader [Integer] state_id the ID of a Spree::State object
|
10
10
|
class TaxLocation
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :country, :state
|
12
12
|
|
13
13
|
# Create a new TaxLocation object
|
14
14
|
#
|
@@ -19,18 +19,15 @@ module Spree
|
|
19
19
|
#
|
20
20
|
# @return [Spree::Tax::TaxLocation] a Spree::Tax::TaxLocation object
|
21
21
|
def initialize(country: nil, state: nil)
|
22
|
-
@
|
23
|
-
@state_id = state && state.id
|
22
|
+
@country, @state = country, state
|
24
23
|
end
|
24
|
+
delegate :id, to: :state, prefix: true, allow_nil: true
|
25
|
+
delegate :id, to: :country, prefix: true, allow_nil: true
|
25
26
|
|
26
27
|
def ==(other)
|
27
28
|
state_id == other.state_id && country_id == other.country_id
|
28
29
|
end
|
29
30
|
|
30
|
-
def country
|
31
|
-
Spree::Country.find_by(id: country_id)
|
32
|
-
end
|
33
|
-
|
34
31
|
def empty?
|
35
32
|
country_id.nil? && state_id.nil?
|
36
33
|
end
|
@@ -25,6 +25,7 @@ module Spree
|
|
25
25
|
def calculate
|
26
26
|
Spree::Tax::OrderTax.new(
|
27
27
|
order_id: order.id,
|
28
|
+
order_taxes: order_rates,
|
28
29
|
line_item_taxes: line_item_rates,
|
29
30
|
shipment_taxes: shipment_rates
|
30
31
|
)
|
@@ -34,6 +35,23 @@ module Spree
|
|
34
35
|
|
35
36
|
attr_reader :order
|
36
37
|
|
38
|
+
# Calculate the order-level taxes.
|
39
|
+
#
|
40
|
+
# @private
|
41
|
+
# @return [Array<Spree::Tax::ItemTax>] calculated taxes for the order
|
42
|
+
def order_rates
|
43
|
+
rates_for_order.map do |rate|
|
44
|
+
amount = rate.compute_amount(order)
|
45
|
+
|
46
|
+
Spree::Tax::ItemTax.new(
|
47
|
+
label: rate.adjustment_label(amount),
|
48
|
+
tax_rate: rate,
|
49
|
+
amount: amount,
|
50
|
+
included_in_price: rate.included_in_price
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
37
55
|
# Calculate the taxes for line items.
|
38
56
|
#
|
39
57
|
# @private
|
@@ -76,6 +94,19 @@ module Spree
|
|
76
94
|
)
|
77
95
|
end
|
78
96
|
end
|
97
|
+
|
98
|
+
# @private
|
99
|
+
# @return [Array<Spree::TaxRate>] rates that apply to an order
|
100
|
+
def rates_for_order
|
101
|
+
tax_category_ids = Set[
|
102
|
+
*@order.line_items.map(&:tax_category_id),
|
103
|
+
*@order.shipments.map(&:tax_category_id)
|
104
|
+
]
|
105
|
+
rates = Spree::TaxRate.active.order_level.for_address(@order.tax_address)
|
106
|
+
rates.select do |rate|
|
107
|
+
tax_category_ids.intersect?(rate.tax_category_ids.to_set)
|
108
|
+
end
|
109
|
+
end
|
79
110
|
end
|
80
111
|
end
|
81
112
|
end
|
@@ -9,26 +9,16 @@ module Spree
|
|
9
9
|
# looking to provide their own calculator should adhere to the API of this
|
10
10
|
# class.
|
11
11
|
#
|
12
|
-
# @see Spree::
|
12
|
+
# @see Spree::Stock::Estimator
|
13
13
|
class ShippingRate
|
14
14
|
include Spree::Tax::TaxHelpers
|
15
15
|
|
16
|
-
attr_reader :shipping_rate
|
17
|
-
|
18
16
|
# Create a new tax calculator.
|
19
17
|
#
|
20
18
|
# @param [Spree::Order] order the order to calculate taxes on
|
21
19
|
# @return [Spree::TaxCalculator::ShippingRate]
|
22
20
|
def initialize(order)
|
23
|
-
|
24
|
-
Spree::Deprecation.warn "passing a single shipping rate to Spree::TaxCalculator::ShippingRate is DEPRECATED. It now expects an order"
|
25
|
-
shipping_rate = order
|
26
|
-
@order = shipping_rate.order
|
27
|
-
@shipping_rate = shipping_rate
|
28
|
-
else
|
29
|
-
@order = order
|
30
|
-
@shipping_rate = nil
|
31
|
-
end
|
21
|
+
@order = order
|
32
22
|
end
|
33
23
|
|
34
24
|
# Calculate taxes for a shipping rate.
|
@@ -38,7 +28,6 @@ module Spree
|
|
38
28
|
# @return [Array<Spree::Tax::ItemTax>] the calculated taxes for the
|
39
29
|
# shipping rate
|
40
30
|
def calculate(shipping_rate)
|
41
|
-
shipping_rate ||= @shipping_rate
|
42
31
|
rates_for_item(shipping_rate).map do |rate|
|
43
32
|
amount = rate.compute_amount(shipping_rate)
|
44
33
|
|
@@ -11,6 +11,11 @@ module Spree
|
|
11
11
|
include Spree::CalculatedAdjustments
|
12
12
|
include Spree::AdjustmentSource
|
13
13
|
|
14
|
+
enum level: {
|
15
|
+
item: 0,
|
16
|
+
order: 1
|
17
|
+
}, _suffix: true
|
18
|
+
|
14
19
|
belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates, optional: true
|
15
20
|
|
16
21
|
has_many :tax_rate_tax_categories,
|
@@ -27,6 +32,8 @@ module Spree
|
|
27
32
|
|
28
33
|
validates :amount, presence: true, numericality: true
|
29
34
|
|
35
|
+
self.allowed_ransackable_associations = %w[tax_categories zone]
|
36
|
+
|
30
37
|
# Finds all tax rates whose zones match a given address
|
31
38
|
scope :for_address, ->(address) { joins(:zone).merge(Spree::Zone.for_address(address)) }
|
32
39
|
scope :for_country,
|
@@ -87,23 +94,6 @@ module Spree
|
|
87
94
|
end
|
88
95
|
scope :included_in_price, -> { where(included_in_price: true) }
|
89
96
|
|
90
|
-
# Creates necessary tax adjustments for the order.
|
91
|
-
#
|
92
|
-
# @deprecated Please use `Spree::Tax::OrderAdjuster#adjust!` instead
|
93
|
-
def adjust(_order_tax_zone, item)
|
94
|
-
Spree::Deprecation.warn("`Spree::TaxRate#adjust` is deprecated. Please use `Spree::Tax::OrderAdjuster#adjust!` instead.", caller)
|
95
|
-
|
96
|
-
amount = compute_amount(item)
|
97
|
-
|
98
|
-
item.adjustments.create!(
|
99
|
-
source: self,
|
100
|
-
amount: amount,
|
101
|
-
order_id: item.order_id,
|
102
|
-
label: adjustment_label(amount),
|
103
|
-
included: included_in_price
|
104
|
-
)
|
105
|
-
end
|
106
|
-
|
107
97
|
# This method is used by Adjustment#update to recalculate the cost.
|
108
98
|
def compute_amount(item)
|
109
99
|
calculator.compute(item)
|
@@ -123,16 +113,6 @@ module Spree
|
|
123
113
|
)
|
124
114
|
end
|
125
115
|
|
126
|
-
def tax_category=(category)
|
127
|
-
self.tax_categories = [category]
|
128
|
-
end
|
129
|
-
|
130
|
-
def tax_category
|
131
|
-
tax_categories[0]
|
132
|
-
end
|
133
|
-
|
134
|
-
deprecate :tax_category => :tax_categories, :tax_category= => :tax_categories=, deprecator: Spree::Deprecation
|
135
|
-
|
136
116
|
private
|
137
117
|
|
138
118
|
def amount_for_adjustment_label
|
@@ -143,6 +123,8 @@ module Spree
|
|
143
123
|
end
|
144
124
|
|
145
125
|
def translation_key(_amount)
|
126
|
+
return "flat_fee" if calculator.is_a?(Spree::Calculator::FlatFee)
|
127
|
+
|
146
128
|
key = included_in_price? ? "vat" : "sales_tax"
|
147
129
|
key += "_with_rate" if show_rate_in_label?
|
148
130
|
key.to_sym
|
@@ -6,13 +6,8 @@ module Spree::Taxon::ActiveStorageAttachment
|
|
6
6
|
|
7
7
|
included do
|
8
8
|
has_attachment :icon,
|
9
|
-
styles:
|
10
|
-
default_style:
|
9
|
+
styles: Spree::Config.taxon_image_styles,
|
10
|
+
default_style: Spree::Config.taxon_image_style_default
|
11
11
|
validate :icon_is_an_image
|
12
12
|
end
|
13
|
-
|
14
|
-
def attachment_partial_name
|
15
|
-
Spree::Deprecation.warn("calling #attachment_partial_name on Spree::Taxon is deprecated without replacement.")
|
16
|
-
'paperclip'
|
17
|
-
end
|
18
13
|
end
|
@@ -5,25 +5,20 @@ module Spree::Taxon::PaperclipAttachment
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
has_attached_file :icon,
|
8
|
-
styles:
|
9
|
-
default_style:
|
8
|
+
styles: Spree::Config.taxon_image_styles,
|
9
|
+
default_style: Spree::Config.taxon_image_style_default,
|
10
10
|
url: '/spree/taxons/:id/:style/:basename.:extension',
|
11
11
|
path: ':rails_root/public/spree/taxons/:id/:style/:basename.:extension',
|
12
12
|
default_url: '/assets/default_taxon.png'
|
13
13
|
|
14
14
|
validates_attachment :icon,
|
15
|
-
content_type: { content_type:
|
15
|
+
content_type: { content_type: Spree::Config.allowed_image_mime_types }
|
16
16
|
end
|
17
17
|
|
18
18
|
def icon_present?
|
19
19
|
icon.present?
|
20
20
|
end
|
21
21
|
|
22
|
-
def attachment_partial_name
|
23
|
-
Spree::Deprecation.warn("calling #attachment_partial_name on Spree::Taxon is deprecated without replacement.")
|
24
|
-
'paperclip'
|
25
|
-
end
|
26
|
-
|
27
22
|
def destroy_attachment(definition)
|
28
23
|
return false unless respond_to?(definition)
|
29
24
|
|
data/app/models/spree/taxon.rb
CHANGED
@@ -27,18 +27,7 @@ module Spree
|
|
27
27
|
|
28
28
|
include ::Spree::Config.taxon_attachment_module
|
29
29
|
|
30
|
-
self.
|
31
|
-
|
32
|
-
# @note This method is meant to be overridden on a store by store basis.
|
33
|
-
# @return [Array] filters that should be used for a taxon
|
34
|
-
def applicable_filters
|
35
|
-
Spree::Deprecation.warn "Spree::Taxon#applicable_filters is deprecated, if you are using this functionality please move it into your own application."
|
36
|
-
|
37
|
-
fs = []
|
38
|
-
fs << Spree::Core::ProductFilters.price_filter if Spree::Core::ProductFilters.respond_to?(:price_filter)
|
39
|
-
fs << Spree::Core::ProductFilters.brand_filter if Spree::Core::ProductFilters.respond_to?(:brand_filter)
|
40
|
-
fs
|
41
|
-
end
|
30
|
+
self.allowed_ransackable_attributes = %w[name]
|
42
31
|
|
43
32
|
# @return [String] meta_title if set otherwise a string containing the
|
44
33
|
# root name and taxon name
|
@@ -19,11 +19,6 @@ module Spree
|
|
19
19
|
scope :default_billing, -> { where(default_billing: true) }
|
20
20
|
scope :active, -> { where(archived: false) }
|
21
21
|
|
22
|
-
scope :default, -> do
|
23
|
-
Spree::Deprecation.warn "This scope is deprecated. Please start using ::default_shipping."
|
24
|
-
default_shipping
|
25
|
-
end
|
26
|
-
|
27
22
|
default_scope -> { order([default: :desc, updated_at: :desc]) }
|
28
23
|
end
|
29
24
|
end
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
class UserLastUrlStorer
|
5
5
|
module Rules
|
6
6
|
# This is the basic rule that ships with Solidus that avoids storing in
|
7
|
-
# session the current path for login/
|
7
|
+
# session the current path for login/logout/signup routes, avoiding possibly
|
8
8
|
# infinte redirects.
|
9
9
|
module AuthenticationRule
|
10
10
|
AUTHENTICATION_ROUTES = %w[spree_signup_path spree_login_path spree_logout_path]
|