solidus_core 4.3.5 → 4.4.1
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 -4
- 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 +15 -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 -127
- 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 +7 -7
- metadata +60 -93
- 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/line_item_action.rb +0 -8
- 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/bin/rails +0 -13
- 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/order.rb
CHANGED
@@ -62,7 +62,7 @@ module Spree
|
|
62
62
|
go_to_state :confirm
|
63
63
|
end
|
64
64
|
|
65
|
-
self.allowed_ransackable_associations = %w[shipments user
|
65
|
+
self.allowed_ransackable_associations = %w[shipments user bill_address ship_address line_items]
|
66
66
|
self.allowed_ransackable_attributes = %w[completed_at created_at email number state payment_state shipment_state total store_id]
|
67
67
|
|
68
68
|
attr_reader :coupon_code
|
@@ -108,8 +108,6 @@ module Spree
|
|
108
108
|
foreign_key: :order_id,
|
109
109
|
dependent: :destroy,
|
110
110
|
inverse_of: :order
|
111
|
-
has_many :order_promotions, class_name: 'Spree::OrderPromotion', dependent: :destroy
|
112
|
-
has_many :promotions, through: :order_promotions
|
113
111
|
|
114
112
|
# Payments
|
115
113
|
has_many :payments, dependent: :destroy, inverse_of: :order
|
@@ -181,7 +179,7 @@ module Spree
|
|
181
179
|
end
|
182
180
|
|
183
181
|
def self.by_state(state)
|
184
|
-
where(state:
|
182
|
+
where(state:)
|
185
183
|
end
|
186
184
|
|
187
185
|
def self.complete
|
@@ -229,7 +227,7 @@ module Spree
|
|
229
227
|
end
|
230
228
|
|
231
229
|
def shipping_discount
|
232
|
-
shipment_adjustments.credit.
|
230
|
+
shipment_adjustments.credit.sum(:amount) * - 1
|
233
231
|
end
|
234
232
|
|
235
233
|
def to_param
|
@@ -316,7 +314,7 @@ module Spree
|
|
316
314
|
|
317
315
|
if persisted?
|
318
316
|
# immediately persist the changes we just made, but don't use save since we might have an invalid address associated
|
319
|
-
self.class.unscoped.where(id:
|
317
|
+
self.class.unscoped.where(id:).update_all(attrs_to_set)
|
320
318
|
end
|
321
319
|
|
322
320
|
assign_attributes(attrs_to_set)
|
@@ -450,7 +448,7 @@ module Spree
|
|
450
448
|
line_items.destroy_all
|
451
449
|
adjustments.destroy_all
|
452
450
|
shipments.destroy_all
|
453
|
-
|
451
|
+
Spree::Bus.publish :order_emptied, order: self
|
454
452
|
|
455
453
|
recalculate
|
456
454
|
end
|
@@ -464,7 +462,7 @@ module Spree
|
|
464
462
|
end
|
465
463
|
|
466
464
|
def can_add_coupon?
|
467
|
-
Spree::
|
465
|
+
Spree::Config.promotions.coupon_code_handler_class.new(self).can_apply?
|
468
466
|
end
|
469
467
|
|
470
468
|
def shipped?
|
@@ -508,11 +506,6 @@ module Spree
|
|
508
506
|
end
|
509
507
|
end
|
510
508
|
|
511
|
-
def apply_shipping_promotions
|
512
|
-
Spree::Config.shipping_promotion_handler_class.new(self).activate
|
513
|
-
recalculate
|
514
|
-
end
|
515
|
-
|
516
509
|
# Clean shipments and make order back to address state (or to whatever state
|
517
510
|
# is set by restart_checkout_flow in case of state machine modifications)
|
518
511
|
def check_shipments_and_restart_checkout
|
@@ -577,7 +570,7 @@ module Spree
|
|
577
570
|
|
578
571
|
def add_store_credit_payments
|
579
572
|
return if user.nil?
|
580
|
-
return if payments.store_credits.checkout.empty? && user.available_store_credit_total(currency:
|
573
|
+
return if payments.store_credits.checkout.empty? && user.available_store_credit_total(currency:).zero?
|
581
574
|
|
582
575
|
payments.store_credits.checkout.each(&:invalidate!)
|
583
576
|
|
@@ -588,7 +581,7 @@ module Spree
|
|
588
581
|
|
589
582
|
remaining_total = outstanding_balance - authorized_total
|
590
583
|
|
591
|
-
matching_store_credits = user.store_credits.where(currency:
|
584
|
+
matching_store_credits = user.store_credits.where(currency:)
|
592
585
|
|
593
586
|
if matching_store_credits.any?
|
594
587
|
payment_method = Spree::PaymentMethod::StoreCredit.first
|
@@ -600,7 +593,7 @@ module Spree
|
|
600
593
|
|
601
594
|
amount_to_take = [credit.amount_remaining, remaining_total].min
|
602
595
|
payments.create!(source: credit,
|
603
|
-
payment_method
|
596
|
+
payment_method:,
|
604
597
|
amount: amount_to_take,
|
605
598
|
state: 'checkout',
|
606
599
|
response_code: credit.generate_authorization_code)
|
@@ -624,13 +617,13 @@ module Spree
|
|
624
617
|
|
625
618
|
def covered_by_store_credit?
|
626
619
|
return false unless user
|
627
|
-
user.available_store_credit_total(currency:
|
620
|
+
user.available_store_credit_total(currency:) >= total
|
628
621
|
end
|
629
622
|
alias_method :covered_by_store_credit, :covered_by_store_credit?
|
630
623
|
|
631
624
|
def total_available_store_credit
|
632
625
|
return 0.0 unless user
|
633
|
-
user.available_store_credit_total(currency:
|
626
|
+
user.available_store_credit_total(currency:)
|
634
627
|
end
|
635
628
|
|
636
629
|
def order_total_after_store_credit
|
@@ -641,16 +634,16 @@ module Spree
|
|
641
634
|
if can_complete? || complete?
|
642
635
|
valid_store_credit_payments.to_a.sum(&:amount)
|
643
636
|
else
|
644
|
-
[total, user.try(:available_store_credit_total, currency:
|
637
|
+
[total, user.try(:available_store_credit_total, currency:) || 0.0].min
|
645
638
|
end
|
646
639
|
end
|
647
640
|
|
648
641
|
def display_total_applicable_store_credit
|
649
|
-
Spree::Money.new(-total_applicable_store_credit, { currency:
|
642
|
+
Spree::Money.new(-total_applicable_store_credit, { currency: })
|
650
643
|
end
|
651
644
|
|
652
645
|
def display_store_credit_remaining_after_capture
|
653
|
-
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency:
|
646
|
+
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency: })
|
654
647
|
end
|
655
648
|
|
656
649
|
def bill_address_attributes=(attributes)
|
@@ -799,7 +792,7 @@ module Spree
|
|
799
792
|
end
|
800
793
|
|
801
794
|
def ensure_promotions_eligible
|
802
|
-
Spree::Config.
|
795
|
+
Spree::Config.promotions.order_adjuster_class.new(self).call
|
803
796
|
|
804
797
|
if promo_total_changed?
|
805
798
|
restart_checkout_flow
|
@@ -36,7 +36,7 @@ class Spree::OrderCancellations
|
|
36
36
|
Spree::OrderMutex.with_lock!(@order) do
|
37
37
|
Spree::InventoryUnit.transaction do
|
38
38
|
inventory_units.each do |iu|
|
39
|
-
unit_cancels << short_ship_unit(iu, created_by:
|
39
|
+
unit_cancels << short_ship_unit(iu, created_by:)
|
40
40
|
end
|
41
41
|
|
42
42
|
update_shipped_shipments(inventory_units)
|
@@ -67,9 +67,9 @@ class Spree::OrderCancellations
|
|
67
67
|
|
68
68
|
Spree::OrderMutex.with_lock!(@order) do
|
69
69
|
unit_cancel = Spree::UnitCancel.create!(
|
70
|
-
inventory_unit
|
71
|
-
reason
|
72
|
-
created_by:
|
70
|
+
inventory_unit:,
|
71
|
+
reason:,
|
72
|
+
created_by:
|
73
73
|
)
|
74
74
|
|
75
75
|
inventory_unit.cancel!
|
@@ -89,8 +89,8 @@ class Spree::OrderCancellations
|
|
89
89
|
|
90
90
|
Spree::OrderMutex.with_lock!(@order) do
|
91
91
|
return_items = inventory_units.map(&:current_or_new_return_item)
|
92
|
-
reimbursement = Spree::Reimbursement.new(order: @order, return_items:
|
93
|
-
reimbursement.return_all(created_by:
|
92
|
+
reimbursement = Spree::Reimbursement.new(order: @order, return_items:)
|
93
|
+
reimbursement.return_all(created_by:)
|
94
94
|
end
|
95
95
|
|
96
96
|
reimbursement
|
@@ -100,9 +100,9 @@ class Spree::OrderCancellations
|
|
100
100
|
|
101
101
|
def short_ship_unit(inventory_unit, created_by: nil)
|
102
102
|
unit_cancel = Spree::UnitCancel.create!(
|
103
|
-
inventory_unit
|
103
|
+
inventory_unit:,
|
104
104
|
reason: Spree::UnitCancel::SHORT_SHIP,
|
105
|
-
created_by:
|
105
|
+
created_by:
|
106
106
|
)
|
107
107
|
unit_cancel.adjust!
|
108
108
|
inventory_unit.cancel!
|
@@ -16,10 +16,10 @@ module Spree
|
|
16
16
|
raise ArgumentError, "order must be supplied" if order.nil?
|
17
17
|
|
18
18
|
# limit the maximum lock time just in case a lock is somehow left in place accidentally
|
19
|
-
expired.where(order:
|
19
|
+
expired.where(order:).delete_all
|
20
20
|
|
21
21
|
begin
|
22
|
-
order_mutex = create!(order:
|
22
|
+
order_mutex = create!(order:)
|
23
23
|
rescue ActiveRecord::RecordNotUnique
|
24
24
|
error = LockFailed.new("Could not obtain lock on order #{order.id}")
|
25
25
|
logger.error error.inspect
|
@@ -22,11 +22,11 @@ class Spree::OrderShipping
|
|
22
22
|
address: shipment.order.ship_address,
|
23
23
|
shipping_method: shipment.shipping_method,
|
24
24
|
shipped_at: Time.current,
|
25
|
-
external_number
|
25
|
+
external_number:,
|
26
26
|
# TODO: Remove the `|| shipment.tracking` once Shipment#ship! is called by
|
27
27
|
# OrderShipping#ship rather than vice versa
|
28
28
|
tracking_number: tracking_number || shipment.tracking,
|
29
|
-
suppress_mailer:
|
29
|
+
suppress_mailer:
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
@@ -51,12 +51,12 @@ class Spree::OrderShipping
|
|
51
51
|
inventory_units.each(&:ship!)
|
52
52
|
|
53
53
|
carton = Spree::Carton.create!(
|
54
|
-
stock_location
|
55
|
-
address
|
56
|
-
shipping_method
|
57
|
-
inventory_units
|
58
|
-
shipped_at
|
59
|
-
external_number
|
54
|
+
stock_location:,
|
55
|
+
address:,
|
56
|
+
shipping_method:,
|
57
|
+
inventory_units:,
|
58
|
+
shipped_at:,
|
59
|
+
external_number:,
|
60
60
|
tracking: tracking_number
|
61
61
|
)
|
62
62
|
end
|
@@ -80,7 +80,7 @@ class Spree::OrderShipping
|
|
80
80
|
|
81
81
|
def send_shipment_emails(carton)
|
82
82
|
carton.orders.each do |order|
|
83
|
-
Spree::Config.carton_shipped_email_class.shipped_email(order
|
83
|
+
Spree::Config.carton_shipped_email_class.shipped_email(order:, carton:).deliver_later
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -26,7 +26,7 @@ module Spree
|
|
26
26
|
update_shipments
|
27
27
|
update_shipment_state
|
28
28
|
end
|
29
|
-
Spree::Bus.publish
|
29
|
+
Spree::Bus.publish(:order_recalculated, order:)
|
30
30
|
persist_totals
|
31
31
|
end
|
32
32
|
end
|
@@ -114,7 +114,6 @@ module Spree
|
|
114
114
|
# http://www.boe.ca.gov/formspubs/pub113/
|
115
115
|
update_promotions
|
116
116
|
update_taxes
|
117
|
-
update_cancellations
|
118
117
|
update_item_totals
|
119
118
|
end
|
120
119
|
|
@@ -158,9 +157,9 @@ module Spree
|
|
158
157
|
recalculate_adjustments
|
159
158
|
|
160
159
|
all_items = line_items + shipments
|
161
|
-
order_tax_adjustments = adjustments.select(&:
|
160
|
+
order_tax_adjustments = adjustments.select(&:tax?)
|
162
161
|
|
163
|
-
order.adjustment_total = all_items.sum(&:adjustment_total) + adjustments.
|
162
|
+
order.adjustment_total = all_items.sum(&:adjustment_total) + adjustments.sum(&:amount)
|
164
163
|
order.included_tax_total = all_items.sum(&:included_tax_total) + order_tax_adjustments.select(&:included?).sum(&:amount)
|
165
164
|
order.additional_tax_total = all_items.sum(&:additional_tax_total) + order_tax_adjustments.reject(&:included?).sum(&:amount)
|
166
165
|
|
@@ -189,14 +188,14 @@ module Spree
|
|
189
188
|
order.state_changes.new(
|
190
189
|
previous_state: old_state,
|
191
190
|
next_state: new_state,
|
192
|
-
name
|
191
|
+
name:,
|
193
192
|
user_id: order.user_id
|
194
193
|
)
|
195
194
|
end
|
196
195
|
end
|
197
196
|
|
198
197
|
def update_promotions
|
199
|
-
Spree::Config.
|
198
|
+
Spree::Config.promotions.order_adjuster_class.new(order).call
|
200
199
|
end
|
201
200
|
|
202
201
|
def update_taxes
|
@@ -217,17 +216,14 @@ module Spree
|
|
217
216
|
end
|
218
217
|
|
219
218
|
def update_cancellations
|
220
|
-
line_items.each do |line_item|
|
221
|
-
line_item.adjustments.select(&:cancellation?).each(&:recalculate)
|
222
|
-
end
|
223
219
|
end
|
220
|
+
deprecate :update_cancellations, deprecator: Spree.deprecator
|
224
221
|
|
225
222
|
def update_item_totals
|
226
223
|
[*line_items, *shipments].each do |item|
|
227
224
|
# The cancellation_total isn't persisted anywhere but is included in
|
228
225
|
# the adjustment_total
|
229
226
|
item.adjustment_total = item.adjustments.
|
230
|
-
select(&:eligible?).
|
231
227
|
reject(&:included?).
|
232
228
|
sum(&:amount)
|
233
229
|
|
@@ -64,7 +64,7 @@ module Spree
|
|
64
64
|
complete! if handle_response(response)
|
65
65
|
end
|
66
66
|
|
67
|
-
capture_events.create!(amount:
|
67
|
+
capture_events.create!(amount:)
|
68
68
|
end
|
69
69
|
|
70
70
|
# Takes the amount in cents to capture.
|
@@ -243,7 +243,7 @@ module Spree
|
|
243
243
|
cvv_result: response.cvv_result,
|
244
244
|
error_code: response.error_code,
|
245
245
|
emv_authorization: response.emv_authorization,
|
246
|
-
gateway_order_id
|
246
|
+
gateway_order_id:,
|
247
247
|
order_number: order.number
|
248
248
|
}
|
249
249
|
end
|
data/app/models/spree/payment.rb
CHANGED
@@ -69,7 +69,7 @@ module Spree
|
|
69
69
|
|
70
70
|
# @return [Spree::Money] this amount of this payment as money object
|
71
71
|
def money
|
72
|
-
Spree::Money.new(amount, { currency:
|
72
|
+
Spree::Money.new(amount, { currency: })
|
73
73
|
end
|
74
74
|
alias display_amount money
|
75
75
|
|
@@ -211,7 +211,7 @@ module Spree
|
|
211
211
|
def set_unique_identifier
|
212
212
|
loop do
|
213
213
|
self.number = generate_identifier
|
214
|
-
break unless self.class.exists?(number:
|
214
|
+
break unless self.class.exists?(number:)
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -107,7 +107,7 @@ module Spree
|
|
107
107
|
store_credit = Spree::StoreCreditEvent.find_by(authorization_code: auth_code).try(:store_credit)
|
108
108
|
|
109
109
|
if store_credit.nil?
|
110
|
-
ActiveMerchant::Billing::Response.new(false, I18n.t('spree.store_credit.unable_to_find_for_action', auth_code
|
110
|
+
ActiveMerchant::Billing::Response.new(false, I18n.t('spree.store_credit.unable_to_find_for_action', auth_code:, action: action_name), {}, {})
|
111
111
|
else
|
112
112
|
handle_action_call(store_credit, action, action_name, auth_code)
|
113
113
|
end
|
@@ -7,7 +7,11 @@ module Spree
|
|
7
7
|
belongs_to :payment_method, optional: true
|
8
8
|
|
9
9
|
has_many :payments, as: :source
|
10
|
-
has_many :wallet_payment_sources,
|
10
|
+
has_many :wallet_payment_sources,
|
11
|
+
class_name: 'Spree::WalletPaymentSource',
|
12
|
+
as: :payment_source,
|
13
|
+
inverse_of: :payment_source,
|
14
|
+
dependent: :destroy
|
11
15
|
|
12
16
|
attr_accessor :imported
|
13
17
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
class PermissionSet < Spree::Base
|
5
|
+
has_many :role_permissions
|
6
|
+
has_many :roles, through: :role_permissions
|
7
|
+
validates :name, :set, :privilege, :category, presence: true
|
8
|
+
scope :display_permissions, -> { where(privilege: "display") }
|
9
|
+
scope :management_permissions, -> { where(privilege: "management") }
|
10
|
+
end
|
11
|
+
end
|
data/app/models/spree/product.rb
CHANGED
@@ -16,7 +16,6 @@ module Spree
|
|
16
16
|
self.product_option_types = []
|
17
17
|
self.product_properties = []
|
18
18
|
self.classifications.destroy_all
|
19
|
-
self.product_promotion_rules = []
|
20
19
|
end
|
21
20
|
|
22
21
|
has_many :product_option_types, dependent: :destroy, inverse_of: :product
|
@@ -31,9 +30,6 @@ module Spree
|
|
31
30
|
has_many :classifications, dependent: :delete_all, inverse_of: :product
|
32
31
|
has_many :taxons, through: :classifications, before_remove: :remove_taxon
|
33
32
|
|
34
|
-
has_many :product_promotion_rules, dependent: :destroy
|
35
|
-
has_many :promotion_rules, through: :product_promotion_rules
|
36
|
-
|
37
33
|
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
|
38
34
|
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :products, optional: true
|
39
35
|
|
@@ -61,6 +57,8 @@ module Spree
|
|
61
57
|
has_many :line_items, through: :variants_including_master
|
62
58
|
has_many :orders, through: :line_items
|
63
59
|
|
60
|
+
has_many :option_values, -> { distinct }, through: :variants_including_master
|
61
|
+
|
64
62
|
scope :sort_by_master_default_price_amount_asc, -> {
|
65
63
|
with_default_price.order('spree_prices.amount ASC')
|
66
64
|
}
|
@@ -131,26 +129,8 @@ module Spree
|
|
131
129
|
|
132
130
|
alias :options :product_option_types
|
133
131
|
|
134
|
-
|
135
|
-
|
136
|
-
#
|
137
|
-
# Usage:
|
138
|
-
# Spree::Product.ransack(
|
139
|
-
# variants_option_values_in: [option_value_id1, option_value_id2]
|
140
|
-
# ).result
|
141
|
-
ransacker :variants_option_values, formatter: proc { |v|
|
142
|
-
if OptionValue.exists?(v)
|
143
|
-
joins(variants_including_master: :option_values)
|
144
|
-
.where(spree_option_values: { id: v })
|
145
|
-
.distinct
|
146
|
-
.select(:id).arel
|
147
|
-
end
|
148
|
-
} do |parent|
|
149
|
-
parent.table[:id]
|
150
|
-
end
|
151
|
-
|
152
|
-
self.allowed_ransackable_associations = %w[stores variants_including_master master variants]
|
153
|
-
self.allowed_ransackable_attributes = %w[name slug variants_option_values]
|
132
|
+
self.allowed_ransackable_associations = %w[stores variants_including_master master variants option_values]
|
133
|
+
self.allowed_ransackable_attributes = %w[name slug]
|
154
134
|
self.allowed_ransackable_scopes = %i[available with_discarded with_all_variant_sku_cont with_kept_variant_sku_cont]
|
155
135
|
|
156
136
|
# @return [Boolean] true if there are any variants
|
@@ -270,7 +250,7 @@ module Spree
|
|
270
250
|
ActiveRecord::Base.transaction do
|
271
251
|
# Works around spree_i18n https://github.com/spree/spree/issues/301
|
272
252
|
property = Spree::Property.create_with(presentation: property_name).find_or_create_by(name: property_name)
|
273
|
-
product_property = Spree::ProductProperty.where(product: self, property:
|
253
|
+
product_property = Spree::ProductProperty.where(product: self, property:).first_or_initialize
|
274
254
|
product_property.value = property_value
|
275
255
|
product_property.save!
|
276
256
|
end
|
@@ -278,8 +258,7 @@ module Spree
|
|
278
258
|
|
279
259
|
# @return [Array] all advertised and not-rejected promotions
|
280
260
|
def possible_promotions
|
281
|
-
|
282
|
-
Spree::Promotion.advertised.where(id: promotion_ids).reject(&:inactive?)
|
261
|
+
Spree::Config.promotions.advertiser_class.for_product(self)
|
283
262
|
end
|
284
263
|
|
285
264
|
# The number of on-hand stock items; Infinity if any variant does not track
|
@@ -384,7 +363,7 @@ module Spree
|
|
384
363
|
end
|
385
364
|
|
386
365
|
def remove_taxon(taxon)
|
387
|
-
removed_classifications = classifications.where(taxon:
|
366
|
+
removed_classifications = classifications.where(taxon:)
|
388
367
|
removed_classifications.each(&:remove_from_list)
|
389
368
|
end
|
390
369
|
end
|
data/app/models/spree/refund.rb
CHANGED
@@ -57,7 +57,7 @@ module Spree
|
|
57
57
|
def build_from_customer_return(customer_return)
|
58
58
|
order = customer_return.order
|
59
59
|
order.reimbursements.build({
|
60
|
-
customer_return
|
60
|
+
customer_return:,
|
61
61
|
return_items: customer_return.return_items.accepted.not_reimbursed
|
62
62
|
})
|
63
63
|
end
|
@@ -88,7 +88,7 @@ module Spree
|
|
88
88
|
reload
|
89
89
|
update!(total: calculated_total)
|
90
90
|
|
91
|
-
reimbursement_performer.perform(self, created_by:
|
91
|
+
reimbursement_performer.perform(self, created_by:)
|
92
92
|
|
93
93
|
if unpaid_amount_within_tolerance?
|
94
94
|
reimbursed!
|
@@ -108,7 +108,7 @@ module Spree
|
|
108
108
|
reload
|
109
109
|
update!(total: calculated_total)
|
110
110
|
|
111
|
-
reimbursement_performer.simulate(self, created_by:
|
111
|
+
reimbursement_performer.simulate(self, created_by:)
|
112
112
|
end
|
113
113
|
|
114
114
|
def return_items_requiring_exchange
|
@@ -131,7 +131,7 @@ module Spree
|
|
131
131
|
def return_all(created_by:)
|
132
132
|
return_items.each(&:accept!)
|
133
133
|
save!
|
134
|
-
perform!(created_by:
|
134
|
+
perform!(created_by:)
|
135
135
|
end
|
136
136
|
|
137
137
|
# The returned category is used as the category
|
@@ -12,12 +12,12 @@ module Spree
|
|
12
12
|
# - #display_amount
|
13
13
|
# so they can be displayed in the Admin UI appropriately.
|
14
14
|
def simulate(reimbursement, created_by:)
|
15
|
-
execute(reimbursement, true, created_by:
|
15
|
+
execute(reimbursement, true, created_by:)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Actually perform the reimbursement
|
19
19
|
def perform(reimbursement, created_by:)
|
20
|
-
execute(reimbursement, false, created_by:
|
20
|
+
execute(reimbursement, false, created_by:)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
@@ -26,7 +26,7 @@ module Spree
|
|
26
26
|
reimbursement_type_hash = calculate_reimbursement_types(reimbursement)
|
27
27
|
|
28
28
|
reimbursement_type_hash.flat_map do |reimbursement_type, return_items|
|
29
|
-
reimbursement_type.reimburse(reimbursement, return_items, simulate, created_by:
|
29
|
+
reimbursement_type.reimburse(reimbursement, return_items, simulate, created_by:)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -26,8 +26,8 @@ module Spree
|
|
26
26
|
included_tax_total = percent_of_tax * return_item.inventory_unit.included_tax_total
|
27
27
|
|
28
28
|
return_item.update!({
|
29
|
-
additional_tax_total
|
30
|
-
included_tax_total:
|
29
|
+
additional_tax_total:,
|
30
|
+
included_tax_total:
|
31
31
|
})
|
32
32
|
end
|
33
33
|
end
|
@@ -7,7 +7,7 @@ module Spree
|
|
7
7
|
class << self
|
8
8
|
def reimburse(reimbursement, return_items, simulate, created_by:)
|
9
9
|
unpaid_amount = return_items.sum(&:total).round(2, :down)
|
10
|
-
reimbursement_list, _unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate, created_by:
|
10
|
+
reimbursement_list, _unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate, created_by:)
|
11
11
|
reimbursement_list
|
12
12
|
end
|
13
13
|
end
|
@@ -21,7 +21,7 @@ module Spree
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def create_credits(reimbursement, unpaid_amount, simulate, reimbursement_list = [], created_by:)
|
24
|
-
credits = [create_credit(reimbursement, unpaid_amount, simulate, created_by:
|
24
|
+
credits = [create_credit(reimbursement, unpaid_amount, simulate, created_by:)]
|
25
25
|
unpaid_amount -= credits.sum(&:amount)
|
26
26
|
reimbursement_list += credits
|
27
27
|
|
@@ -32,8 +32,8 @@ module Spree
|
|
32
32
|
|
33
33
|
def create_refund(reimbursement, payment, amount, simulate)
|
34
34
|
refund = reimbursement.refunds.build({
|
35
|
-
payment
|
36
|
-
amount
|
35
|
+
payment:,
|
36
|
+
amount:,
|
37
37
|
reason: Spree::RefundReason.return_processing_reason
|
38
38
|
})
|
39
39
|
|
@@ -50,8 +50,8 @@ module Spree
|
|
50
50
|
# If you have multiple methods of crediting a customer, overwrite this method
|
51
51
|
# Must return an array of objects the respond to #description, #display_amount
|
52
52
|
def create_credit(reimbursement, unpaid_amount, simulate, created_by:)
|
53
|
-
creditable = create_creditable(reimbursement, unpaid_amount, created_by:
|
54
|
-
credit = reimbursement.credits.build(creditable
|
53
|
+
creditable = create_creditable(reimbursement, unpaid_amount, created_by:)
|
54
|
+
credit = reimbursement.credits.build(creditable:, amount: unpaid_amount)
|
55
55
|
simulate ? credit.readonly! : credit.save!
|
56
56
|
credit
|
57
57
|
end
|
@@ -61,7 +61,7 @@ module Spree
|
|
61
61
|
user: reimbursement.order.user,
|
62
62
|
amount: unpaid_amount,
|
63
63
|
category: reimbursement.store_credit_category,
|
64
|
-
created_by
|
64
|
+
created_by:,
|
65
65
|
memo: "Refund for uncreditable payments on order #{reimbursement.order.number}",
|
66
66
|
currency: reimbursement.order.currency
|
67
67
|
)
|
@@ -53,7 +53,7 @@ module Spree
|
|
53
53
|
scope :not_expired, -> { where.not(reception_status: 'expired') }
|
54
54
|
scope :received, -> { where(reception_status: 'received') }
|
55
55
|
INTERMEDIATE_RECEPTION_STATUSES.each do |reception_status|
|
56
|
-
scope reception_status, -> { where(reception_status:
|
56
|
+
scope reception_status, -> { where(reception_status:) }
|
57
57
|
end
|
58
58
|
scope :pending, -> { where(acceptance_status: 'pending') }
|
59
59
|
scope :accepted, -> { where(acceptance_status: 'accepted') }
|
@@ -93,8 +93,8 @@ module Spree
|
|
93
93
|
# @return [Spree::ReturnItem] a valid return item for the given inventory
|
94
94
|
# unit if one exists, or a new one if one does not
|
95
95
|
def self.from_inventory_unit(inventory_unit)
|
96
|
-
valid.find_by(inventory_unit:
|
97
|
-
new(inventory_unit:
|
96
|
+
valid.find_by(inventory_unit:) ||
|
97
|
+
new(inventory_unit:).tap(&:set_default_amount)
|
98
98
|
end
|
99
99
|
|
100
100
|
# @return [Boolean] true when an exchange has been requested on this return
|
@@ -130,7 +130,7 @@ module Spree
|
|
130
130
|
# @return [ActiveRecord::Relation<Spree::Variant>] the variants eligible
|
131
131
|
# for exchange for this return item
|
132
132
|
def eligible_exchange_variants(stock_locations = nil)
|
133
|
-
exchange_variant_engine.eligible_variants(variant, stock_locations:
|
133
|
+
exchange_variant_engine.eligible_variants(variant, stock_locations:)
|
134
134
|
end
|
135
135
|
|
136
136
|
# Builds the exchange inventory unit for this return item, only if an
|
@@ -248,20 +248,20 @@ module Spree
|
|
248
248
|
|
249
249
|
def validate_no_other_completed_return_items
|
250
250
|
other_return_item = Spree::ReturnItem.where({
|
251
|
-
inventory_unit_id
|
251
|
+
inventory_unit_id:,
|
252
252
|
reception_status: COMPLETED_RECEPTION_STATUSES
|
253
|
-
}).where.not(id:
|
253
|
+
}).where.not(id:).first
|
254
254
|
|
255
255
|
if other_return_item && (new_record? || COMPLETED_RECEPTION_STATUSES.include?(reception_status.to_sym))
|
256
256
|
errors.add(:inventory_unit, :other_completed_return_item_exists,
|
257
|
-
inventory_unit_id
|
257
|
+
inventory_unit_id:,
|
258
258
|
return_item_id: other_return_item.id)
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
262
262
|
def cancel_others
|
263
|
-
Spree::ReturnItem.where(inventory_unit_id:
|
264
|
-
.where.not(id:
|
263
|
+
Spree::ReturnItem.where(inventory_unit_id:)
|
264
|
+
.where.not(id:)
|
265
265
|
.valid
|
266
266
|
.each(&:cancel!)
|
267
267
|
end
|