spree_core 6.0.3 → 6.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/jobs/spree/imports/create_rows_job.rb +4 -2
- data/app/jobs/spree/imports/process_rows_job.rb +4 -2
- data/app/jobs/spree/payments/handle_webhook_job.rb +12 -1
- data/app/jobs/spree/products/auto_match_taxons_job.rb +5 -2
- data/app/jobs/spree/search_provider/index_job.rb +8 -0
- data/app/jobs/spree/search_provider/remove_job.rb +3 -0
- data/app/jobs/spree/stock_locations/stock_items/create_job.rb +5 -2
- data/app/mailers/spree/base_mailer.rb +1 -1
- data/app/models/concerns/spree/acted_by.rb +2 -2
- data/app/models/concerns/spree/customer_methods.rb +6 -4
- data/app/models/concerns/spree/deprecated_customer_alias.rb +11 -3
- data/app/models/concerns/spree/derived_number.rb +1 -1
- data/app/models/concerns/spree/has_custom_fields.rb +16 -11
- data/app/models/concerns/spree/integrations_concern.rb +5 -3
- data/app/models/concerns/spree/label_translatable.rb +4 -4
- data/app/models/concerns/spree/metadata.rb +3 -3
- data/app/models/concerns/spree/personal_data_matching.rb +5 -1
- data/app/models/concerns/spree/presentation_translatable.rb +1 -1
- data/app/models/concerns/spree/product_scopes.rb +2 -2
- data/app/models/concerns/spree/publishable.rb +26 -3
- data/app/models/concerns/spree/purchase/addresses.rb +8 -5
- data/app/models/concerns/spree/purchase/deprecated_aliases.rb +2 -2
- data/app/models/concerns/spree/stores/markets.rb +4 -2
- data/app/models/concerns/spree/user_address.rb +5 -2
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/spree/address.rb +29 -14
- data/app/models/spree/asset.rb +3 -3
- data/app/models/spree/authentication/strategies/base_strategy.rb +10 -1
- data/app/models/spree/base.rb +1 -1
- data/app/models/spree/calculator/shipping/flat_rate.rb +6 -4
- data/app/models/spree/cart.rb +9 -4
- data/app/models/spree/category.rb +8 -6
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/current.rb +19 -0
- data/app/models/spree/custom_field.rb +6 -6
- data/app/models/spree/custom_field_definition.rb +10 -7
- data/app/models/spree/delivery_method.rb +21 -15
- data/app/models/spree/delivery_rate.rb +1 -1
- data/app/models/spree/digital.rb +1 -1
- data/app/models/spree/digital_asset.rb +2 -2
- data/app/models/spree/digital_link.rb +4 -4
- data/app/models/spree/export.rb +29 -2
- data/app/models/spree/fulfillment/custom_events.rb +18 -10
- data/app/models/spree/fulfillment.rb +30 -23
- data/app/models/spree/fulfillment_item.rb +3 -3
- data/app/models/spree/fulfilment_changer.rb +1 -1
- data/app/models/spree/gift_card.rb +12 -12
- data/app/models/spree/import.rb +23 -15
- data/app/models/spree/import_row.rb +6 -6
- data/app/models/spree/inventory_unit.rb +1 -1
- data/app/models/spree/invitation.rb +14 -6
- data/app/models/spree/line_item.rb +10 -8
- data/app/models/spree/media.rb +27 -3
- data/app/models/spree/metafield.rb +1 -1
- data/app/models/spree/metafield_definition.rb +1 -1
- data/app/models/spree/metafields.rb +2 -2
- data/app/models/spree/option_type.rb +26 -0
- data/app/models/spree/option_value.rb +3 -3
- data/app/models/spree/order.rb +92 -46
- data/app/models/spree/order_inventory.rb +2 -2
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_updater.rb +34 -20
- data/app/models/spree/payment.rb +8 -8
- data/app/models/spree/payment_method.rb +11 -9
- data/app/models/spree/price.rb +22 -8
- data/app/models/spree/price_list.rb +12 -6
- data/app/models/spree/price_rules/zone_rule.rb +1 -1
- data/app/models/spree/product.rb +32 -33
- data/app/models/spree/product_category.rb +10 -4
- data/app/models/spree/product_collection.rb +8 -1
- data/app/models/spree/promotion/rules/category.rb +27 -10
- data/app/models/spree/promotion/rules/country.rb +1 -1
- data/app/models/spree/promotion/rules/taxon.rb +4 -2
- data/app/models/spree/promotion/rules/user.rb +1 -1
- data/app/models/spree/promotion_action.rb +1 -1
- data/app/models/spree/promotion_rule_category.rb +5 -5
- data/app/models/spree/promotion_rule_taxon.rb +2 -2
- data/app/models/spree/prototype.rb +4 -1
- data/app/models/spree/return_authorization_reason.rb +3 -3
- data/app/models/spree/return_reason.rb +1 -1
- data/app/models/spree/search_provider/base.rb +2 -2
- data/app/models/spree/search_provider.rb +7 -5
- data/app/models/spree/seller.rb +93 -10
- data/app/models/spree/seller_requirements/complete_profile.rb +26 -7
- data/app/models/spree/shipment.rb +4 -1
- data/app/models/spree/shipping_method.rb +4 -1
- data/app/models/spree/shipping_rate.rb +1 -1
- data/app/models/spree/stock/coordinator.rb +2 -2
- data/app/models/spree/stock/estimator.rb +7 -5
- data/app/models/spree/stock/package.rb +10 -8
- data/app/models/spree/stock_item.rb +1 -1
- data/app/models/spree/stock_level/custom_events.rb +1 -1
- data/app/models/spree/stock_level.rb +31 -2
- data/app/models/spree/stock_location.rb +12 -8
- data/app/models/spree/stock_movement.rb +7 -6
- data/app/models/spree/stock_reservation.rb +5 -5
- data/app/models/spree/store.rb +42 -16
- data/app/models/spree/store_credit.rb +2 -2
- data/app/models/spree/store_credit_category.rb +5 -5
- data/app/models/spree/store_credit_type.rb +2 -2
- data/app/models/spree/subscriber.rb +7 -7
- data/app/models/spree/tax_rate.rb +5 -5
- data/app/models/spree/taxon.rb +3 -3
- data/app/models/spree/taxon_rule.rb +2 -2
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/variant.rb +12 -10
- data/app/models/spree/variant_media.rb +1 -1
- data/app/models/spree/wished_item.rb +1 -1
- data/app/models/spree/wishlist.rb +2 -2
- data/app/models/spree/wishlist_item/custom_events.rb +2 -2
- data/app/models/spree/zone.rb +1 -1
- data/app/models/spree/zone_member.rb +1 -1
- data/app/services/spree/carts/associate.rb +6 -2
- data/app/services/spree/carts/create.rb +1 -1
- data/app/services/spree/carts/destroy.rb +23 -7
- data/app/services/spree/carts/remove_item.rb +1 -1
- data/app/services/spree/carts/remove_line_item.rb +2 -2
- data/app/services/spree/carts/remove_out_of_stock_items.rb +3 -1
- data/app/services/spree/carts/set_quantity.rb +2 -2
- data/app/services/spree/carts/update.rb +17 -0
- data/app/services/spree/checkout/add_store_credit.rb +3 -3
- data/app/services/spree/checkout/remove_store_credit.rb +2 -2
- data/app/services/spree/collections/regenerate_products.rb +37 -15
- data/app/services/spree/companies/add_member.rb +9 -4
- data/app/services/spree/diagnostics/error_log.rb +139 -0
- data/app/services/spree/diagnostics/section.rb +72 -0
- data/app/services/spree/diagnostics/sections.rb +121 -0
- data/app/services/spree/diagnostics/stack.rb +73 -0
- data/app/services/spree/diagnostics.rb +132 -0
- data/app/services/spree/imports/row_processors/product_variant.rb +19 -0
- data/app/services/spree/newsletter/subscribe.rb +7 -3
- data/app/services/spree/orders/approve.rb +3 -3
- data/app/services/spree/orders/create_user_account.rb +2 -2
- data/app/services/spree/orders/remove_line_item.rb +16 -5
- data/app/services/spree/product_memberships.rb +21 -1
- data/app/services/spree/product_types/apply_to_products.rb +12 -2
- data/app/services/spree/products/auto_match_collections.rb +20 -4
- data/app/services/spree/products/auto_match_taxons.rb +5 -2
- data/app/services/spree/shipments/update.rb +2 -2
- data/app/services/spree/stock_locations/stock_items/create.rb +5 -2
- data/app/services/spree/stock_reservations/extend.rb +3 -1
- data/app/services/spree/stock_reservations/reserve.rb +12 -7
- data/app/services/spree/store_credits/apply.rb +9 -1
- data/app/services/spree/taxons/add_products.rb +4 -2
- data/app/services/spree/taxons/regenerate_products.rb +5 -2
- data/app/services/spree/taxons/remove_products.rb +4 -2
- data/app/services/spree/update_check.rb +7 -31
- data/app/tools/spree/agent_tools/describe_resource.rb +3 -0
- data/app/tools/spree/agent_tools/get_resource.rb +1 -1
- data/app/tools/spree/agent_tools/resource_write.rb +1 -1
- data/app/tools/spree/agent_tools/search_resources.rb +42 -10
- data/app/workflows/spree/carts/add_item.rb +52 -1
- data/app/workflows/spree/carts/complete.rb +14 -2
- data/app/workflows/spree/carts/recalculate.rb +1 -1
- data/app/workflows/spree/fulfillments/update.rb +1 -1
- data/app/workflows/spree/orders/cancel.rb +3 -1
- data/app/workflows/spree/payments/capture.rb +2 -2
- data/app/workflows/spree/payments/handle_webhook.rb +7 -3
- data/app/workflows/spree/seller_transfers/create.rb +1 -1
- data/app/workflows/spree/sellers/approve.rb +6 -0
- data/app/workflows/spree/sellers/create.rb +5 -2
- data/app/workflows/spree/stock_levels/bulk_upsert.rb +19 -7
- data/config/locales/be.yml +1 -1
- data/config/locales/en.yml +12 -0
- data/config/locales/fr.yml +1 -1
- data/config/locales/lt.yml +1 -1
- data/config/locales/ru.yml +1 -1
- data/config/locales/uk.yml +1 -1
- data/db/migrate/20240303174340_fix_spree_stock_item_unique_index.rb +14 -10
- data/db/migrate/20260710000001_rename_taxons_to_categories.rb +1 -1
- data/db/migrate/20260728000004_rename_shipping_to_fulfillment_and_delivery.rb +1 -1
- data/db/migrate/20260806000001_add_store_id_to_spree_tax_rates_and_categories.rb +1 -1
- data/db/migrate/20260807130001_add_country_state_codes_to_consumers.rb +1 -1
- data/db/migrate/20260809000001_rename_metafields_to_custom_fields.rb +1 -1
- data/db/migrate/20260809150001_promote_shipping_categories_to_delivery_profiles.rb +1 -1
- data/db/migrate/20260811000001_add_delivery_tracking_to_fulfillments.rb +1 -1
- data/db/migrate/20260814000001_rename_stock_items_to_stock_levels.rb +13 -7
- data/db/migrate/20260824000001_add_store_to_spree_media.rb +1 -1
- data/db/migrate/20260828100001_unify_import_and_export_tenancy.rb +1 -1
- data/db/migrate/20261016000001_remove_default_from_spree_tax_rates_included_in_price.rb +1 -1
- data/lib/spree/agent_tool.rb +3 -3
- data/lib/spree/agent_tools/default_catalog.rb +2 -2
- data/lib/spree/agent_tools/legacy_tools.rb +1 -1
- data/lib/spree/agent_tools/operation_tool.rb +1 -1
- data/lib/spree/agent_tools/record_summary.rb +8 -2
- data/lib/spree/agent_tools/resource_map.rb +82 -7
- data/lib/spree/core/dependencies.rb +10 -10
- data/lib/spree/core/engine.rb +14 -0
- data/lib/spree/core/number_generator.rb +4 -3
- data/lib/spree/core/preferences/preferable.rb +1 -1
- data/lib/spree/core/preferences/preferable_class_methods.rb +5 -1
- data/lib/spree/core/pricing/resolver.rb +2 -2
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +48 -10
- data/lib/spree/i18n.rb +6 -2
- data/lib/spree/localized_number.rb +1 -1
- data/lib/spree/removed_apis.rb +274 -0
- data/lib/spree/reporting/default_vocabulary.rb +26 -6
- data/lib/spree/testing_support/factories/digital_asset_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_level_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -1
- data/lib/spree/testing_support/factories/wishlist_item_factory.rb +1 -1
- data/lib/spree/testing_support/i18n.rb +7 -2
- data/lib/spree/testing_support/order_walkthrough.rb +5 -2
- data/lib/spree/upgrades/5_6_to_6_0/manifest.yml +14 -14
- data/lib/tasks/carts_migration.rake +1 -1
- data/lib/tasks/categories_and_collections.rake +1 -1
- data/lib/tasks/deliveries_migration.rake +1 -1
- data/lib/tasks/delivery_method_rules_migration.rake +1 -1
- data/lib/tasks/delivery_migration.rake +1 -1
- data/lib/tasks/delivery_profiles_migration.rake +2 -2
- data/lib/tasks/diagnostics.rake +11 -0
- data/lib/tasks/fold_store_credit_categories.rake +1 -1
- data/lib/tasks/migrate_country_state_codes.rake +1 -1
- data/lib/tasks/migrate_returns.rake +4 -4
- data/lib/tasks/migrate_rich_text_to_columns.rake +1 -1
- data/lib/tasks/store_settings.rake +1 -1
- data/lib/tasks/typed_stock_movements_migration.rake +1 -1
- metadata +13 -6
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class Diagnostics
|
|
3
|
+
# The most recent Spree errors, for the diagnostics report. Subscribed to
|
|
4
|
+
# the Rails error reporter, so it sees what Spree reports with
|
|
5
|
+
# +Rails.error.report+ as well as unhandled request and job errors.
|
|
6
|
+
#
|
|
7
|
+
# Only the exception class and where it was raised are kept, never the
|
|
8
|
+
# message: messages carry customer data (emails, addresses, values echoed
|
|
9
|
+
# from a row) and the report ends up in a public issue. Frames from the
|
|
10
|
+
# host application become +app/[redacted]+ and frames from private gems
|
|
11
|
+
# +gem/[redacted]+, so the merchant's own code is not shared either.
|
|
12
|
+
#
|
|
13
|
+
# Entries live in Rails.cache, so a cache clear empties the log. With a
|
|
14
|
+
# per-process memory store a restart does too, and each process keeps its
|
|
15
|
+
# own.
|
|
16
|
+
class ErrorLog
|
|
17
|
+
CACHE_KEY = 'spree/diagnostics/errors'.freeze
|
|
18
|
+
LIMIT = 50
|
|
19
|
+
FRAME_LIMIT = 10
|
|
20
|
+
HOST_FRAME = 'app/[redacted]'.freeze
|
|
21
|
+
PRIVATE_FRAME = 'gem/[redacted]'.freeze
|
|
22
|
+
RECORDING = :spree_diagnostics_error_log_recording
|
|
23
|
+
|
|
24
|
+
# One backtrace line, as the report shows it.
|
|
25
|
+
Frame = Struct.new(:text, :spree, :host)
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
# @return [Array<Hash>] newest first
|
|
29
|
+
def entries
|
|
30
|
+
Array(Rails.cache.read(CACHE_KEY)).sort_by { |entry| entry[:last_seen_at] }.reverse
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [void]
|
|
34
|
+
def clear
|
|
35
|
+
Rails.cache.delete(CACHE_KEY)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Gem directories and the application's, longest first, so a path is
|
|
39
|
+
# matched by the most specific root: a gem vendored inside the app is
|
|
40
|
+
# that gem, and an app inside a gem's directory (a test dummy app) is
|
|
41
|
+
# the app. Built once per process, since every reported error needs it.
|
|
42
|
+
#
|
|
43
|
+
# @return [Array<Array(String, Proc)>] path prefix and the frame it makes
|
|
44
|
+
def roots
|
|
45
|
+
@roots ||= Gem.loaded_specs.values.map { |spec| [spec.full_gem_path + File::SEPARATOR, gem_frame(spec)] }.
|
|
46
|
+
push([Rails.root.to_s + File::SEPARATOR, ->(_) { Frame.new(HOST_FRAME, false, true) }]).
|
|
47
|
+
sort_by { |root, _| -root.length }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def gem_frame(spec)
|
|
53
|
+
return ->(_) { Frame.new(PRIVATE_FRAME, false, false) } unless Stack.public_gem?(spec)
|
|
54
|
+
|
|
55
|
+
spree = Stack.spree_gem?(spec)
|
|
56
|
+
->(relative) { Frame.new("#{spec.name}-#{spec.version}/#{relative}", spree, false) }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Rails error subscriber interface. Leaves out refused requests: an
|
|
61
|
+
# error Rails answers with a 4xx (an invalid record, a missing one, a
|
|
62
|
+
# bad parameter) is the client's, not a bug. Never raises, and never
|
|
63
|
+
# recurses: a cache store that reports its own failure to Rails.error
|
|
64
|
+
# would otherwise call back in here.
|
|
65
|
+
def report(error, context:, source: nil, **)
|
|
66
|
+
return if Thread.current[RECORDING] || client_error?(error)
|
|
67
|
+
|
|
68
|
+
recording do
|
|
69
|
+
frames = frames_for(error)
|
|
70
|
+
record(error.class.name, source, frames, request_id(context)) if spree_error?(source, frames)
|
|
71
|
+
end
|
|
72
|
+
rescue StandardError
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
# Only the outermost call clears the flag: a nested call that returned
|
|
79
|
+
# early would otherwise re-arm recursion for the rest of the outer one.
|
|
80
|
+
def recording
|
|
81
|
+
Thread.current[RECORDING] = true
|
|
82
|
+
yield
|
|
83
|
+
ensure
|
|
84
|
+
Thread.current[RECORDING] = nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def record(error_class, source, frames, request_id)
|
|
88
|
+
now = Time.current.iso8601
|
|
89
|
+
fingerprint = [error_class, (frames.find(&:spree) || frames.first)&.text].join('|')
|
|
90
|
+
entries = Array(Rails.cache.read(CACHE_KEY))
|
|
91
|
+
entry = entries.find { |existing| existing[:fingerprint] == fingerprint }
|
|
92
|
+
|
|
93
|
+
if entry
|
|
94
|
+
entry.merge!(count: entry[:count] + 1, last_seen_at: now, request_id: request_id || entry[:request_id])
|
|
95
|
+
else
|
|
96
|
+
entries << { fingerprint: fingerprint, error_class: error_class, source: source, frames: frames.map(&:text),
|
|
97
|
+
request_id: request_id, count: 1, first_seen_at: now, last_seen_at: now }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
kept = entries.sort_by { |existing| existing[:last_seen_at] }.last(LIMIT)
|
|
101
|
+
Rails.cache.write(CACHE_KEY, kept)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Spree's when Spree reported it, or when Spree code ran between the
|
|
105
|
+
# raise and the host application. Every request also passes through
|
|
106
|
+
# Spree's middleware further out, so frames past the first host
|
|
107
|
+
# application frame don't count: an error raised in the merchant's own
|
|
108
|
+
# controller is theirs.
|
|
109
|
+
def spree_error?(source, frames)
|
|
110
|
+
source.to_s.start_with?('spree') || frames.take_while { |frame| !frame.host }.any?(&:spree)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Where the error was raised, then every Spree frame and the host
|
|
114
|
+
# application's (collapsed), so the Spree line that led to a library
|
|
115
|
+
# error isn't pushed out by the library's own frames. Ruby's own frames
|
|
116
|
+
# are dropped.
|
|
117
|
+
def frames_for(error)
|
|
118
|
+
origin, *rest = Array(error.backtrace).filter_map { |line| frame(line) }
|
|
119
|
+
[origin, *rest.select { |frame| frame.spree || frame.host }].compact.
|
|
120
|
+
chunk_while { |a, b| a.host && b.host }.map(&:first).first(FRAME_LIMIT)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def frame(line)
|
|
124
|
+
path = line.sub(/:in .*\z/, '')
|
|
125
|
+
root, make = self.class.roots.find { |prefix, _| path.start_with?(prefix) }
|
|
126
|
+
make&.call(path.delete_prefix(root))
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def client_error?(error)
|
|
130
|
+
ActionDispatch::ExceptionWrapper.status_code_for_exception(error.class.name) < 500
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def request_id(context)
|
|
134
|
+
controller = context[:controller]
|
|
135
|
+
context[:request_id] || (controller.request.request_id if controller.respond_to?(:request))
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class Diagnostics
|
|
3
|
+
# One part of the diagnostics report. A subclass names its rows; each row
|
|
4
|
+
# is read separately and reports "unavailable" when reading it fails, since
|
|
5
|
+
# a half-broken installation is exactly when the report is needed.
|
|
6
|
+
#
|
|
7
|
+
# Everything a row returns ends up in a public GitHub issue, so a row adds
|
|
8
|
+
# one deliberately chosen fact: never a name, URL, email or credential, and
|
|
9
|
+
# records only by prefixed ID.
|
|
10
|
+
#
|
|
11
|
+
# class MyGem::DiagnosticsSection < Spree::Diagnostics::Section
|
|
12
|
+
# def title = 'My gem'
|
|
13
|
+
#
|
|
14
|
+
# def rows
|
|
15
|
+
# { 'Mode' => -> { MyGem.config.mode } }
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# Spree.diagnostics_sections << 'MyGem::DiagnosticsSection'
|
|
20
|
+
class Section
|
|
21
|
+
UNAVAILABLE = 'unavailable'.freeze
|
|
22
|
+
|
|
23
|
+
attr_reader :store
|
|
24
|
+
|
|
25
|
+
# @param store [Spree::Store]
|
|
26
|
+
def initialize(store)
|
|
27
|
+
@store = store
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @return [String]
|
|
31
|
+
def key
|
|
32
|
+
self.class.name.demodulize.underscore
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [String]
|
|
36
|
+
def title
|
|
37
|
+
raise NotImplementedError
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @return [Hash{String => Proc}] label => reader
|
|
41
|
+
def rows
|
|
42
|
+
raise NotImplementedError
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @return [Array<Hash>] `{ label:, value: }`, values as strings
|
|
46
|
+
def to_rows
|
|
47
|
+
rows.filter_map do |label, reader|
|
|
48
|
+
value = read(reader)
|
|
49
|
+
{ label: label, value: value } unless value.nil?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def read(reader)
|
|
56
|
+
format_value(reader.call)
|
|
57
|
+
rescue StandardError
|
|
58
|
+
UNAVAILABLE
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def format_value(value)
|
|
62
|
+
case value
|
|
63
|
+
when nil then nil
|
|
64
|
+
when true then 'yes'
|
|
65
|
+
when false then 'no'
|
|
66
|
+
when Array then value.compact_blank.join(', ').presence || 'none'
|
|
67
|
+
else value.to_s
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class Diagnostics
|
|
3
|
+
# The sections core ships. Extensions add their own through
|
|
4
|
+
# {Spree.diagnostics_sections}.
|
|
5
|
+
module Sections
|
|
6
|
+
class Platform < Section
|
|
7
|
+
def title = 'Spree'
|
|
8
|
+
|
|
9
|
+
def rows
|
|
10
|
+
{
|
|
11
|
+
'Version' => -> { ::Spree.version },
|
|
12
|
+
'Gems' => -> { Stack.spree_gems.map { |name, version| "#{name} #{version}" } },
|
|
13
|
+
'Other gems built on Spree' => -> { extensions }
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
# Only a count: the other gems built on Spree are often the merchant's
|
|
20
|
+
# own, private ones, and their names don't belong in a public issue.
|
|
21
|
+
def extensions
|
|
22
|
+
listed = Stack.spree_gems
|
|
23
|
+
Gem.loaded_specs.values.count do |spec|
|
|
24
|
+
!listed.key?(spec.name) && (Stack.spree_gem?(spec) || spec.runtime_dependencies.any? { |dependency| listed.key?(dependency.name) })
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Runtime < Section
|
|
30
|
+
def title = 'Runtime'
|
|
31
|
+
|
|
32
|
+
def rows
|
|
33
|
+
{
|
|
34
|
+
'Ruby' => -> { "#{RUBY_VERSION} (#{RUBY_PLATFORM})" },
|
|
35
|
+
'Rails' => -> { Rails.version },
|
|
36
|
+
'Environment' => -> { Rails.env },
|
|
37
|
+
'Operating system' => -> { operating_system },
|
|
38
|
+
'Web server' => -> { web_server }
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def operating_system
|
|
45
|
+
uname = Etc.uname
|
|
46
|
+
"#{uname[:sysname]} #{uname[:release]} #{uname[:machine]}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def web_server
|
|
50
|
+
"Puma #{::Puma::Const::PUMA_VERSION}" if defined?(::Puma::Const::PUMA_VERSION)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class Infrastructure < Section
|
|
55
|
+
def title = 'Infrastructure'
|
|
56
|
+
|
|
57
|
+
def rows
|
|
58
|
+
{
|
|
59
|
+
'Database' => -> { [Stack.database, database_version].compact.join(' ') },
|
|
60
|
+
'Queue adapter' => -> { ActiveJob::Base.queue_adapter_name },
|
|
61
|
+
'Cache store' => -> { Rails.cache.class.name.demodulize.underscore },
|
|
62
|
+
'File storage' => -> { Rails.application.config.active_storage.service }
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
# PostgreSQL reports 180006 for 18.6.
|
|
69
|
+
def database_version
|
|
70
|
+
version = ActiveRecord::Base.connection.database_version
|
|
71
|
+
version.is_a?(Integer) ? "#{version / 10_000}.#{version % 10_000}" : version.to_s
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Settings changed from their defaults. Only flags, numbers and
|
|
76
|
+
# fixed-choice strings are shown: free-form strings can hold URLs,
|
|
77
|
+
# names or credentials, so they are never reported, whatever they are.
|
|
78
|
+
class Preferences < Section
|
|
79
|
+
REPORTABLE_TYPES = %i[boolean integer decimal].freeze
|
|
80
|
+
|
|
81
|
+
def title = 'Changed settings'
|
|
82
|
+
|
|
83
|
+
def rows
|
|
84
|
+
config_rows.merge(store_rows)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def config_rows
|
|
90
|
+
config = ::Spree::Config
|
|
91
|
+
config.class.types.each_with_object({}) do |(name, type), rows|
|
|
92
|
+
next if config.class.deprecations[name] || REPORTABLE_TYPES.exclude?(type)
|
|
93
|
+
|
|
94
|
+
rows["config.#{name}"] = lambda do
|
|
95
|
+
value = config.get(name)
|
|
96
|
+
value unless value == config.class.defaults[name]
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def store_rows
|
|
102
|
+
store.class.preference_definitions.each_with_object({}) do |(name, definition), rows|
|
|
103
|
+
next unless reportable?(name, definition)
|
|
104
|
+
|
|
105
|
+
rows["store.#{name}"] = lambda do
|
|
106
|
+
value = store.get_preference(name)
|
|
107
|
+
value unless value == store.preference_default(name)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def reportable?(name, definition)
|
|
113
|
+
return false if definition[:internal] || definition[:deprecated]
|
|
114
|
+
|
|
115
|
+
REPORTABLE_TYPES.include?(definition[:type]) ||
|
|
116
|
+
(definition[:type] == :string && store.preference_choices(name).is_a?(Array))
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class Diagnostics
|
|
3
|
+
# The installation's stack and rough size, shared by the update check's
|
|
4
|
+
# heartbeat and the diagnostics report so the two never describe the same
|
|
5
|
+
# installation differently.
|
|
6
|
+
module Stack
|
|
7
|
+
# Order-of-magnitude buckets: enough to tell a hobby install from a large
|
|
8
|
+
# merchant, never an exact figure.
|
|
9
|
+
BUCKETS = {
|
|
10
|
+
0..0 => '0',
|
|
11
|
+
1..9 => '1-9',
|
|
12
|
+
10..99 => '10-99',
|
|
13
|
+
100..999 => '100-999',
|
|
14
|
+
1_000..9_999 => '1k-9k',
|
|
15
|
+
10_000..99_999 => '10k-99k'
|
|
16
|
+
}.freeze
|
|
17
|
+
LARGEST_BUCKET = '100k+'.freeze
|
|
18
|
+
SPREE_URL = %r{\Ahttps?://(www\.)?(spreecommerce\.org|github\.com/spree/)}
|
|
19
|
+
|
|
20
|
+
module_function
|
|
21
|
+
|
|
22
|
+
# @return [String] the database adapter, e.g. +postgresql+
|
|
23
|
+
def database
|
|
24
|
+
ActiveRecord::Base.connection_db_config.adapter
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Spree's own gems and published Spree extensions, by name. A private
|
|
28
|
+
# gem named spree_* is left out: its name is the merchant's business.
|
|
29
|
+
#
|
|
30
|
+
# @return [Hash{String => String}] gem name => version
|
|
31
|
+
def spree_gems
|
|
32
|
+
Gem.loaded_specs.values.select { |spec| spree_gem?(spec) && public_gem?(spec) }.
|
|
33
|
+
sort_by(&:name).to_h { |spec| [spec.name, spec.version.to_s] }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @param spec [Gem::Specification]
|
|
37
|
+
# @return [Boolean]
|
|
38
|
+
def spree_gem?(spec)
|
|
39
|
+
spec.name == 'spree' || spec.name.start_with?('spree_')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Whether a gem's name can appear in a public bug report: one of Spree's
|
|
43
|
+
# own, or one installed from rubygems.org. Gems from a path, git or a
|
|
44
|
+
# private gem server are often the merchant's own code.
|
|
45
|
+
#
|
|
46
|
+
# @param spec [Gem::Specification]
|
|
47
|
+
# @return [Boolean]
|
|
48
|
+
def public_gem?(spec)
|
|
49
|
+
return true if [spec.homepage, *spec.metadata.values].any? { |url| url.to_s.match?(SPREE_URL) }
|
|
50
|
+
|
|
51
|
+
source = spec.respond_to?(:source) ? spec.source : nil
|
|
52
|
+
source.is_a?(Bundler::Source::Rubygems) && source.remotes.all? { |remote| remote.host == 'rubygems.org' }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @return [Boolean] whether this installation serves an admin dashboard
|
|
56
|
+
def dashboard_served?
|
|
57
|
+
(defined?(Spree::Dashboard) && Spree::Dashboard.dist_path.present?) || Spree::Config.dashboard_url.present?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @param count [Integer]
|
|
61
|
+
# @return [String]
|
|
62
|
+
def bucket(count)
|
|
63
|
+
BUCKETS.find { |range, _| range.cover?(count) }&.last || LARGEST_BUCKET
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @return [String, nil] nil when the installation has no sellers
|
|
67
|
+
def seller_bucket
|
|
68
|
+
count = Spree::Seller.count
|
|
69
|
+
bucket(count) if count.positive?
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
# An anonymised description of this installation for bug reports: versions,
|
|
3
|
+
# stack, store setup by prefixed ID, providers, changed settings and recent
|
|
4
|
+
# Spree errors. The rake task, the Admin API and the CLI all render this one
|
|
5
|
+
# report, so what a maintainer reads is the same wherever it came from.
|
|
6
|
+
#
|
|
7
|
+
# report = Spree::Diagnostics.report(store: Spree::Current.store)
|
|
8
|
+
# puts report.to_markdown
|
|
9
|
+
class Diagnostics
|
|
10
|
+
ISSUE_URL = 'https://github.com/spree/spree/issues/new?template=bug_report.yml'.freeze
|
|
11
|
+
# GitHub refuses very long URLs; past this the issue form opens empty and
|
|
12
|
+
# the report is pasted by hand.
|
|
13
|
+
MAX_ISSUE_URL_LENGTH = 6000
|
|
14
|
+
|
|
15
|
+
# A built report. Never persisted.
|
|
16
|
+
class Report
|
|
17
|
+
attr_reader :generated_at, :sections, :errors
|
|
18
|
+
|
|
19
|
+
def initialize(generated_at:, sections:, errors:)
|
|
20
|
+
@generated_at = generated_at
|
|
21
|
+
@sections = sections
|
|
22
|
+
@errors = errors
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [String] Spree version, for the report's headline
|
|
26
|
+
def spree_version
|
|
27
|
+
Spree.version
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @return [Hash]
|
|
31
|
+
def to_h
|
|
32
|
+
{ generated_at: generated_at.iso8601, spree_version: spree_version, sections: sections, errors: errors,
|
|
33
|
+
markdown: to_markdown, issue_url: issue_url, issue_prefilled: issue_prefilled? }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# A new GitHub issue with the report filled in, or the empty form when
|
|
37
|
+
# the report is too long for a URL.
|
|
38
|
+
#
|
|
39
|
+
# @return [String]
|
|
40
|
+
def issue_url
|
|
41
|
+
@issue_url ||= begin
|
|
42
|
+
prefilled = "#{ISSUE_URL}&environment=#{ERB::Util.url_encode(to_markdown)}"
|
|
43
|
+
prefilled.length <= MAX_ISSUE_URL_LENGTH ? prefilled : ISSUE_URL
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @return [Boolean]
|
|
48
|
+
def issue_prefilled?
|
|
49
|
+
issue_url != ISSUE_URL
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# GitHub-flavoured Markdown, folded into a <details> block so it doesn't
|
|
53
|
+
# take over the issue it is pasted into.
|
|
54
|
+
#
|
|
55
|
+
# @return [String]
|
|
56
|
+
def to_markdown
|
|
57
|
+
@to_markdown ||= render_markdown
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def render_markdown
|
|
63
|
+
lines = ['<details>', "<summary>Spree #{spree_version} diagnostics (#{generated_at.iso8601})</summary>", '']
|
|
64
|
+
|
|
65
|
+
sections.each do |section|
|
|
66
|
+
next if section[:rows].empty?
|
|
67
|
+
|
|
68
|
+
lines.push("**#{section[:title]}**", '', '| | |', '| --- | --- |')
|
|
69
|
+
section[:rows].each { |row| lines << "| #{escape(row[:label])} | #{escape(row[:value])} |" }
|
|
70
|
+
lines << ''
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if errors
|
|
74
|
+
lines.push('**Recent errors**', '')
|
|
75
|
+
lines << 'None recorded.' if errors.empty?
|
|
76
|
+
errors.each do |error|
|
|
77
|
+
lines << "- `#{error[:error_class]}` × #{error[:count]}, last #{error[:last_seen_at]}#{" (#{error[:source]})" if error[:source]}"
|
|
78
|
+
error[:frames].each { |frame| lines << " - `#{frame}`" }
|
|
79
|
+
end
|
|
80
|
+
lines << ''
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
lines << '</details>'
|
|
84
|
+
lines.join("\n")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def escape(value)
|
|
88
|
+
value.to_s.gsub(/[\\|]/) { |char| "\\#{char}" }.gsub(/[\r\n]+/, ' ')
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class << self
|
|
93
|
+
# @param store [Spree::Store]
|
|
94
|
+
# @param extra_sections [Array<Hash>] what only the caller can see, as
|
|
95
|
+
# `{ title:, rows: { label => value } }` — the CLI's tooling, the
|
|
96
|
+
# dashboard's browser
|
|
97
|
+
# @param errors [Boolean] false to leave recent errors out, as
|
|
98
|
+
# +spree info+ does: it runs in its own process, which rarely sees
|
|
99
|
+
# the server's error log
|
|
100
|
+
# @return [Spree::Diagnostics::Report]
|
|
101
|
+
def report(store: Spree::Store.default, extra_sections: [], errors: true)
|
|
102
|
+
Report.new(generated_at: Time.current, errors: (recent_errors if errors),
|
|
103
|
+
sections: sections_for(store) + extra_sections.map { |section| extra_section(section) })
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private
|
|
107
|
+
|
|
108
|
+
def sections_for(store)
|
|
109
|
+
Spree.diagnostics_sections.filter_map do |class_name|
|
|
110
|
+
section = class_name.to_s.constantize.new(store)
|
|
111
|
+
{ key: section.key, title: section.title, rows: section.to_rows }
|
|
112
|
+
rescue StandardError
|
|
113
|
+
{ key: class_name.to_s.demodulize.underscore, title: class_name.to_s.demodulize.titleize,
|
|
114
|
+
rows: [{ label: 'Error', value: 'This section could not be read' }] }
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def extra_section(section)
|
|
119
|
+
title = section[:title].to_s
|
|
120
|
+
rows = section[:rows].to_h.map { |label, value| { label: label.to_s, value: value.to_s } }
|
|
121
|
+
{ key: title.parameterize(separator: '_'), title: title, rows: rows }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# A failing cache must not take the rest of the report down with it.
|
|
125
|
+
def recent_errors
|
|
126
|
+
ErrorLog.entries.map { |entry| entry.except(:fingerprint) }
|
|
127
|
+
rescue StandardError
|
|
128
|
+
[]
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -13,6 +13,7 @@ module Spree
|
|
|
13
13
|
ensure_decimals!
|
|
14
14
|
@store = row.store
|
|
15
15
|
@seller = import.seller
|
|
16
|
+
ensure_seller_options_exist! if seller.present?
|
|
16
17
|
# Before the product is saved: rows are not wrapped in a transaction,
|
|
17
18
|
# so an unknown location must fail the row with nothing written.
|
|
18
19
|
@stock_location = import_stock_location if attributes['inventory_count'].present?
|
|
@@ -351,6 +352,24 @@ module Spree
|
|
|
351
352
|
Spree::OptionType.for_store(store)
|
|
352
353
|
end
|
|
353
354
|
|
|
355
|
+
# A seller builds variants from the marketplace's option types and
|
|
356
|
+
# values and never adds to them, so a name the store does not have
|
|
357
|
+
# fails the row before the product is written. Rows of one product
|
|
358
|
+
# repeat the same options, so the answer is cached per combination.
|
|
359
|
+
def ensure_seller_options_exist!
|
|
360
|
+
pairs = options.map { |option| [option[:option_name], option[:option_value]] }
|
|
361
|
+
return if pairs.empty?
|
|
362
|
+
|
|
363
|
+
unknown = cached_lookup(:unknown_seller_options, pairs) { Spree::OptionType.unknown_options(store, pairs) }.first
|
|
364
|
+
return unless unknown
|
|
365
|
+
|
|
366
|
+
raise ArgumentError, I18n.t('spree.product_import_unknown_option_type', name: unknown[:name]) unless unknown[:option_type]
|
|
367
|
+
|
|
368
|
+
raise ArgumentError, I18n.t('spree.product_import_unknown_option_value',
|
|
369
|
+
option_type: unknown[:option_type].label.presence || unknown[:option_type].name,
|
|
370
|
+
value: unknown[:value])
|
|
371
|
+
end
|
|
372
|
+
|
|
354
373
|
def find_or_create_option_value!(option_type, label)
|
|
355
374
|
cached_lookup(:option_value, option_type.id, label) do
|
|
356
375
|
begin
|
|
@@ -2,7 +2,8 @@ module Spree
|
|
|
2
2
|
module Newsletter
|
|
3
3
|
class Subscribe
|
|
4
4
|
def initialize(email:, current_user: nil, current_store: nil, redirect_url: nil)
|
|
5
|
-
@
|
|
5
|
+
@submitted_email = email.to_s.strip
|
|
6
|
+
@email = @submitted_email.downcase
|
|
6
7
|
@current_user = current_user
|
|
7
8
|
@current_store = current_store || Spree::Store.current
|
|
8
9
|
@redirect_url = redirect_url
|
|
@@ -32,7 +33,7 @@ module Spree
|
|
|
32
33
|
|
|
33
34
|
private
|
|
34
35
|
|
|
35
|
-
attr_reader :email, :current_user, :current_store, :redirect_url
|
|
36
|
+
attr_reader :email, :submitted_email, :current_user, :current_store, :redirect_url
|
|
36
37
|
|
|
37
38
|
def publish_subscription_requested
|
|
38
39
|
event_name = 'newsletter_subscriber.subscription_requested'
|
|
@@ -62,7 +63,10 @@ module Spree
|
|
|
62
63
|
@known_user ||= if current_user&.email.to_s.casecmp?(email.to_s)
|
|
63
64
|
current_user
|
|
64
65
|
else
|
|
65
|
-
|
|
66
|
+
# Customer emails are not downcased on save, so try the
|
|
67
|
+
# address as submitted before the normalized form.
|
|
68
|
+
Spree.customer_class.find_by(email: submitted_email) ||
|
|
69
|
+
Spree.customer_class.find_by(email: email)
|
|
66
70
|
end
|
|
67
71
|
end
|
|
68
72
|
end
|
|
@@ -8,12 +8,12 @@ module Spree
|
|
|
8
8
|
# @param order [Spree::Order]
|
|
9
9
|
# @param approver [Object, nil] who approved it — an admin user or an
|
|
10
10
|
# API key (see Spree.actor_classes)
|
|
11
|
-
# @param level [String, nil] deprecated and ignored — removed in Spree 6.
|
|
12
|
-
# @param note [String, nil] deprecated and ignored — removed in Spree 6.
|
|
11
|
+
# @param level [String, nil] deprecated and ignored — removed in Spree 6.3
|
|
12
|
+
# @param note [String, nil] deprecated and ignored — removed in Spree 6.3
|
|
13
13
|
# @return [Spree::ServiceModule::Result]
|
|
14
14
|
def call(order:, approver: nil, level: nil, note: nil)
|
|
15
15
|
if level.present? || note.present?
|
|
16
|
-
Spree::Deprecation.warn('Spree::Orders::Approve no longer accepts level or note — they were never read and will be removed in Spree 6.
|
|
16
|
+
Spree::Deprecation.warn('Spree::Orders::Approve no longer accepts level or note — they were never read and will be removed in Spree 6.3.')
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
changes = { considered_risky: false, approved_at: Time.current }
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
module Orders
|
|
3
|
-
# @deprecated Use {Spree::Customers::Create}; removed in 6.
|
|
3
|
+
# @deprecated Use {Spree::Customers::Create}; removed in 6.3. Note that
|
|
4
4
|
# core no longer sends a welcome email — implement it on the
|
|
5
5
|
# `user.created` event or the `customers.create.after_create` hook.
|
|
6
6
|
class CreateUserAccount
|
|
7
7
|
def self.call(order:, accepts_email_marketing: false)
|
|
8
8
|
Spree::Deprecation.warn(
|
|
9
|
-
'Spree::Orders::CreateUserAccount is deprecated and will be removed in Spree 6.
|
|
9
|
+
'Spree::Orders::CreateUserAccount is deprecated and will be removed in Spree 6.3. ' \
|
|
10
10
|
'Use Spree::Customers::Create (Spree.customer_create_workflow) instead. ' \
|
|
11
11
|
'Core no longer sends a welcome email — send it from a user.created subscriber or the customers.create.after_create hook.'
|
|
12
12
|
)
|
|
@@ -11,12 +11,23 @@ module Spree
|
|
|
11
11
|
# @param options [Hash] accepted for signature compatibility and ignored
|
|
12
12
|
# @return [Spree::ServiceModule::Result] value is the removed line item
|
|
13
13
|
def call(order:, line_item:, options: {})
|
|
14
|
-
result =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
14
|
+
result = nil
|
|
15
|
+
# A savepoint: a caller's transaction (the API's order lock) joins the
|
|
16
|
+
# workflow's own, so a late rejection would otherwise commit the removal.
|
|
17
|
+
ActiveRecord::Base.transaction(requires_new: true) do
|
|
18
|
+
result = Spree.order_upsert_items_workflow.call(
|
|
19
|
+
order: order,
|
|
20
|
+
items: [{ variant_id: line_item.variant_id, quantity: 0 }]
|
|
21
|
+
)
|
|
22
|
+
raise ActiveRecord::Rollback if result.failure?
|
|
23
|
+
end
|
|
24
|
+
return failure(line_item, result.error) if result.failure?
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
# The order workflow leaves totals to its caller.
|
|
27
|
+
Spree::Orders::Recalculate.call(order: order)
|
|
28
|
+
order.update_statuses!
|
|
29
|
+
|
|
30
|
+
success(line_item)
|
|
20
31
|
end
|
|
21
32
|
end
|
|
22
33
|
end
|