solidus_core 4.3.4 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/spree/base_helper.rb +2 -2
- data/app/mailers/spree/base_mailer.rb +1 -1
- data/app/mailers/spree/carton_mailer.rb +1 -1
- data/app/mailers/spree/order_mailer.rb +3 -3
- data/app/mailers/spree/reimbursement_mailer.rb +1 -1
- data/app/models/concerns/spree/active_storage_adapter/normalization.rb +1 -1
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- data/app/models/concerns/spree/display_money.rb +1 -1
- data/app/models/concerns/spree/ordered_property_value_list.rb +2 -2
- data/app/models/concerns/spree/user_address_book.rb +4 -4
- data/app/models/concerns/spree/user_methods.rb +3 -3
- data/app/models/spree/address.rb +6 -6
- data/app/models/spree/adjustment.rb +13 -66
- data/app/models/spree/calculator/returns/default_refund_amount.rb +1 -1
- data/app/models/spree/carton.rb +2 -2
- data/app/models/spree/credit_card.rb +6 -6
- data/app/models/spree/deprecated_configurable_class.rb +40 -0
- data/app/models/spree/fulfilment_changer.rb +4 -4
- data/app/models/spree/inventory_unit.rb +2 -2
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/null_promotion_adjuster.rb +13 -0
- data/app/models/spree/null_promotion_advertiser.rb +9 -0
- data/app/models/spree/null_promotion_finder.rb +9 -0
- data/app/models/spree/null_promotion_handler.rb +44 -0
- data/app/models/spree/order.rb +15 -22
- data/app/models/spree/order_cancellations.rb +8 -8
- data/app/models/spree/order_mutex.rb +2 -2
- data/app/models/spree/order_shipping.rb +9 -9
- data/app/models/spree/order_updater.rb +6 -10
- data/app/models/spree/payment/processing.rb +2 -2
- data/app/models/spree/payment.rb +2 -2
- data/app/models/spree/payment_create.rb +1 -1
- data/app/models/spree/payment_method/store_credit.rb +1 -1
- data/app/models/spree/payment_source.rb +5 -1
- data/app/models/spree/permission_set.rb +11 -0
- data/app/models/spree/product.rb +7 -28
- data/app/models/spree/refund.rb +1 -1
- data/app/models/spree/reimbursement.rb +4 -4
- data/app/models/spree/reimbursement_performer.rb +3 -3
- data/app/models/spree/reimbursement_tax_calculator.rb +2 -2
- data/app/models/spree/reimbursement_type/credit.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +6 -6
- data/app/models/spree/reimbursement_type/store_credit.rb +1 -1
- data/app/models/spree/return_item.rb +9 -9
- data/app/models/spree/role.rb +3 -1
- data/app/models/spree/role_permission.rb +8 -0
- data/app/models/spree/shipment.rb +7 -7
- data/app/models/spree/shipping_category.rb +2 -0
- data/app/models/spree/shipping_rate.rb +1 -1
- data/app/models/spree/{order_contents.rb → simple_order_contents.rb} +4 -11
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock/inventory_unit_builder.rb +1 -1
- data/app/models/spree/stock/package.rb +2 -2
- data/app/models/spree/stock/simple_coordinator.rb +1 -1
- data/app/models/spree/stock_location.rb +5 -5
- data/app/models/spree/store.rb +1 -1
- data/app/models/spree/store_credit.rb +17 -15
- data/app/models/spree/store_credit_event.rb +3 -3
- data/app/models/spree/tax_calculator/default.rb +2 -2
- data/app/models/spree/tax_calculator/shipping_rate.rb +1 -1
- data/app/models/spree/tax_category.rb +3 -1
- data/app/models/spree/tax_rate.rb +3 -3
- data/app/models/spree/taxonomy.rb +2 -2
- data/app/models/spree/unit_cancel.rb +1 -2
- data/app/models/spree/variant/vat_price_generator.rb +1 -1
- data/app/models/spree/variant.rb +7 -2
- data/app/models/spree/wallet.rb +2 -2
- data/app/views/spree/order_mailer/cancel_email.html.erb +1 -1
- data/app/views/spree/order_mailer/cancel_email.text.erb +1 -1
- data/app/views/spree/order_mailer/confirm_email.html.erb +5 -5
- data/app/views/spree/order_mailer/confirm_email.text.erb +5 -5
- data/config/locales/en.yml +4 -90
- data/db/default/spree/permission_sets.rb +10 -0
- data/db/default/spree/return_reasons.rb +3 -1
- data/db/default/spree/states.rb +1 -1
- data/db/migrate/20160101010000_solidus_one_four.rb +0 -117
- data/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb +9 -0
- data/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb +9 -0
- data/db/migrate/20240821173641_add_description_to_spree_roles.rb +5 -0
- data/db/migrate/20240904152041_add_privilege_and_category_to_spree_permission_sets.rb +6 -0
- data/db/seeds.rb +1 -0
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
- data/lib/generators/solidus/update/update_generator.rb +1 -1
- data/lib/generators/spree/dummy/templates/rails/test.rb +6 -1
- data/lib/spree/app_configuration.rb +53 -84
- data/lib/spree/core/class_constantizer.rb +2 -2
- data/lib/spree/core/controller_helpers/payment_parameters.rb +1 -1
- data/lib/spree/core/engine.rb +1 -0
- data/lib/spree/core/environment/calculators.rb +35 -3
- data/lib/spree/core/environment/promotions.rb +25 -4
- data/lib/spree/core/environment_extension.rb +16 -2
- data/lib/spree/core/importer/order.rb +5 -5
- data/lib/spree/core/importer/product.rb +3 -3
- data/lib/spree/core/nested_class_set.rb +28 -0
- data/lib/spree/core/null_promotion_configuration.rb +84 -0
- data/lib/spree/core/product_filters.rb +1 -1
- data/lib/spree/core/search/variant.rb +2 -2
- data/lib/spree/core/state_machines/order.rb +0 -1
- data/lib/spree/core/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +2 -2
- data/lib/spree/core.rb +2 -6
- data/lib/spree/deprecator.rb +9 -0
- data/lib/spree/i18n.rb +1 -1
- data/lib/spree/mailer_previews/carton_preview.rb +1 -1
- data/lib/spree/permission_sets/base.rb +13 -1
- data/lib/spree/permission_sets/configuration_display.rb +10 -0
- data/lib/spree/permission_sets/configuration_management.rb +10 -0
- data/lib/spree/permission_sets/dashboard_display.rb +12 -0
- data/lib/spree/permission_sets/default_customer.rb +11 -1
- data/lib/spree/permission_sets/order_display.rb +10 -0
- data/lib/spree/permission_sets/order_management.rb +10 -0
- data/lib/spree/permission_sets/product_display.rb +10 -0
- data/lib/spree/permission_sets/product_management.rb +10 -0
- data/lib/spree/permission_sets/restricted_stock_display.rb +10 -0
- data/lib/spree/permission_sets/restricted_stock_management.rb +10 -0
- data/lib/spree/permission_sets/stock_display.rb +10 -0
- data/lib/spree/permission_sets/stock_management.rb +10 -0
- data/lib/spree/permission_sets/super_user.rb +10 -0
- data/lib/spree/permission_sets/user_display.rb +10 -0
- data/lib/spree/permission_sets/user_management.rb +10 -0
- data/lib/spree/permission_sets.rb +0 -2
- data/lib/spree/permitted_attributes.rb +2 -2
- data/lib/spree/preferences/store.rb +2 -2
- data/lib/spree/testing_support/capybara_ext.rb +1 -1
- data/lib/spree/testing_support/dummy_ability.rb +7 -0
- data/lib/spree/testing_support/dummy_app/database.yml +2 -2
- data/lib/spree/testing_support/dummy_app/migrations.rb +8 -15
- data/lib/spree/testing_support/dummy_app/rake_tasks.rb +2 -2
- data/lib/spree/testing_support/dummy_app.rb +17 -12
- data/lib/spree/testing_support/factories/adjustment_factory.rb +1 -2
- data/lib/spree/testing_support/factories/calculator_factory.rb +1 -5
- data/lib/spree/testing_support/factories/carton_factory.rb +2 -2
- data/lib/spree/testing_support/factories/customer_return_factory.rb +2 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +3 -3
- data/lib/spree/testing_support/factories/order_factory.rb +5 -24
- data/lib/spree/testing_support/factories/product_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_item_factory.rb +5 -1
- data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +1 -1
- data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +3 -3
- data/lib/spree/testing_support/shared_examples/calculator.rb +10 -0
- data/lib/spree/testing_support/shared_examples/order_factory.rb +141 -0
- data/lib/spree/testing_support/shared_examples/working_factory.rb +15 -0
- data/lib/tasks/colorado_delivery_fee.rake +2 -2
- data/solidus_core.gemspec +6 -6
- metadata +60 -91
- data/app/jobs/spree/promotion_code_batch_job.rb +0 -26
- data/app/mailers/spree/promotion_code_batch_mailer.rb +0 -15
- data/app/models/spree/calculator/distributed_amount.rb +0 -33
- data/app/models/spree/calculator/flat_percent_item_total.rb +0 -23
- data/app/models/spree/calculator/flexi_rate.rb +0 -22
- data/app/models/spree/calculator/percent_on_line_item.rb +0 -13
- data/app/models/spree/calculator/tiered_flat_rate.rb +0 -52
- data/app/models/spree/calculator/tiered_percent.rb +0 -62
- data/app/models/spree/order_promotion.rb +0 -27
- data/app/models/spree/promotion/actions/create_adjustment.rb +0 -81
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -98
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -139
- data/app/models/spree/promotion/actions/free_shipping.rb +0 -59
- data/app/models/spree/promotion/order_adjustments_recalculator.rb +0 -92
- data/app/models/spree/promotion/rules/first_order.rb +0 -38
- data/app/models/spree/promotion/rules/first_repeat_purchase_since.rb +0 -36
- data/app/models/spree/promotion/rules/item_total.rb +0 -86
- data/app/models/spree/promotion/rules/minimum_quantity.rb +0 -59
- data/app/models/spree/promotion/rules/nth_order.rb +0 -45
- data/app/models/spree/promotion/rules/one_use_per_user.rb +0 -25
- data/app/models/spree/promotion/rules/option_value.rb +0 -50
- data/app/models/spree/promotion/rules/product.rb +0 -86
- data/app/models/spree/promotion/rules/store.rb +0 -26
- data/app/models/spree/promotion/rules/taxon.rb +0 -91
- data/app/models/spree/promotion/rules/user.rb +0 -34
- data/app/models/spree/promotion/rules/user_logged_in.rb +0 -20
- data/app/models/spree/promotion/rules/user_role.rb +0 -45
- data/app/models/spree/promotion.rb +0 -271
- data/app/models/spree/promotion_action.rb +0 -47
- data/app/models/spree/promotion_category.rb +0 -8
- data/app/models/spree/promotion_chooser.rb +0 -34
- data/app/models/spree/promotion_code/batch_builder.rb +0 -64
- data/app/models/spree/promotion_code.rb +0 -54
- data/app/models/spree/promotion_code_batch.rb +0 -27
- data/app/models/spree/promotion_handler/cart.rb +0 -75
- data/app/models/spree/promotion_handler/coupon.rb +0 -123
- data/app/models/spree/promotion_handler/page.rb +0 -26
- data/app/models/spree/promotion_handler/shipping.rb +0 -61
- data/app/models/spree/promotion_rule.rb +0 -55
- data/app/models/spree/promotion_rule_store.rb +0 -10
- data/app/models/spree/promotion_rule_taxon.rb +0 -8
- data/app/models/spree/promotion_rule_user.rb +0 -10
- data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +0 -2
- data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +0 -2
- data/db/migrate/20161017102621_create_spree_promotion_code_batch.rb +0 -38
- data/db/migrate/20180202190713_create_promotion_rule_stores.rb +0 -12
- data/db/migrate/20180328172631_add_join_characters_to_promotion_code_batch.rb +0 -11
- data/db/migrate/20190106184413_remove_code_from_spree_promotions.rb +0 -42
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +0 -20
- data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +0 -5
- data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +0 -6
- data/db/migrate/20230325161633_drop_unused_promo_action_line_items.rb +0 -13
- data/db/migrate/20231027084517_add_order_promotions_foreign_key.rb +0 -10
- data/db/migrate/20231031175215_add_promotion_order_promotion_foreign_key.rb +0 -10
- data/lib/solidus/migrations/promotions_with_code_handlers.rb +0 -66
- data/lib/spree/permission_sets/promotion_display.rb +0 -25
- data/lib/spree/permission_sets/promotion_management.rb +0 -25
- data/lib/spree/ransack_4_1_patch.rb +0 -16
- data/lib/spree/testing_support/factories/order_promotion_factory.rb +0 -8
- data/lib/spree/testing_support/factories/promotion_category_factory.rb +0 -7
- data/lib/spree/testing_support/factories/promotion_code_factory.rb +0 -8
- data/lib/spree/testing_support/factories/promotion_factory.rb +0 -98
data/app/models/spree/role.rb
CHANGED
@@ -4,8 +4,10 @@ module Spree
|
|
4
4
|
class Role < Spree::Base
|
5
5
|
has_many :role_users, class_name: "Spree::RoleUser", dependent: :destroy
|
6
6
|
has_many :users, through: :role_users
|
7
|
+
has_many :role_permissions, dependent: :destroy
|
8
|
+
has_many :permission_sets, through: :role_permissions
|
7
9
|
|
8
|
-
|
10
|
+
validates :name, presence: true, uniqueness: { case_sensitive: true, allow_blank: true }
|
9
11
|
|
10
12
|
def admin?
|
11
13
|
name == "admin"
|
@@ -31,7 +31,7 @@ module Spree
|
|
31
31
|
scope :ready, -> { with_state('ready') }
|
32
32
|
scope :shipped, -> { with_state('shipped') }
|
33
33
|
scope :trackable, -> { where("tracking IS NOT NULL AND tracking != ''") }
|
34
|
-
scope :with_state, ->(*state) { where(state:
|
34
|
+
scope :with_state, ->(*state) { where(state:) }
|
35
35
|
# sort by most recent shipped_at, falling back to created_at. add "id desc" to make specs that involve this scope more deterministic.
|
36
36
|
scope :reverse_chronological, -> {
|
37
37
|
order(Arel.sql("coalesce(#{Spree::Shipment.table_name}.shipped_at, #{Spree::Shipment.table_name}.created_at) desc"), id: :desc)
|
@@ -92,7 +92,7 @@ module Spree
|
|
92
92
|
# @return [BigDecimal] the amount of this item, taking into consideration
|
93
93
|
# all non-tax adjustments.
|
94
94
|
def total_before_tax
|
95
|
-
amount + adjustments.
|
95
|
+
amount + adjustments.reject(&:tax?).sum(&:amount)
|
96
96
|
end
|
97
97
|
|
98
98
|
# @return [BigDecimal] the amount of this shipment before VAT tax
|
@@ -175,7 +175,7 @@ module Spree
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def manifest
|
178
|
-
@manifest ||= Spree::ShippingManifest.new(inventory_units:
|
178
|
+
@manifest ||= Spree::ShippingManifest.new(inventory_units:).items
|
179
179
|
end
|
180
180
|
|
181
181
|
def selected_shipping_rate_id
|
@@ -217,7 +217,7 @@ module Spree
|
|
217
217
|
|
218
218
|
def set_up_inventory(state, variant, _order, line_item)
|
219
219
|
inventory_units.create(
|
220
|
-
state
|
220
|
+
state:,
|
221
221
|
variant_id: variant.id,
|
222
222
|
line_item_id: line_item.id
|
223
223
|
)
|
@@ -263,7 +263,7 @@ module Spree
|
|
263
263
|
self.cost = selected_shipping_rate.cost
|
264
264
|
if changed?
|
265
265
|
update_columns(
|
266
|
-
cost
|
266
|
+
cost:,
|
267
267
|
updated_at: Time.current
|
268
268
|
)
|
269
269
|
end
|
@@ -312,7 +312,7 @@ module Spree
|
|
312
312
|
end
|
313
313
|
|
314
314
|
def after_ship
|
315
|
-
order.shipping.ship_shipment(self, suppress_mailer:
|
315
|
+
order.shipping.ship_shipment(self, suppress_mailer:)
|
316
316
|
end
|
317
317
|
|
318
318
|
def can_get_rates?
|
@@ -339,7 +339,7 @@ module Spree
|
|
339
339
|
|
340
340
|
def ensure_can_destroy
|
341
341
|
if shipped? || canceled?
|
342
|
-
errors.add(:state, :cannot_destroy, state:
|
342
|
+
errors.add(:state, :cannot_destroy, state:)
|
343
343
|
throw :abort
|
344
344
|
end
|
345
345
|
end
|
@@ -31,7 +31,7 @@ module Spree
|
|
31
31
|
tax_explanations = taxes.map(&:label).join(tax_label_separator)
|
32
32
|
|
33
33
|
I18n.t 'spree.shipping_rate.display_price.display_price_with_explanations',
|
34
|
-
price
|
34
|
+
price:,
|
35
35
|
explanations: tax_explanations
|
36
36
|
end
|
37
37
|
alias_method :display_cost, :display_price
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
class
|
4
|
+
class SimpleOrderContents
|
5
5
|
attr_accessor :order
|
6
6
|
|
7
7
|
def initialize(order)
|
@@ -38,12 +38,7 @@ module Spree
|
|
38
38
|
if order.update(params)
|
39
39
|
unless order.completed?
|
40
40
|
order.line_items = order.line_items.select { |li| li.quantity > 0 }
|
41
|
-
# Update totals, then check if the order is eligible for any cart promotions.
|
42
|
-
# If we do not update first, then the item total will be wrong and ItemTotal
|
43
|
-
# promotion rules would not be triggered.
|
44
|
-
reload_totals
|
45
41
|
order.check_shipments_and_restart_checkout
|
46
|
-
PromotionHandler::Cart.new(order).activate
|
47
42
|
end
|
48
43
|
reload_totals
|
49
44
|
true
|
@@ -71,10 +66,8 @@ module Spree
|
|
71
66
|
private
|
72
67
|
|
73
68
|
def after_add_or_remove(line_item, options = {})
|
74
|
-
reload_totals
|
75
69
|
shipment = options[:shipment]
|
76
70
|
shipment.present? ? shipment.update_amounts : order.check_shipments_and_restart_checkout
|
77
|
-
PromotionHandler::Cart.new(order, line_item).activate
|
78
71
|
reload_totals
|
79
72
|
line_item
|
80
73
|
end
|
@@ -88,8 +81,8 @@ module Spree
|
|
88
81
|
|
89
82
|
line_item ||= order.line_items.new(
|
90
83
|
quantity: 0,
|
91
|
-
variant
|
92
|
-
adjustments: []
|
84
|
+
variant:,
|
85
|
+
adjustments: []
|
93
86
|
)
|
94
87
|
|
95
88
|
line_item.quantity += quantity.to_i
|
@@ -117,7 +110,7 @@ module Spree
|
|
117
110
|
def grab_line_item_by_variant(variant, raise_error = false, options = {})
|
118
111
|
line_item = order.find_line_item_by_variant(variant, options)
|
119
112
|
|
120
|
-
if
|
113
|
+
if line_item.blank? && raise_error
|
121
114
|
raise ActiveRecord::RecordNotFound, "Line item not found for variant #{variant.sku}"
|
122
115
|
end
|
123
116
|
|
@@ -124,8 +124,8 @@ module Spree
|
|
124
124
|
contents.each { |content_item| content_item.inventory_unit.state = content_item.state.to_s }
|
125
125
|
|
126
126
|
Spree::Shipment.new(
|
127
|
-
order
|
128
|
-
stock_location
|
127
|
+
order:,
|
128
|
+
stock_location:,
|
129
129
|
inventory_units: contents.map(&:inventory_unit)
|
130
130
|
)
|
131
131
|
end
|
@@ -41,7 +41,7 @@ module Spree
|
|
41
41
|
@desired = Spree::StockQuantities.new(inventory_units_by_variant.transform_values(&:count))
|
42
42
|
@availability = Spree::Stock::Availability.new(
|
43
43
|
variants: desired.variants,
|
44
|
-
stock_locations:
|
44
|
+
stock_locations:
|
45
45
|
)
|
46
46
|
|
47
47
|
@allocator = Spree::Config.stock.allocator_class.new(availability)
|
@@ -39,7 +39,7 @@ module Spree
|
|
39
39
|
|
40
40
|
# Wrapper for creating a new stock item respecting the backorderable config
|
41
41
|
def propagate_variant(variant)
|
42
|
-
stock_items.create!(variant
|
42
|
+
stock_items.create!(variant:, backorderable: backorderable_default)
|
43
43
|
end
|
44
44
|
|
45
45
|
# Return either an existing stock item or create a new one. Useful in
|
@@ -55,7 +55,7 @@ module Spree
|
|
55
55
|
#
|
56
56
|
# @return [StockItem] Corresponding StockItem for the StockLocation's variant.
|
57
57
|
def stock_item(variant_id)
|
58
|
-
stock_items.where(variant_id:
|
58
|
+
stock_items.where(variant_id:).order(:id).first
|
59
59
|
end
|
60
60
|
|
61
61
|
# Attempts to look up StockItem for the variant, and creates one if not found.
|
@@ -101,8 +101,8 @@ module Spree
|
|
101
101
|
if quantity < 1 && !stock_item(variant)
|
102
102
|
raise InvalidMovementError.new(I18n.t('spree.negative_movement_absent_item'))
|
103
103
|
end
|
104
|
-
stock_item_or_create(variant).stock_movements.create!(quantity
|
105
|
-
originator:
|
104
|
+
stock_item_or_create(variant).stock_movements.create!(quantity:,
|
105
|
+
originator:)
|
106
106
|
end
|
107
107
|
|
108
108
|
def fill_status(variant, quantity)
|
@@ -121,7 +121,7 @@ module Spree
|
|
121
121
|
|
122
122
|
def ensure_one_default
|
123
123
|
if default
|
124
|
-
Spree::StockLocation.where(default: true).where.not(id:
|
124
|
+
Spree::StockLocation.where(default: true).where.not(id:).find_each do |stock_location|
|
125
125
|
stock_location.default = false
|
126
126
|
stock_location.save!
|
127
127
|
end
|
data/app/models/spree/store.rb
CHANGED
@@ -58,7 +58,7 @@ module Spree
|
|
58
58
|
|
59
59
|
def ensure_default_exists_and_is_unique
|
60
60
|
if default
|
61
|
-
Spree::Store.where.not(id:
|
61
|
+
Spree::Store.where.not(id:).update_all(default: false)
|
62
62
|
elsif Spree::Store.where(default: true).count == 0
|
63
63
|
self.default = true
|
64
64
|
end
|
@@ -40,6 +40,8 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
40
40
|
extend Spree::DisplayMoney
|
41
41
|
money_methods :amount, :amount_used, :amount_authorized
|
42
42
|
|
43
|
+
alias_method :display_number, :category_name
|
44
|
+
|
43
45
|
# Sets this store credit's amount to a new value,
|
44
46
|
# parsing it as a localized number if the new value is a string.
|
45
47
|
#
|
@@ -56,7 +58,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
56
58
|
def authorize(amount, order_currency, options = {})
|
57
59
|
authorization_code = options[:action_authorization_code]
|
58
60
|
if authorization_code
|
59
|
-
if store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:
|
61
|
+
if store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:)
|
60
62
|
# Don't authorize again on capture
|
61
63
|
return true
|
62
64
|
end
|
@@ -90,7 +92,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
90
92
|
|
91
93
|
def capture(amount, authorization_code, order_currency, options = {})
|
92
94
|
return false unless authorize(amount, order_currency, action_authorization_code: authorization_code)
|
93
|
-
auth_event = store_credit_events.find_by!(action: AUTHORIZE_ACTION, authorization_code:
|
95
|
+
auth_event = store_credit_events.find_by!(action: AUTHORIZE_ACTION, authorization_code:)
|
94
96
|
|
95
97
|
if amount <= auth_event.amount
|
96
98
|
if currency != order_currency
|
@@ -115,7 +117,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
115
117
|
end
|
116
118
|
|
117
119
|
def void(authorization_code, options = {})
|
118
|
-
if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:
|
120
|
+
if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:)
|
119
121
|
update!({
|
120
122
|
action: VOID_ACTION,
|
121
123
|
action_amount: auth_event.amount,
|
@@ -133,7 +135,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
133
135
|
|
134
136
|
def credit(amount, authorization_code, order_currency, options = {})
|
135
137
|
# Find the amount related to this authorization_code in order to add the store credit back
|
136
|
-
capture_event = store_credit_events.find_by(action: CAPTURE_ACTION, authorization_code:
|
138
|
+
capture_event = store_credit_events.find_by(action: CAPTURE_ACTION, authorization_code:)
|
137
139
|
|
138
140
|
if currency != order_currency # sanity check to make sure the order currency hasn't changed since the auth
|
139
141
|
errors.add(:base, I18n.t('spree.store_credit.currency_mismatch'))
|
@@ -219,25 +221,25 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
219
221
|
|
220
222
|
def create_credit_record_params(amount)
|
221
223
|
{
|
222
|
-
amount
|
223
|
-
user_id
|
224
|
-
category_id
|
225
|
-
created_by_id
|
226
|
-
currency
|
227
|
-
type_id
|
224
|
+
amount:,
|
225
|
+
user_id:,
|
226
|
+
category_id:,
|
227
|
+
created_by_id:,
|
228
|
+
currency:,
|
229
|
+
type_id:,
|
228
230
|
memo: credit_allocation_memo
|
229
231
|
}
|
230
232
|
end
|
231
233
|
|
232
234
|
def credit_allocation_memo
|
233
|
-
I18n.t("spree.store_credit.credit_allocation_memo", id:
|
235
|
+
I18n.t("spree.store_credit.credit_allocation_memo", id:)
|
234
236
|
end
|
235
237
|
|
236
238
|
def store_event
|
237
239
|
return unless saved_change_to_amount? || saved_change_to_amount_used? || saved_change_to_amount_authorized? || [ELIGIBLE_ACTION, INVALIDATE_ACTION].include?(action)
|
238
240
|
|
239
241
|
event = if action
|
240
|
-
store_credit_events.build(action:
|
242
|
+
store_credit_events.build(action:)
|
241
243
|
else
|
242
244
|
store_credit_events.where(action: ALLOCATION_ACTION).first_or_initialize
|
243
245
|
end
|
@@ -245,10 +247,10 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
245
247
|
event.update!({
|
246
248
|
amount: action_amount || amount,
|
247
249
|
authorization_code: action_authorization_code || event.authorization_code || generate_authorization_code,
|
248
|
-
amount_remaining
|
249
|
-
user_total_amount: user.available_store_credit_total(currency:
|
250
|
+
amount_remaining:,
|
251
|
+
user_total_amount: user.available_store_credit_total(currency:),
|
250
252
|
originator: action_originator,
|
251
|
-
store_credit_reason:
|
253
|
+
store_credit_reason:
|
252
254
|
})
|
253
255
|
end
|
254
256
|
|
@@ -33,15 +33,15 @@ module Spree
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def display_amount
|
36
|
-
Spree::Money.new(amount, { currency:
|
36
|
+
Spree::Money.new(amount, { currency: })
|
37
37
|
end
|
38
38
|
|
39
39
|
def display_user_total_amount
|
40
|
-
Spree::Money.new(user_total_amount, { currency:
|
40
|
+
Spree::Money.new(user_total_amount, { currency: })
|
41
41
|
end
|
42
42
|
|
43
43
|
def display_remaining_amount
|
44
|
-
Spree::Money.new(amount_remaining, { currency:
|
44
|
+
Spree::Money.new(amount_remaining, { currency: })
|
45
45
|
end
|
46
46
|
|
47
47
|
def display_event_date
|
@@ -46,7 +46,7 @@ module Spree
|
|
46
46
|
Spree::Tax::ItemTax.new(
|
47
47
|
label: rate.adjustment_label(amount),
|
48
48
|
tax_rate: rate,
|
49
|
-
amount
|
49
|
+
amount:,
|
50
50
|
included_in_price: rate.included_in_price
|
51
51
|
)
|
52
52
|
end
|
@@ -89,7 +89,7 @@ module Spree
|
|
89
89
|
item_id: item.id,
|
90
90
|
label: rate.adjustment_label(amount),
|
91
91
|
tax_rate: rate,
|
92
|
-
amount
|
92
|
+
amount:,
|
93
93
|
included_in_price: rate.included_in_price
|
94
94
|
)
|
95
95
|
end
|
@@ -4,6 +4,8 @@ module Spree
|
|
4
4
|
class TaxCategory < Spree::Base
|
5
5
|
include Spree::SoftDeletable
|
6
6
|
|
7
|
+
self.allowed_ransackable_attributes = %w[name description]
|
8
|
+
|
7
9
|
after_discard do
|
8
10
|
self.tax_rate_tax_categories = []
|
9
11
|
end
|
@@ -28,7 +30,7 @@ module Spree
|
|
28
30
|
|
29
31
|
def ensure_one_default
|
30
32
|
if is_default
|
31
|
-
Spree::TaxCategory.where(is_default: true).where.not(id:
|
33
|
+
Spree::TaxCategory.where(is_default: true).where.not(id:).update_all(is_default: false, updated_at: Time.current)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -11,10 +11,10 @@ module Spree
|
|
11
11
|
include Spree::CalculatedAdjustments
|
12
12
|
include Spree::AdjustmentSource
|
13
13
|
|
14
|
-
enum level
|
14
|
+
enum :level, {
|
15
15
|
item: 0,
|
16
16
|
order: 1
|
17
|
-
},
|
17
|
+
}, suffix: true
|
18
18
|
|
19
19
|
belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates, optional: true
|
20
20
|
|
@@ -37,7 +37,7 @@ module Spree
|
|
37
37
|
# Finds all tax rates whose zones match a given address
|
38
38
|
scope :for_address, ->(address) { joins(:zone).merge(Spree::Zone.for_address(address)) }
|
39
39
|
scope :for_country,
|
40
|
-
->(country) { for_address(Spree::Tax::TaxLocation.new(country:
|
40
|
+
->(country) { for_address(Spree::Tax::TaxLocation.new(country:)) }
|
41
41
|
scope :active, -> do
|
42
42
|
table = arel_table
|
43
43
|
time = Time.current
|
@@ -21,11 +21,11 @@ module Spree
|
|
21
21
|
def set_name
|
22
22
|
if root
|
23
23
|
root.update_columns(
|
24
|
-
name
|
24
|
+
name:,
|
25
25
|
updated_at: Time.current
|
26
26
|
)
|
27
27
|
else
|
28
|
-
self.root = Spree::Taxon.create!(taxonomy_id: id, name:
|
28
|
+
self.root = Spree::Taxon.create!(taxonomy_id: id, name:)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -20,10 +20,9 @@ class Spree::UnitCancel < Spree::Base
|
|
20
20
|
|
21
21
|
self.adjustment = inventory_unit.line_item.adjustments.create!(
|
22
22
|
source: self,
|
23
|
-
amount
|
23
|
+
amount:,
|
24
24
|
order: inventory_unit.order,
|
25
25
|
label: "#{I18n.t('spree.cancellation')} - #{reason}",
|
26
|
-
eligible: true,
|
27
26
|
finalized: true
|
28
27
|
)
|
29
28
|
|
@@ -41,7 +41,7 @@ module Spree
|
|
41
41
|
def find_or_initialize_price_by(country_iso, currency)
|
42
42
|
variant.prices.detect do |price|
|
43
43
|
price.country_iso == country_iso && price.currency == currency
|
44
|
-
end || variant.prices.build(country_iso
|
44
|
+
end || variant.prices.build(country_iso:, currency:)
|
45
45
|
end
|
46
46
|
|
47
47
|
# nil is added to the array so we always have an export price.
|
data/app/models/spree/variant.rb
CHANGED
@@ -80,6 +80,11 @@ module Spree
|
|
80
80
|
|
81
81
|
after_destroy :destroy_option_values_variants
|
82
82
|
|
83
|
+
scope :template_variants, -> do
|
84
|
+
left_joins(product: { option_types: :option_values }).where(is_master: true).where.not(spree_option_values: { id: nil }).reorder(nil).distinct
|
85
|
+
end
|
86
|
+
scope :non_template_variants, -> { where.not(id: template_variants) }
|
87
|
+
|
83
88
|
# Returns variants that are in stock. When stock locations are provided as
|
84
89
|
# a parameter, the scope is limited to variants that are in stock in the
|
85
90
|
# provided stock locations.
|
@@ -94,7 +99,7 @@ module Spree
|
|
94
99
|
if stock_locations.present?
|
95
100
|
in_stock_variants = in_stock_variants.where(spree_stock_items: { stock_location_id: stock_locations.map(&:id) })
|
96
101
|
end
|
97
|
-
in_stock_variants
|
102
|
+
in_stock_variants.distinct
|
98
103
|
end
|
99
104
|
|
100
105
|
# Returns a scope of Variants which are suppliable. This includes:
|
@@ -194,7 +199,7 @@ module Spree
|
|
194
199
|
#
|
195
200
|
# @return [String] a sentence-ified string of option values.
|
196
201
|
def options_text
|
197
|
-
values = option_values.
|
202
|
+
values = option_values.sort_by do |option_value|
|
198
203
|
option_value.option_type.position
|
199
204
|
end
|
200
205
|
|
data/app/models/spree/wallet.rb
CHANGED
@@ -28,7 +28,7 @@ class Spree::Wallet
|
|
28
28
|
# @param payment_source [PaymentSource] The payment source to add to the wallet
|
29
29
|
# @return [WalletPaymentSource] the generated WalletPaymentSource
|
30
30
|
def add(payment_source)
|
31
|
-
user.wallet_payment_sources.find_or_create_by!(payment_source:
|
31
|
+
user.wallet_payment_sources.find_or_create_by!(payment_source:)
|
32
32
|
end
|
33
33
|
|
34
34
|
# Remove a PaymentSource from the wallet.
|
@@ -37,7 +37,7 @@ class Spree::Wallet
|
|
37
37
|
# @raise [ActiveRecord::RecordNotFound] if the source is not in the wallet.
|
38
38
|
# @return [WalletPaymentSource] the destroyed WalletPaymentSource
|
39
39
|
def remove(payment_source)
|
40
|
-
user.wallet_payment_sources.find_by!(payment_source:
|
40
|
+
user.wallet_payment_sources.find_by!(payment_source:).destroy!
|
41
41
|
end
|
42
42
|
|
43
43
|
# Find a WalletPaymentSource in the wallet by id.
|
@@ -26,7 +26,7 @@
|
|
26
26
|
<td><%= t('.subtotal') %></td>
|
27
27
|
<td><%= @order.display_item_total %></td>
|
28
28
|
</tr>
|
29
|
-
<% @order.adjustments.
|
29
|
+
<% @order.adjustments.each do |adjustment| %>
|
30
30
|
<tr>
|
31
31
|
<td></td>
|
32
32
|
<td><%= sanitize(adjustment.label) %></td>
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<% end %>
|
11
11
|
============================================================
|
12
12
|
<%= t('.subtotal') %> <%= @order.display_item_total %>
|
13
|
-
<% @order.adjustments.
|
13
|
+
<% @order.adjustments.each do |adjustment| %>
|
14
14
|
<%= raw(adjustment.label) %> <%= adjustment.display_amount %>
|
15
15
|
<% end %>
|
16
16
|
<%= t('.total') %> <%= @order.display_total %>
|
@@ -31,8 +31,8 @@
|
|
31
31
|
</td>
|
32
32
|
</tr>
|
33
33
|
<% if @order.line_item_adjustments.exists? %>
|
34
|
-
<% if @order.all_adjustments.promotion.
|
35
|
-
<% @order.all_adjustments.promotion.
|
34
|
+
<% if @order.all_adjustments.promotion.exists? %>
|
35
|
+
<% @order.all_adjustments.promotion.group_by(&:label).each do |label, adjustments| %>
|
36
36
|
<tr>
|
37
37
|
<td></td>
|
38
38
|
<td><%= t('spree.promotion') %> <%= label %>:</td>
|
@@ -48,8 +48,8 @@
|
|
48
48
|
<td><%= Spree::Money.new(shipments.sum(&:total_before_tax), currency: @order.currency) %></td>
|
49
49
|
</tr>
|
50
50
|
<% end %>
|
51
|
-
<% if @order.all_adjustments.
|
52
|
-
<% @order.all_adjustments.
|
51
|
+
<% if @order.all_adjustments.tax.exists? %>
|
52
|
+
<% @order.all_adjustments.tax.group_by(&:label).each do |label, adjustments| %>
|
53
53
|
<tr>
|
54
54
|
<td></td>
|
55
55
|
<td><%= t('spree.tax') %> <%= label %>:</td>
|
@@ -57,7 +57,7 @@
|
|
57
57
|
</tr>
|
58
58
|
<% end %>
|
59
59
|
<% end %>
|
60
|
-
<% @order.adjustments.
|
60
|
+
<% @order.adjustments.each do |adjustment| %>
|
61
61
|
<% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
|
62
62
|
<tr>
|
63
63
|
<td></td>
|
@@ -11,8 +11,8 @@
|
|
11
11
|
============================================================
|
12
12
|
<%= t('.subtotal') %> <%= @order.display_item_total %>
|
13
13
|
<% if @order.line_item_adjustments.exists? %>
|
14
|
-
<% if @order.all_adjustments.promotion.
|
15
|
-
<% @order.all_adjustments.promotion.
|
14
|
+
<% if @order.all_adjustments.promotion.exists? %>
|
15
|
+
<% @order.all_adjustments.promotion.group_by(&:label).each do |label, adjustments| %>
|
16
16
|
<%= t('spree.promotion') %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
|
17
17
|
<% end %>
|
18
18
|
<% end %>
|
@@ -22,13 +22,13 @@
|
|
22
22
|
<%= t('spree.shipping') %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:total_before_tax), currency: @order.currency) %>
|
23
23
|
<% end %>
|
24
24
|
|
25
|
-
<% if @order.all_adjustments.
|
26
|
-
<% @order.all_adjustments.
|
25
|
+
<% if @order.all_adjustments.tax.exists? %>
|
26
|
+
<% @order.all_adjustments.tax.group_by(&:label).each do |label, adjustments| %>
|
27
27
|
<%= t('spree.tax') %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
|
28
28
|
<% end %>
|
29
29
|
<% end %>
|
30
30
|
|
31
|
-
<% @order.adjustments.
|
31
|
+
<% @order.adjustments.each do |adjustment| %>
|
32
32
|
<% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
|
33
33
|
<%= adjustment.label %> <%= adjustment.display_amount %>
|
34
34
|
<% end %>
|