spree_core 6.0.0.rc5 → 6.0.0.rc7
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/images/save_from_url_job.rb +24 -5
- data/app/models/concerns/spree/account_deactivation.rb +54 -0
- data/app/models/concerns/spree/calculator/currency_amounts.rb +19 -6
- data/app/models/concerns/spree/derived_number.rb +1 -1
- data/app/models/concerns/spree/has_external_references.rb +24 -16
- data/app/models/concerns/spree/prefixed_id.rb +15 -5
- data/app/models/concerns/spree/publishable.rb +47 -1
- data/app/models/concerns/spree/purchase/addresses.rb +19 -4
- data/app/models/concerns/spree/purchase/digital_items.rb +17 -3
- data/app/models/concerns/spree/purchase/freight.rb +2 -1
- data/app/models/concerns/spree/purchase/payment_processing.rb +7 -1
- data/app/models/concerns/spree/purchase/quantity_rules.rb +2 -0
- data/app/models/concerns/spree/stores/channels.rb +3 -1
- data/app/models/concerns/spree/translatable_resource.rb +6 -1
- data/app/models/spree/admin_user.rb +1 -0
- data/app/models/spree/base.rb +33 -1
- data/app/models/spree/calculator/shipping/digital_delivery.rb +3 -1
- data/app/models/spree/calculator/shipping/flat_rate.rb +3 -1
- data/app/models/spree/calculator/shipping/per_item.rb +3 -1
- data/app/models/spree/cart.rb +4 -1
- data/app/models/spree/category.rb +76 -5
- data/app/models/spree/channel.rb +79 -40
- data/app/models/spree/company.rb +45 -2
- data/app/models/spree/customer.rb +1 -1
- data/app/models/spree/customer_group.rb +59 -41
- data/app/models/spree/delivery_method.rb +18 -8
- data/app/models/spree/delivery_profile.rb +18 -0
- data/app/models/spree/digital_asset.rb +14 -0
- data/app/models/spree/event.rb +20 -5
- data/app/models/spree/fulfillment.rb +8 -1
- data/app/models/spree/fulfillment_changer.rb +3 -1
- data/app/models/spree/fulfillment_item.rb +11 -0
- data/app/models/spree/import.rb +20 -2
- data/app/models/spree/order_routing/strategy/rules.rb +4 -1
- data/app/models/spree/price_list.rb +15 -0
- data/app/models/spree/product/channels.rb +16 -8
- data/app/models/spree/product.rb +7 -2
- data/app/models/spree/return.rb +8 -1
- data/app/models/spree/search_provider/base.rb +8 -3
- data/app/models/spree/search_provider/database.rb +2 -10
- data/app/models/spree/seller.rb +35 -5
- data/app/models/spree/seller_balance.rb +28 -0
- data/app/models/spree/seller_requirements/delivery_method.rb +20 -2
- data/app/models/spree/stock/coordinator.rb +7 -4
- data/app/models/spree/stock/estimator.rb +6 -0
- data/app/models/spree/stock/inventory_unit_builder.rb +14 -2
- data/app/models/spree/stock/packer.rb +39 -5
- data/app/models/spree/stock/quantifier.rb +16 -0
- data/app/models/spree/stock_location.rb +15 -8
- data/app/models/spree/store.rb +31 -2
- data/app/models/spree/store_credit.rb +4 -4
- data/app/models/spree/variant.rb +23 -6
- data/app/models/spree/webhook_endpoint.rb +45 -11
- data/app/services/spree/carts/price_items.rb +3 -0
- data/app/services/spree/carts/split_by_seller.rb +3 -1
- data/app/services/spree/catalogs/set_product_terms.rb +8 -3
- data/app/services/spree/collections/add_products.rb +1 -1
- data/app/services/spree/collections/regenerate_products.rb +1 -3
- data/app/services/spree/collections/remove_products.rb +1 -1
- data/app/services/spree/newsletter/subscribe.rb +9 -1
- data/app/services/spree/order_groups/allocate_payments.rb +7 -5
- data/app/services/spree/orders/update.rb +19 -0
- data/app/services/spree/product_memberships.rb +16 -6
- data/app/services/spree/products/duplicator.rb +12 -4
- data/app/services/spree/search_provider/custom_field_schema.rb +10 -2
- data/app/services/spree/stock_levels/correct.rb +11 -4
- data/app/services/spree/stock_reservations/reserve.rb +1 -1
- data/app/services/spree/stores/provision_defaults.rb +11 -7
- data/app/services/spree/tags/bulk_add.rb +16 -6
- data/app/workflows/spree/carts/complete.rb +25 -9
- data/app/workflows/spree/carts/upsert_items.rb +31 -4
- data/app/workflows/spree/customers/anonymize.rb +2 -2
- data/app/workflows/spree/digital_assets/create.rb +56 -0
- data/app/workflows/spree/digital_assets/update.rb +44 -0
- data/app/workflows/spree/digital_assets/writing.rb +108 -0
- data/app/workflows/spree/imports/start_mapping.rb +3 -1
- data/app/workflows/spree/orders/complete.rb +12 -5
- data/app/workflows/spree/payments/capture.rb +12 -0
- data/app/workflows/spree/products/nested_attributes.rb +12 -28
- data/app/workflows/spree/products/propose.rb +9 -4
- data/app/workflows/spree/stock_levels/bulk_upsert.rb +28 -13
- data/app/workflows/spree/variants/nested_attributes.rb +35 -10
- data/config/locales/en.yml +10 -0
- data/db/migrate/20261022000001_store_credit_actor_polymorphic.rb +13 -0
- data/db/migrate/20261023100001_add_deactivated_at_to_spree_admin_users.rb +7 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +87 -0
- data/lib/spree/checkout/default_requirements.rb +12 -2
- data/lib/spree/core/dependencies.rb +5 -0
- data/lib/spree/core/permissions/default_catalog.rb +7 -2
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/reporting/default_vocabulary.rb +1 -1
- data/lib/spree/testing_support/factories/product_factory.rb +10 -4
- data/lib/spree/testing_support/factories/store_factory.rb +4 -1
- data/lib/spree/upgrades/5_6_to_6_0/manifest.yml +10 -0
- data/lib/tasks/backfill_tagging_tenants.rake +35 -0
- data/lib/tasks/seller_sample_data.rake +114 -112
- metadata +13 -6
data/config/locales/en.yml
CHANGED
|
@@ -463,6 +463,9 @@ en:
|
|
|
463
463
|
required_for_carton_purchase_unit: is required when the purchase unit is cartons
|
|
464
464
|
spree/webhook_endpoint:
|
|
465
465
|
attributes:
|
|
466
|
+
subscriptions:
|
|
467
|
+
invalid_pattern: 'must hold event names or patterns such as order.* or *.created (rejected: %{entries})'
|
|
468
|
+
too_many: can hold at most %{count} entries
|
|
466
469
|
url:
|
|
467
470
|
internal_address_not_allowed: must not point to an internal or private network address
|
|
468
471
|
invalid_url: must be a valid http or https URL
|
|
@@ -685,6 +688,8 @@ en:
|
|
|
685
688
|
canceler: Canceler
|
|
686
689
|
cannot_be_destroyed: Order cannot be destroyed.
|
|
687
690
|
capture: Capture
|
|
691
|
+
capture_amount_not_positive: The capture amount must be greater than zero.
|
|
692
|
+
capture_exceeds_payment_amount: The capture amount cannot exceed the payment amount.
|
|
688
693
|
cart: Cart
|
|
689
694
|
cart_already_updated: The cart has already been updated.
|
|
690
695
|
cart_completion_in_progress: The cart is being completed. Please retry in a moment.
|
|
@@ -817,6 +822,11 @@ en:
|
|
|
817
822
|
digital_delivery: Digital Delivery
|
|
818
823
|
digital_assets: Digital assets
|
|
819
824
|
digital_assets_attachment_must_be_private: Upload the file to private storage before attaching it
|
|
825
|
+
digital_assets_content_type_list_invalid: 'Not a content type: %{types}. Use the type/subtype form, such as application/pdf'
|
|
826
|
+
digital_assets_content_type_not_accepted: "%{content_type} files are not accepted on this marketplace"
|
|
827
|
+
digital_assets_provider_takes_no_file: This file is delivered by the marketplace's own system, so a replacement file cannot be uploaded
|
|
828
|
+
digital_assets_sellers_disabled: This marketplace does not let sellers add or change digital files
|
|
829
|
+
digital_assets_upload_not_found: The uploaded file could not be found. Upload it again
|
|
820
830
|
discontinued: Discontinued
|
|
821
831
|
discontinued_variants_present: Some line items in this order have products that are no longer available.
|
|
822
832
|
display_delivery_range: Delivery in %{delivery_range} business days
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Makes a store credit's issuer polymorphic, so a credit issued with a secret
|
|
2
|
+
# API key — a return an integration refunds to store credit — records the key
|
|
3
|
+
# rather than failing. See docs/plans/6.0-action-actors.md.
|
|
4
|
+
class StoreCreditActorPolymorphic < ActiveRecord::Migration[8.1]
|
|
5
|
+
def change
|
|
6
|
+
# Nullable with no default: the type is data, filled by
|
|
7
|
+
# `rake spree:upgrade:backfill_actor_types`. Until it runs, the
|
|
8
|
+
# transitional reader resolves these rows through the admin user class.
|
|
9
|
+
add_column :spree_store_credits, :created_by_type, :string
|
|
10
|
+
add_index :spree_store_credits, [:created_by_type, :created_by_id],
|
|
11
|
+
name: 'index_spree_store_credits_on_created_by_actor'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Lets a staff account be switched off without deleting it, so records that
|
|
2
|
+
# name it as their actor keep their history. See Spree::AccountDeactivation.
|
|
3
|
+
class AddDeactivatedAtToSpreeAdminUsers < ActiveRecord::Migration[8.1]
|
|
4
|
+
def change
|
|
5
|
+
add_column :spree_admin_users, :deactivated_at, :datetime
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -77,4 +77,91 @@ Dummy::Application.configure do
|
|
|
77
77
|
config.active_record.encryption.key_derivation_salt = 'spree-test-key-derivation-salt'
|
|
78
78
|
|
|
79
79
|
routes.default_url_options = { host: 'localhost', port: 3000 }
|
|
80
|
+
|
|
81
|
+
# An N+1 inside an API request fails the example instead of being logged,
|
|
82
|
+
# so a serializer or model method that queries once per record cannot land
|
|
83
|
+
# unnoticed. Wrap a deliberately repeated lookup in Prosopite.pause.
|
|
84
|
+
if defined?(Prosopite)
|
|
85
|
+
# Hooked from Spree's own test app rather than declared in the
|
|
86
|
+
# controller, so a host application that bundles Prosopite for itself is
|
|
87
|
+
# never opted into Spree's guard. Prepended so the lookups made by the
|
|
88
|
+
# authentication and parent callbacks are scanned too.
|
|
89
|
+
config.to_prepare do
|
|
90
|
+
if defined?(Spree::Api::V3::BaseController)
|
|
91
|
+
Spree::Api::V3::BaseController.prepend_around_action { |_controller, action| Prosopite.scan(&action) }
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
Prosopite.rails_logger = true
|
|
96
|
+
# Raise only under RSpec, where a report belongs to the example that
|
|
97
|
+
# caused it. The same dummy app serves a real server for the SDK and
|
|
98
|
+
# browser suites, and there a raise becomes a 500 the client cannot act
|
|
99
|
+
# on — those runs log instead. SPREE_N_PLUS_ONE_GUARD overrides either
|
|
100
|
+
# way ('raise', 'log').
|
|
101
|
+
running_specs = ENV.key?('TEST_ENV_NUMBER') || $PROGRAM_NAME.end_with?('rspec')
|
|
102
|
+
guard_mode = ENV.fetch('SPREE_N_PLUS_ONE_GUARD') { running_specs ? 'raise' : 'log' }
|
|
103
|
+
Prosopite.raise = guard_mode == 'raise'
|
|
104
|
+
|
|
105
|
+
# The Rails cleaner keeps only the host app's frames, which hides the
|
|
106
|
+
# serializer or model line that issued the repeated query.
|
|
107
|
+
Prosopite.backtrace_cleaner = ActiveSupport::BacktraceCleaner.new.tap do |cleaner|
|
|
108
|
+
cleaner.add_silencer { |line| line.include?('/gems/') || line.include?('/rspec') }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# The guard covers what a request reads. Writes run their callbacks one
|
|
112
|
+
# record at a time by design — a `dependent: :destroy` cascade, a number
|
|
113
|
+
# or uniqueness probe per created row — so statements issued under a
|
|
114
|
+
# save or destroy are not reported.
|
|
115
|
+
Prosopite.allow_stack_paths = [
|
|
116
|
+
%r{active_record/persistence\.rb:\d+:in '[^']*#(save|save!|destroy|destroy!|touch)'},
|
|
117
|
+
# A touch is a write too, and Spree overrides `touch` in its own
|
|
118
|
+
# concern, so the frame is Spree's rather than Active Record's.
|
|
119
|
+
%r{active_record/timestamp\.rb:\d+:in '[^']*#touch'},
|
|
120
|
+
%r{/spree/publishable\.rb:\d+:in '[^']*#touch'},
|
|
121
|
+
%r{/paranoia\.rb:\d+:in '[^']*destroy'},
|
|
122
|
+
# Validations run before the persistence frame starts, so a uniqueness
|
|
123
|
+
# or ladder probe on the row being saved needs its own entry.
|
|
124
|
+
%r{active_record/validations\.rb:\d+:in '[^']*#(save|save!)'},
|
|
125
|
+
# after_commit callbacks are the same per-record write work, deferred
|
|
126
|
+
# until the transaction that wrote the rows ends.
|
|
127
|
+
%r{active_record/transactions\.rb:\d+:in '[^']*#committed!'},
|
|
128
|
+
# Locking a row re-reads it, once per row the caller is about to write.
|
|
129
|
+
%r{active_record/locking/pessimistic\.rb:\d+:in '[^']*#lock!'},
|
|
130
|
+
# A product payload writes each nested variant and media row through its
|
|
131
|
+
# own workflow — SKU probe, option lookup, blob resolution — once per row.
|
|
132
|
+
%r{/spree/products/nested_attributes\.rb:\d+:in '[^']*#(write_variant|apply_media)'},
|
|
133
|
+
# A settlement is swept per currency, and each sweep writes its own payout.
|
|
134
|
+
%r{/spree/seller_payouts/sweep\.rb:\d+:in '[^']*#collect_transfers'},
|
|
135
|
+
# A split checkout re-sums and then places each seller's order it just
|
|
136
|
+
# wrote, one workflow run per order.
|
|
137
|
+
%r{/spree/carts/split_by_seller\.rb:\d+:in '[^']*#resum_totals'},
|
|
138
|
+
%r{/spree/orders/complete\.rb:\d+:in '[^']*#place_sibling'},
|
|
139
|
+
# Each requested line is priced, stock-checked, saved and taxed as it
|
|
140
|
+
# is written.
|
|
141
|
+
%r{/spree/carts/upsert_items\.rb:\d+:in '[^']*#apply_item'}
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
# A purchase's billing and shipping addresses, and a transfer's two
|
|
145
|
+
# warehouses, are two links into one table read through the same code,
|
|
146
|
+
# so one record reads as a repeat. Lists still load each link in one
|
|
147
|
+
# query for the whole page.
|
|
148
|
+
Prosopite.ignore_queries = [
|
|
149
|
+
/FROM [`"]?(spree_addresses|spree_stock_locations)[`"]? WHERE (.+ AND )?[`"]?\1[`"]?\.[`"]?id[`"]? (=|IN)/
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
# Prosopite fingerprints through pg_query, which rejects SQLite's `?`
|
|
153
|
+
# binds, so SQLite borrows the text normalizer written for MySQL. That
|
|
154
|
+
# normalizer blanks anything double-quoted, which is a string literal in
|
|
155
|
+
# MySQL but an identifier in SQLite — left alone it erases every table
|
|
156
|
+
# name, collapsing unrelated queries into one fingerprint and reporting
|
|
157
|
+
# a single record's distinct associations as an N+1. Re-quoting
|
|
158
|
+
# identifiers as backticks first keeps table names in the fingerprint.
|
|
159
|
+
Prosopite.singleton_class.prepend(Module.new do
|
|
160
|
+
def fingerprint(query)
|
|
161
|
+
return super unless ActiveRecord::Base.connection_db_config.adapter == 'sqlite3'
|
|
162
|
+
|
|
163
|
+
mysql_fingerprint(query.gsub(/"([^"]*)"/) { "`#{Regexp.last_match(1)}`" })
|
|
164
|
+
end
|
|
165
|
+
end)
|
|
166
|
+
end
|
|
80
167
|
end
|
|
@@ -107,7 +107,11 @@ module Spree
|
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
def completion_line_items
|
|
110
|
-
|
|
110
|
+
# Everything the discontinuation and stock checks read, for every line
|
|
111
|
+
# at once.
|
|
112
|
+
@completion_line_items ||= @cart.line_items.includes(
|
|
113
|
+
variant: [{ product: %i[store product_publications] }, { stock_levels: %i[stock_location active_stock_reservations] }]
|
|
114
|
+
).to_a
|
|
111
115
|
end
|
|
112
116
|
|
|
113
117
|
def delivery_step_required?
|
|
@@ -125,7 +129,13 @@ module Spree
|
|
|
125
129
|
# What checkout has to collect, which is the whole total unless an
|
|
126
130
|
# arrangement collects only part of it up front.
|
|
127
131
|
def payment_satisfied?
|
|
128
|
-
@cart.
|
|
132
|
+
paid = if @cart.read_association_in_memory?(:payments)
|
|
133
|
+
@cart.payments.reject(&:has_invalid_status?).sum(BigDecimal('0'), &:amount)
|
|
134
|
+
else
|
|
135
|
+
@cart.payments.valid.sum(:amount)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
paid >= @cart.amount_due_at_checkout
|
|
129
139
|
end
|
|
130
140
|
|
|
131
141
|
# Advisory rather than completion-only: the buyer has to be told the
|
|
@@ -186,6 +186,11 @@ module Spree
|
|
|
186
186
|
# handler sees a nested payload and the variants endpoint alike
|
|
187
187
|
variant_create_workflow: 'Spree::Variants::Create',
|
|
188
188
|
variant_update_workflow: 'Spree::Variants::Update',
|
|
189
|
+
|
|
190
|
+
# digital assets — the operator's and the seller's endpoints and the
|
|
191
|
+
# nested list on a product write all run through these
|
|
192
|
+
digital_asset_create_workflow: 'Spree::DigitalAssets::Create',
|
|
193
|
+
digital_asset_update_workflow: 'Spree::DigitalAssets::Update',
|
|
189
194
|
product_archive_workflow: 'Spree::Products::Archive',
|
|
190
195
|
product_draft_workflow: 'Spree::Products::Draft',
|
|
191
196
|
|
|
@@ -165,7 +165,7 @@ module Spree
|
|
|
165
165
|
[Spree::Store, Spree::PaymentMethod, Spree::Gateway,
|
|
166
166
|
Spree::DeliveryZone, Spree::DeliveryZoneMember,
|
|
167
167
|
Spree::StockLocation, Spree::DeliveryProfile,
|
|
168
|
-
Spree::Market, Spree::TaxCategory, Spree::TaxRate,
|
|
168
|
+
Spree::Market, Spree::TaxCategory, Spree::TaxRate,
|
|
169
169
|
Spree::RefundReason, Spree::ReturnReason, Spree::ClaimReason,
|
|
170
170
|
Spree::OrderCancellationReason, Spree::TaxExemptionReason, Spree::Channel,
|
|
171
171
|
Spree::OrderRoutingRule, Spree::CustomFieldDefinition, Spree::Policy]
|
|
@@ -201,7 +201,12 @@ module Spree
|
|
|
201
201
|
})
|
|
202
202
|
catalog.register_scope(:integrations, group: :settings, resources: -> { [Spree::Integration] })
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
# The CORS allowlist is a credential as much as a key is: an origin on
|
|
205
|
+
# it may call the cookie-authenticated refresh endpoint from a browser
|
|
206
|
+
# and read back any signed-in admin's access token. So it sits with
|
|
207
|
+
# API keys rather than settings, under a scope a delegated OAuth token
|
|
208
|
+
# never holds.
|
|
209
|
+
catalog.register_scope(:api_keys, group: :access, resources: -> { [Spree::ApiKey, Spree::AllowedOrigin] })
|
|
205
210
|
# Connecting an AI agent hands a third party a standing credential to
|
|
206
211
|
# the store, so it is its own permission rather than part of settings
|
|
207
212
|
# — a merchandiser who may edit a delivery zone is not thereby someone
|
data/lib/spree/core/version.rb
CHANGED
|
@@ -541,7 +541,7 @@ module Spree
|
|
|
541
541
|
# and tax category per row and throw all of it away.
|
|
542
542
|
hydrate: lambda { |store, ids, _params|
|
|
543
543
|
currency = Spree::Current.currency || store.default_currency
|
|
544
|
-
products = store.products.with_deleted.includes(:primary_media).where(id: ids)
|
|
544
|
+
products = store.products.with_deleted.includes(:primary_media, default_variant: :prices).where(id: ids)
|
|
545
545
|
products.to_h do |product|
|
|
546
546
|
amount = product.default_variant&.amount_in(currency)
|
|
547
547
|
[product.id, {
|
|
@@ -15,8 +15,11 @@ FactoryBot.define do
|
|
|
15
15
|
end
|
|
16
16
|
after(:create) do |product|
|
|
17
17
|
if product.store&.default_channel && product.product_publications.empty?
|
|
18
|
-
Spree::ProductPublication.create
|
|
19
|
-
|
|
18
|
+
# Built through the association, not Spree::ProductPublication.create!:
|
|
19
|
+
# the `empty?` above loads and caches the collection, so a row written
|
|
20
|
+
# around it leaves the product holding an association that reads empty
|
|
21
|
+
# while the table has the row.
|
|
22
|
+
product.product_publications.create!(
|
|
20
23
|
channel: product.store.default_channel,
|
|
21
24
|
published_at: product.available_on,
|
|
22
25
|
unpublished_at: product.discontinue_on
|
|
@@ -69,8 +72,11 @@ FactoryBot.define do
|
|
|
69
72
|
# keep passing. Production callers must publish explicitly via the
|
|
70
73
|
# Admin SDK / Dashboard create form.
|
|
71
74
|
if product.store&.default_channel && product.product_publications.empty?
|
|
72
|
-
Spree::ProductPublication.create
|
|
73
|
-
|
|
75
|
+
# Built through the association, not Spree::ProductPublication.create!:
|
|
76
|
+
# the `empty?` above loads and caches the collection, so a row written
|
|
77
|
+
# around it leaves the product holding an association that reads empty
|
|
78
|
+
# while the table has the row.
|
|
79
|
+
product.product_publications.create!(
|
|
74
80
|
channel: product.store.default_channel,
|
|
75
81
|
published_at: product.available_on,
|
|
76
82
|
unpublished_at: product.discontinue_on
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
FactoryBot.define do
|
|
2
2
|
factory :store, class: Spree::Store do
|
|
3
|
-
|
|
3
|
+
# The suite-wide default store outlives the process that created it, while
|
|
4
|
+
# a sequence restarts with every process, so the code also steps past
|
|
5
|
+
# whatever is already in the database.
|
|
6
|
+
sequence(:code) { |i| "spree_#{i + Spree::Store.unscoped.count}" }
|
|
4
7
|
name { 'Spree Test Store' }
|
|
5
8
|
url { 'www.example.com' }
|
|
6
9
|
mail_from_address { 'no-reply@example.com' }
|
|
@@ -819,3 +819,13 @@ steps:
|
|
|
819
819
|
Run AFTER the steps that create or move attachments (media, categories,
|
|
820
820
|
returns), so their files are covered. Idempotent — files that already
|
|
821
821
|
have a store are skipped.
|
|
822
|
+
|
|
823
|
+
- id: backfill_tagging_tenants
|
|
824
|
+
name: "Stamp the store on taggings written without one"
|
|
825
|
+
task: "spree:upgrade:backfill_tagging_tenants"
|
|
826
|
+
notes: |
|
|
827
|
+
Tags added through the bulk endpoints carried no store on their
|
|
828
|
+
taggings, and the admin tag list filters by it, so those tags were
|
|
829
|
+
missing from the list. This stamps the store of the record on every
|
|
830
|
+
tagging without one, for each taggable that keeps its taggings per
|
|
831
|
+
store. Idempotent — taggings that already carry a store are skipped.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
namespace :spree do
|
|
2
|
+
namespace :upgrade do
|
|
3
|
+
desc <<~DESC
|
|
4
|
+
Stamps the store on taggings written without one, for every taggable
|
|
5
|
+
that keeps its taggings per store. Tags added through the bulk endpoints
|
|
6
|
+
before Spree 6.0 carried no store, and the admin tag list filters by it,
|
|
7
|
+
so those tags were missing from the list. Idempotent — taggings that
|
|
8
|
+
already carry a store are skipped.
|
|
9
|
+
DESC
|
|
10
|
+
task backfill_tagging_tenants: :environment do
|
|
11
|
+
total = 0
|
|
12
|
+
|
|
13
|
+
Spree.taggable_types.map(&:constantize).each do |taggable|
|
|
14
|
+
column = taggable.try(:tenant_column)
|
|
15
|
+
next if column.blank?
|
|
16
|
+
|
|
17
|
+
count = 0
|
|
18
|
+
ActsAsTaggableOn::Tagging.where(taggable_type: taggable.polymorphic_name, tenant: nil).in_batches do |taggings|
|
|
19
|
+
tenants = taggable.unscoped.where(id: taggings.select(:taggable_id)).pluck(:id, column).to_h
|
|
20
|
+
|
|
21
|
+
tenants.compact.group_by { |_id, tenant| tenant }.each do |tenant, pairs|
|
|
22
|
+
count += taggings.where(taggable_id: pairs.map(&:first)).update_all(tenant: tenant.to_s)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
next if count.zero?
|
|
27
|
+
|
|
28
|
+
total += count
|
|
29
|
+
puts " #{taggable.name}: #{count} tagging(s) stamped with the #{column}."
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
puts total.zero? ? ' Nothing to backfill.' : " Backfilled #{total} tagging(s)."
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -10,132 +10,134 @@ namespace :spree do
|
|
|
10
10
|
abort "spree:sellers:sample_data is for development and test only (RAILS_ENV=#{Rails.env})."
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
Spree::Events.disable do
|
|
14
|
+
store = Spree::Store.default || Spree::Store.first
|
|
15
|
+
abort 'No store found — run db:seed first.' if store.nil?
|
|
16
|
+
|
|
17
|
+
email = ENV.fetch('SELLER_EMAIL', 'seller@example.com')
|
|
18
|
+
password = ENV.fetch('SELLER_PASSWORD', 'spree123')
|
|
19
|
+
|
|
20
|
+
seller_name = ENV.fetch('SELLER_NAME', 'Bright Sparks')
|
|
21
|
+
seller = Spree::Seller.find_by(name: seller_name, store: store)
|
|
22
|
+
|
|
23
|
+
# Through the workflow, so the sample seller gets the stock location a
|
|
24
|
+
# real one does — without it their returns have nowhere to go and the
|
|
25
|
+
# checklist can never be finished.
|
|
26
|
+
if seller.nil?
|
|
27
|
+
result = Spree.seller_create_workflow.call(
|
|
28
|
+
store: store, attributes: { name: seller_name, status: 'approved' }
|
|
29
|
+
)
|
|
30
|
+
abort "Could not create the sample seller: #{result.value.errors.full_messages.to_sentence}" unless result.success?
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
seller = result.value
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# An existing account keeps its own password. Re-running the task then
|
|
37
|
-
# tells you to use the credentials you already have, rather than silently
|
|
38
|
-
# changing them underneath you.
|
|
39
|
-
if owner
|
|
40
|
-
puts "Reusing existing user #{email} — password unchanged."
|
|
41
|
-
else
|
|
42
|
-
owner = Spree.admin_user_class.create!(
|
|
43
|
-
email: email, password: password, first_name: 'Ada', last_name: 'Lovelace'
|
|
44
|
-
)
|
|
45
|
-
end
|
|
35
|
+
owner = Spree.admin_user_class.find_by(email: email)
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
# An existing account keeps its own password. Re-running the task then
|
|
38
|
+
# tells you to use the credentials you already have, rather than silently
|
|
39
|
+
# changing them underneath you.
|
|
40
|
+
if owner
|
|
41
|
+
puts "Reusing existing user #{email} — password unchanged."
|
|
42
|
+
else
|
|
43
|
+
owner = Spree.admin_user_class.create!(
|
|
44
|
+
email: email, password: password, first_name: 'Ada', last_name: 'Lovelace'
|
|
45
|
+
)
|
|
46
|
+
end
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
# something to show without having to send an email first.
|
|
51
|
-
invitee = ENV.fetch('SELLER_INVITEE', 'pending@example.com')
|
|
52
|
-
unless seller.invitations.pending.exists?(email: invitee)
|
|
53
|
-
seller.invitations.create!(email: invitee, role: seller.default_user_role, inviter: owner)
|
|
54
|
-
end
|
|
48
|
+
seller.add_user(owner)
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
Spree::SellerRequirements::ReturnsAddress.create!(store: store, position: 3, active: true, required: true)
|
|
63
|
-
Spree::SellerRequirements::Attestation.create!(
|
|
64
|
-
store: store, position: 4, active: true, required: true,
|
|
65
|
-
name: 'Confirm you can ship within two working days'
|
|
66
|
-
)
|
|
67
|
-
Spree::SellerRequirements::OperatorReview.create!(
|
|
68
|
-
store: store, position: 5, active: true, required: false,
|
|
69
|
-
name: 'Marketplace background check'
|
|
70
|
-
)
|
|
71
|
-
end
|
|
50
|
+
# One outstanding offer, so the panel's pending-invitations card has
|
|
51
|
+
# something to show without having to send an email first.
|
|
52
|
+
invitee = ENV.fetch('SELLER_INVITEE', 'pending@example.com')
|
|
53
|
+
unless seller.invitations.pending.exists?(email: invitee)
|
|
54
|
+
seller.invitations.create!(email: invitee, role: seller.default_user_role, inviter: owner)
|
|
55
|
+
end
|
|
72
56
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
email: "sample-buyer-#{index + 1}@example.com",
|
|
88
|
-
status: 'placed', completed_at: (index + 1).weeks.ago,
|
|
89
|
-
total: 100 + (index * 25), item_total: 100 + (index * 25)
|
|
57
|
+
# A checklist to work through, so the panel's onboarding page and its
|
|
58
|
+
# nav counter have something to show. Skipped when the marketplace
|
|
59
|
+
# already defines its own.
|
|
60
|
+
if store.seller_requirements.none?
|
|
61
|
+
Spree::SellerRequirements::AcceptTerms.create!(store: store, position: 1, active: true, required: true)
|
|
62
|
+
Spree::SellerRequirements::BillingAddress.create!(store: store, position: 2, active: true, required: true)
|
|
63
|
+
Spree::SellerRequirements::ReturnsAddress.create!(store: store, position: 3, active: true, required: true)
|
|
64
|
+
Spree::SellerRequirements::Attestation.create!(
|
|
65
|
+
store: store, position: 4, active: true, required: true,
|
|
66
|
+
name: 'Confirm you can ship within two working days'
|
|
67
|
+
)
|
|
68
|
+
Spree::SellerRequirements::OperatorReview.create!(
|
|
69
|
+
store: store, position: 5, active: true, required: false,
|
|
70
|
+
name: 'Marketplace background check'
|
|
90
71
|
)
|
|
91
72
|
end
|
|
92
73
|
|
|
93
|
-
settled
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
74
|
+
# A fund ledger to read: a settled payout with the sales it covered, one
|
|
75
|
+
# still owed, and a sale not yet swept into either. Written directly
|
|
76
|
+
# rather than through fulfilment and the payout sweep — reaching those
|
|
77
|
+
# would mean placing and shipping real orders, which is a different
|
|
78
|
+
# task's job, and the screens under test read these rows either way.
|
|
79
|
+
provider = Spree::PayoutProvider::System.provider_key
|
|
80
|
+
currency = store.default_currency
|
|
81
|
+
|
|
82
|
+
if seller.seller_transfers.none?
|
|
83
|
+
# Each earning hangs off an order, because that is what a seller
|
|
84
|
+
# clicks through to from their ledger.
|
|
85
|
+
sample_orders = 5.times.map do |index|
|
|
86
|
+
Spree::Order.create!(
|
|
87
|
+
store: store, seller: seller, currency: currency,
|
|
88
|
+
email: "sample-buyer-#{index + 1}@example.com",
|
|
89
|
+
status: 'placed', completed_at: (index + 1).weeks.ago,
|
|
90
|
+
total: 100 + (index * 25), item_total: 100 + (index * 25)
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
settled = seller.seller_payouts.create!(
|
|
95
|
+
store: store, amount: 0, currency: currency, provider: provider, status: 'completed',
|
|
96
|
+
reference: 'BACS-SAMPLE-001',
|
|
97
|
+
period_start: 6.weeks.ago, period_end: 4.weeks.ago
|
|
98
|
+
)
|
|
99
|
+
owed = seller.seller_payouts.create!(
|
|
100
|
+
store: store, amount: 0, currency: currency, provider: provider, status: 'pending',
|
|
101
|
+
period_start: 3.weeks.ago, period_end: 1.week.ago
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Two settled, two owed, one still unswept — so the balance is a real
|
|
105
|
+
# subtraction rather than a single number, and the payouts queue has
|
|
106
|
+
# both a completed row and one to mark paid.
|
|
107
|
+
[[settled, 0], [settled, 1], [owed, 2], [owed, 3], [nil, 4]].each do |payout, index|
|
|
108
|
+
order = sample_orders[index]
|
|
109
|
+
seller.seller_transfers.create!(
|
|
110
|
+
store: store, order: order, payout: payout,
|
|
111
|
+
amount: Spree::Money::Rounding.to_currency(order.total * BigDecimal('0.85'), currency), currency: currency,
|
|
112
|
+
kind: 'earning', provider: provider, status: 'completed',
|
|
113
|
+
created_at: order.completed_at
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# A refund on the newest settled sale, so the reversal row and the
|
|
118
|
+
# negative amount both appear on the earnings screens.
|
|
119
|
+
original = seller.seller_transfers.earnings.order(:created_at).last
|
|
108
120
|
seller.seller_transfers.create!(
|
|
109
|
-
store: store, order: order,
|
|
110
|
-
amount: Spree::Money::Rounding.to_currency(
|
|
111
|
-
kind: '
|
|
112
|
-
created_at: order.completed_at
|
|
121
|
+
store: store, order: original.order, reversed_from: original,
|
|
122
|
+
amount: -Spree::Money::Rounding.to_currency(original.amount / 2, currency), currency: currency,
|
|
123
|
+
kind: 'refund_reversal', provider: provider, status: 'completed'
|
|
113
124
|
)
|
|
114
|
-
end
|
|
115
125
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
seller.seller_transfers.create!(
|
|
120
|
-
store: store, order: original.order, reversed_from: original,
|
|
121
|
-
amount: -Spree::Money::Rounding.to_currency(original.amount / 2, currency), currency: currency,
|
|
122
|
-
kind: 'refund_reversal', provider: provider, status: 'completed'
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
# Each settlement is worth exactly what it claimed.
|
|
126
|
-
[settled, owed].each { |payout| payout.update!(amount: payout.transfers.sum(:amount)) }
|
|
127
|
-
end
|
|
126
|
+
# Each settlement is worth exactly what it claimed.
|
|
127
|
+
[settled, owed].each { |payout| payout.update!(amount: payout.transfers.sum(:amount)) }
|
|
128
|
+
end
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
progress = Spree::Sellers::Requirements.new(seller.reload).progress
|
|
131
|
+
balances = seller.balances
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
puts "Seller: #{seller.name} (#{seller.prefixed_id}, #{seller.status})"
|
|
134
|
+
puts "Checklist: #{progress[:done]}/#{progress[:total]} done"
|
|
135
|
+
puts "Sign in: #{email}"
|
|
136
|
+
puts "Pending: #{seller.invitations.pending.pluck(:email).join(', ')}"
|
|
137
|
+
puts "Ledger: #{seller.seller_transfers.count} earning(s), #{seller.seller_payouts.count} payout(s)"
|
|
138
|
+
balances.each do |balance|
|
|
139
|
+
puts "Balance: #{balance.display_balance} owed (#{balance.display_earned} earned, #{balance.display_paid} paid)"
|
|
140
|
+
end
|
|
139
141
|
end
|
|
140
142
|
end
|
|
141
143
|
end
|