spree_core 6.0.2 → 6.0.4
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/addresses/geocode_address_job.rb +6 -3
- data/app/jobs/spree/payments/handle_webhook_job.rb +12 -1
- data/app/jobs/spree/variants/remove_line_item_job.rb +5 -0
- data/app/models/concerns/spree/has_custom_fields.rb +4 -1
- data/app/models/concerns/spree/personal_data_matching.rb +5 -1
- data/app/models/concerns/spree/preference_schema.rb +5 -0
- data/app/models/concerns/spree/product_scopes.rb +2 -2
- data/app/models/concerns/spree/publishable.rb +26 -3
- data/app/models/concerns/spree/typed_associations.rb +53 -20
- data/app/models/spree/address.rb +2 -2
- data/app/models/spree/authentication/strategies/base_strategy.rb +10 -1
- data/app/models/spree/cart.rb +7 -2
- data/app/models/spree/collection.rb +7 -2
- data/app/models/spree/invitation.rb +6 -2
- data/app/models/spree/media.rb +25 -1
- data/app/models/spree/order.rb +6 -2
- data/app/models/spree/price.rb +3 -0
- data/app/models/spree/product.rb +21 -14
- data/app/models/spree/product_category.rb +7 -1
- data/app/models/spree/product_collection.rb +8 -1
- data/app/models/spree/promotion.rb +1 -2
- data/app/models/spree/seller.rb +93 -10
- data/app/models/spree/seller_requirements/complete_profile.rb +26 -7
- data/app/models/spree/stock_level.rb +30 -1
- data/app/models/spree/stock_movement.rb +1 -0
- data/app/services/spree/carts/destroy.rb +22 -6
- 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/newsletter/subscribe.rb +8 -4
- data/app/services/spree/orders/create_from_cart.rb +6 -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/stock_reservations/reserve.rb +9 -6
- data/app/services/spree/store_credits/apply.rb +9 -1
- data/app/services/spree/update_check.rb +7 -31
- data/app/tools/spree/agent_tools/create_export.rb +3 -1
- data/app/tools/spree/agent_tools/create_import.rb +1 -0
- data/app/tools/spree/agent_tools/create_media.rb +2 -1
- data/app/tools/spree/agent_tools/create_resource.rb +12 -4
- data/app/tools/spree/agent_tools/delete_resource.rb +12 -4
- data/app/tools/spree/agent_tools/describe_resource.rb +72 -6
- data/app/tools/spree/agent_tools/get_resource.rb +8 -5
- data/app/tools/spree/agent_tools/resource_write.rb +16 -3
- data/app/tools/spree/agent_tools/search_resources.rb +51 -20
- data/app/tools/spree/agent_tools/update_resource.rb +6 -6
- data/app/tools/spree/agent_tools/upload_file.rb +1 -0
- data/app/workflows/spree/carts/add_item.rb +51 -0
- data/app/workflows/spree/carts/complete.rb +18 -3
- data/app/workflows/spree/carts/merge.rb +25 -4
- data/app/workflows/spree/orders/complete.rb +39 -14
- data/app/workflows/spree/payments/handle_webhook.rb +7 -3
- data/app/workflows/spree/products/activate.rb +7 -2
- data/app/workflows/spree/products/archive.rb +7 -2
- data/app/workflows/spree/products/draft.rb +7 -2
- data/app/workflows/spree/products/status_transition.rb +24 -0
- 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 +11 -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/20260814000001_rename_stock_items_to_stock_levels.rb +13 -7
- data/lib/generators/spree/api_resource/api_resource_generator.rb +35 -3
- data/lib/generators/spree/api_resource/templates/admin_controller.rb.tt +9 -4
- data/lib/generators/spree/api_resource/templates/admin_integration_spec.rb.tt +74 -0
- data/lib/generators/spree/api_resource/templates/store_controller.rb.tt +11 -6
- data/lib/spree/agent_tool.rb +105 -1
- data/lib/spree/agent_tools/default_catalog.rb +16 -21
- data/lib/spree/agent_tools/legacy_tools.rb +212 -0
- data/lib/spree/agent_tools/operation_catalog.rb +206 -0
- data/lib/spree/agent_tools/operation_tool.rb +189 -0
- data/lib/spree/agent_tools/record_summary.rb +8 -2
- data/lib/spree/agent_tools/registry.rb +65 -31
- data/lib/spree/agent_tools/resource_map.rb +207 -9
- data/lib/spree/agent_tools.rb +3 -3
- data/lib/spree/core/dependencies_helper.rb +96 -40
- data/lib/spree/core/engine.rb +12 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +30 -2
- data/lib/spree/reporting/default_vocabulary.rb +25 -5
- data/lib/spree/testing_support/extension_rake.rb +12 -0
- data/lib/spree/upgrades/5_6_to_6_0/manifest.yml +34 -0
- data/lib/tasks/dependencies.rake +2 -2
- data/lib/tasks/diagnostics.rake +11 -0
- metadata +29 -7
- data/lib/spree/agent_tools/workflow_endpoints.rb +0 -88
- data/lib/spree/agent_tools/workflow_schema.rb +0 -279
- data/lib/spree/agent_tools/workflow_tool.rb +0 -654
|
@@ -10,7 +10,14 @@ module Spree
|
|
|
10
10
|
# cap the merged quantity) and previously required replacing the whole
|
|
11
11
|
# strategy class.
|
|
12
12
|
class Merge < Spree::Workflow
|
|
13
|
-
hooks :validate, :after_merge
|
|
13
|
+
hooks :validate, :after_items_moved, :after_merge
|
|
14
|
+
|
|
15
|
+
# Every line item of the folded-in cart → the line item now holding its
|
|
16
|
+
# quantity: itself when it moved across, or the surviving cart's line it
|
|
17
|
+
# was added to. Set before +after_items_moved+ runs.
|
|
18
|
+
#
|
|
19
|
+
# @return [Hash{Spree::LineItem => Spree::LineItem}]
|
|
20
|
+
attr_reader :line_item_map
|
|
14
21
|
|
|
15
22
|
# @param cart [Spree::Cart] the surviving cart
|
|
16
23
|
# @param other_cart [Spree::Cart, nil] the cart folded in and destroyed
|
|
@@ -28,6 +35,10 @@ module Spree
|
|
|
28
35
|
|
|
29
36
|
ApplicationRecord.transaction do
|
|
30
37
|
step :move_line_items
|
|
38
|
+
# Inside the transaction and before the absorbed lines are deleted,
|
|
39
|
+
# so an extension can move what it keeps against them.
|
|
40
|
+
run_hooks :after_items_moved
|
|
41
|
+
step :destroy_absorbed_line_items
|
|
31
42
|
step :associate_customer
|
|
32
43
|
step :destroy_drained_cart
|
|
33
44
|
end
|
|
@@ -46,19 +57,29 @@ module Spree
|
|
|
46
57
|
end
|
|
47
58
|
|
|
48
59
|
# A matching item absorbs the quantity; everything else is re-pointed
|
|
49
|
-
# at the surviving cart.
|
|
60
|
+
# at the surviving cart. Absorbed items are deleted only after the
|
|
61
|
+
# +after_items_moved+ hook.
|
|
50
62
|
def move_line_items
|
|
51
|
-
other_cart.line_items.reload.
|
|
63
|
+
@line_item_map = other_cart.line_items.reload.to_a.index_with do |other_line_item|
|
|
52
64
|
existing = matching_line_item(other_line_item)
|
|
53
65
|
|
|
54
66
|
if existing
|
|
55
67
|
existing.quantity += other_line_item.quantity
|
|
56
68
|
existing.save!
|
|
57
|
-
|
|
69
|
+
existing
|
|
58
70
|
else
|
|
59
71
|
other_line_item.update!(cart: cart, order: nil)
|
|
72
|
+
other_line_item
|
|
60
73
|
end
|
|
61
74
|
end
|
|
75
|
+
# Matching loaded the surviving cart's items before any moved in.
|
|
76
|
+
cart.line_items.reset
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def destroy_absorbed_line_items
|
|
80
|
+
line_item_map.each do |other_line_item, line_item|
|
|
81
|
+
other_line_item.destroy! unless other_line_item == line_item
|
|
82
|
+
end
|
|
62
83
|
end
|
|
63
84
|
|
|
64
85
|
# Options-aware comparison (personalization, gift wrapping) with a
|
|
@@ -7,6 +7,8 @@ module Spree
|
|
|
7
7
|
# may still need to process payments). Idempotent: an already-placed
|
|
8
8
|
# order halts successfully, so interrupted completions replay safely.
|
|
9
9
|
class Complete < Spree::Workflow
|
|
10
|
+
hooks :validate
|
|
11
|
+
|
|
10
12
|
# Set only when the order divided between sellers.
|
|
11
13
|
attr_reader :order_group
|
|
12
14
|
|
|
@@ -18,9 +20,13 @@ module Spree
|
|
|
18
20
|
# rollup work's call (docs/plans/6.0-b2b-wholesale-shipping.md phase 7)
|
|
19
21
|
# @param notify_customer [Boolean, nil] admin drafts pass false to
|
|
20
22
|
# complete silently; nil (checkout) leaves customer notification on
|
|
23
|
+
# @param validated [Boolean] the caller already ran its own veto, so the
|
|
24
|
+
# validate hook is skipped: checkout's finalize, whose
|
|
25
|
+
# carts.complete.validate ran before the payment was taken, and the
|
|
26
|
+
# orders a seller division places beside the one it came from
|
|
21
27
|
# @return [Spree::ServiceModule::Result] value is the order, or the
|
|
22
28
|
# Spree::OrderGroup when it divided between sellers
|
|
23
|
-
def perform(order:, payment_pending: false, notify_customer: nil)
|
|
29
|
+
def perform(order:, payment_pending: false, notify_customer: nil, validated: false)
|
|
24
30
|
super
|
|
25
31
|
|
|
26
32
|
order.notify_customer = notify_customer unless notify_customer.nil?
|
|
@@ -37,20 +43,30 @@ module Spree
|
|
|
37
43
|
|
|
38
44
|
step :ensure_not_canceled
|
|
39
45
|
|
|
40
|
-
order.with_lock do
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
placed_here = order.with_lock do
|
|
47
|
+
# A completion running alongside this one placed it while this one
|
|
48
|
+
# waited for the lock. Placed, not merely in that status: it may
|
|
49
|
+
# have been canceled since.
|
|
50
|
+
next false if order.reload.completed?
|
|
51
|
+
|
|
52
|
+
step :validate_order unless validated
|
|
53
|
+
step :process_payments unless payment_pending || !order.payment_required?
|
|
54
|
+
step :split_by_seller
|
|
55
|
+
step :finalize_fulfillments
|
|
56
|
+
step :place_order
|
|
57
|
+
step :freeze_tax_exemptions
|
|
58
|
+
step :use_coupon_codes
|
|
59
|
+
step :redeem_gift_card
|
|
60
|
+
step :fulfill_auto_fulfillments
|
|
61
|
+
step :ensure_digital_links
|
|
62
|
+
true
|
|
52
63
|
end
|
|
53
64
|
|
|
65
|
+
# The run that placed it announces it and finishes what follows; this
|
|
66
|
+
# one answers as a replay would, so nothing after placement happens
|
|
67
|
+
# twice.
|
|
68
|
+
halt!(order.order_group || order) unless placed_here
|
|
69
|
+
|
|
54
70
|
step :ensure_placed_status
|
|
55
71
|
step :release_stock_reservations
|
|
56
72
|
step :cancel_unused_payment_sessions
|
|
@@ -67,6 +83,14 @@ module Spree
|
|
|
67
83
|
failure(order, 'Order is canceled') if order.canceled?
|
|
68
84
|
end
|
|
69
85
|
|
|
86
|
+
# The extension veto, under the order's row lock: a handler sees the
|
|
87
|
+
# order as it is placed, and anything else that takes the lock to change
|
|
88
|
+
# it waits for the outcome. Rejecting rolls the lock back before any
|
|
89
|
+
# payment is processed.
|
|
90
|
+
def validate_order
|
|
91
|
+
run_hooks :validate
|
|
92
|
+
end
|
|
93
|
+
|
|
70
94
|
def process_payments
|
|
71
95
|
order.process_payments! unless payment_covered?
|
|
72
96
|
|
|
@@ -276,7 +300,8 @@ module Spree
|
|
|
276
300
|
end
|
|
277
301
|
|
|
278
302
|
def place_sibling(sibling)
|
|
279
|
-
result = Spree.order_complete_workflow.call(order: sibling, payment_pending: true, notify_customer: false
|
|
303
|
+
result = Spree.order_complete_workflow.call(order: sibling, payment_pending: true, notify_customer: false,
|
|
304
|
+
validated: true)
|
|
280
305
|
failure(order, result.error) if result.failure?
|
|
281
306
|
end
|
|
282
307
|
|
|
@@ -54,9 +54,13 @@ module Spree
|
|
|
54
54
|
# banks), and the capture webhook that follows must still be able to
|
|
55
55
|
# complete its payment. Not halt! — that is forbidden inside a
|
|
56
56
|
# transaction (there is nothing committed to halt with).
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
#
|
|
58
|
+
# Completing the owner is checked on its own, not folded into that
|
|
59
|
+
# guard: a payment can be completed (a synchronous confirmation, an
|
|
60
|
+
# earlier delivery) while the order is not, and a redelivery or job
|
|
61
|
+
# retry must still place the order or the buyer stays charged
|
|
62
|
+
# without one.
|
|
63
|
+
step :ensure_payment unless payment_session.reload.payment&.completed?
|
|
60
64
|
step :complete_session
|
|
61
65
|
step :complete_owner unless order.reload.completed?
|
|
62
66
|
end
|
|
@@ -5,6 +5,8 @@ module Spree
|
|
|
5
5
|
# after_transition, so a handler can veto the change before anything is
|
|
6
6
|
# written and see the product it applies to.
|
|
7
7
|
class Activate < Spree::Workflow
|
|
8
|
+
include StatusTransition
|
|
9
|
+
|
|
8
10
|
hooks :validate, :after_activate
|
|
9
11
|
|
|
10
12
|
# @param product [Spree::Product]
|
|
@@ -14,12 +16,15 @@ module Spree
|
|
|
14
16
|
|
|
15
17
|
run_hooks :validate
|
|
16
18
|
|
|
17
|
-
ApplicationRecord.transaction do
|
|
19
|
+
moved = ApplicationRecord.transaction do
|
|
20
|
+
next false if already_in?('active')
|
|
21
|
+
|
|
18
22
|
step :mark_active
|
|
19
23
|
run_hooks :after_activate
|
|
24
|
+
true
|
|
20
25
|
end
|
|
21
26
|
|
|
22
|
-
product.publish_event('product.activated')
|
|
27
|
+
product.publish_event('product.activated') if moved
|
|
23
28
|
success(product)
|
|
24
29
|
end
|
|
25
30
|
|
|
@@ -3,6 +3,8 @@ module Spree
|
|
|
3
3
|
# Takes a product off sale for good. Replaces the `archive` state machine
|
|
4
4
|
# event.
|
|
5
5
|
class Archive < Spree::Workflow
|
|
6
|
+
include StatusTransition
|
|
7
|
+
|
|
6
8
|
hooks :validate, :after_archive
|
|
7
9
|
|
|
8
10
|
# @param product [Spree::Product]
|
|
@@ -12,13 +14,16 @@ module Spree
|
|
|
12
14
|
|
|
13
15
|
run_hooks :validate
|
|
14
16
|
|
|
15
|
-
ApplicationRecord.transaction do
|
|
17
|
+
moved = ApplicationRecord.transaction do
|
|
18
|
+
next false if already_in?('archived')
|
|
19
|
+
|
|
16
20
|
step :mark_archived
|
|
17
21
|
step :withdraw_submission
|
|
18
22
|
run_hooks :after_archive
|
|
23
|
+
true
|
|
19
24
|
end
|
|
20
25
|
|
|
21
|
-
product.publish_event('product.archived')
|
|
26
|
+
product.publish_event('product.archived') if moved
|
|
22
27
|
success(product)
|
|
23
28
|
end
|
|
24
29
|
|
|
@@ -3,6 +3,8 @@ module Spree
|
|
|
3
3
|
# Returns a product to draft, hiding it from the storefront while it is
|
|
4
4
|
# worked on. Replaces the `draft` state machine event.
|
|
5
5
|
class Draft < Spree::Workflow
|
|
6
|
+
include StatusTransition
|
|
7
|
+
|
|
6
8
|
hooks :validate, :after_draft
|
|
7
9
|
|
|
8
10
|
# @param product [Spree::Product]
|
|
@@ -12,17 +14,20 @@ module Spree
|
|
|
12
14
|
|
|
13
15
|
run_hooks :validate
|
|
14
16
|
|
|
15
|
-
ApplicationRecord.transaction do
|
|
17
|
+
moved = ApplicationRecord.transaction do
|
|
18
|
+
next false if already_in?('draft')
|
|
19
|
+
|
|
16
20
|
step :mark_draft
|
|
17
21
|
step :withdraw_submission
|
|
18
22
|
run_hooks :after_draft
|
|
23
|
+
true
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
# Its siblings (Activate, Archive, Propose, Approve, Reject) all
|
|
22
27
|
# announce themselves, and this one now carries a marketplace meaning
|
|
23
28
|
# too: taking a listing back withdraws an open submission, which a
|
|
24
29
|
# seller's integration has the same reason to hear about.
|
|
25
|
-
product.publish_event('product.drafted')
|
|
30
|
+
product.publish_event('product.drafted') if moved
|
|
26
31
|
|
|
27
32
|
success(product)
|
|
28
33
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Products
|
|
3
|
+
# What the status workflows share: whether the product is already in the
|
|
4
|
+
# status a move would put it in, read under a row lock inside the
|
|
5
|
+
# workflow's own transaction.
|
|
6
|
+
#
|
|
7
|
+
# Two requests for the same move otherwise both read the old status, both
|
|
8
|
+
# write the new one and both publish the event, so every webhook
|
|
9
|
+
# subscriber hears of one change twice. With the lock the second waits,
|
|
10
|
+
# finds the move made, and changes nothing.
|
|
11
|
+
#
|
|
12
|
+
# The status is read by query rather than by reloading the product, so a
|
|
13
|
+
# caller's unsaved edits on the record are kept.
|
|
14
|
+
module StatusTransition
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
# @param status [String]
|
|
18
|
+
# @return [Boolean]
|
|
19
|
+
def already_in?(status)
|
|
20
|
+
product.class.where(id: product.id).lock.pick(:status) == status
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -2,6 +2,11 @@ module Spree
|
|
|
2
2
|
module Sellers
|
|
3
3
|
# Lets a seller trade. Also the way back for one that was suspended or
|
|
4
4
|
# turned down, which is why the guard admits more than the linear path.
|
|
5
|
+
#
|
|
6
|
+
# A seller the operator created and never invited (or whose invitation is
|
|
7
|
+
# still open) can be admitted too, but only with `override_requirements`:
|
|
8
|
+
# the operator is skipping onboarding altogether, so it must be as
|
|
9
|
+
# deliberate — and as visible on the event — as skipping the checklist.
|
|
5
10
|
class Approve < Spree::Workflow
|
|
6
11
|
hooks :validate, :after_approve
|
|
7
12
|
|
|
@@ -40,6 +45,7 @@ module Spree
|
|
|
40
45
|
|
|
41
46
|
return if seller.onboarding? || seller.ready_for_review? ||
|
|
42
47
|
seller.suspended? || seller.rejected?
|
|
48
|
+
return if override_requirements && (seller.pending? || seller.invited?)
|
|
43
49
|
|
|
44
50
|
failure(seller, :not_approvable)
|
|
45
51
|
end
|
|
@@ -53,14 +53,17 @@ module Spree
|
|
|
53
53
|
# location in the marketplace needs to see. `default` is per-owner, so
|
|
54
54
|
# this is the default among *this seller's* locations and leaves the
|
|
55
55
|
# operator's own alone.
|
|
56
|
+
#
|
|
57
|
+
# A seller created with a returns address already has its location, so
|
|
58
|
+
# that one becomes the default rather than a second being made.
|
|
56
59
|
def provision_stock_location
|
|
57
|
-
@stock_location = seller.stock_locations.new(
|
|
60
|
+
@stock_location = seller.stock_locations.first || seller.stock_locations.new(
|
|
58
61
|
store: seller.store,
|
|
59
62
|
name: seller.name,
|
|
60
|
-
default: true,
|
|
61
63
|
active: true,
|
|
62
64
|
country_code: seller.store.default_country_code
|
|
63
65
|
)
|
|
66
|
+
@stock_location.default = true
|
|
64
67
|
# A new seller has no catalog, so there is nothing to propagate — the
|
|
65
68
|
# levels arrive with their products.
|
|
66
69
|
@stock_location.propagate_all_variants = false
|
|
@@ -13,8 +13,7 @@ module Spree
|
|
|
13
13
|
# external system knows. The movement records the delta between what Spree
|
|
14
14
|
# held and what the feed says.
|
|
15
15
|
class BulkUpsert < Spree::Workflow
|
|
16
|
-
|
|
17
|
-
# What the stock history shows against a movement this service wrote.
|
|
16
|
+
# What the stock history shows against a movement whose row gave no reason.
|
|
18
17
|
FEED_REASON = 'inventory_feed'.freeze
|
|
19
18
|
|
|
20
19
|
# @param store [Spree::Store] whose shelves these are. Ids are resolved
|
|
@@ -23,11 +22,13 @@ module Spree
|
|
|
23
22
|
# @param rows [Array<Hash>] one per shelf: +variant_id+ and
|
|
24
23
|
# +stock_location_id+ naming it (prefixed ids, or raw), then either
|
|
25
24
|
# +count_on_hand+ (the figure it should end at) or +adjustment+ (a
|
|
26
|
-
# signed change); +backorderable+ optional
|
|
27
|
-
# @return [Spree::ServiceModule::Result] +{ stock_level_count: N }
|
|
25
|
+
# signed change); +backorderable+ and +reason+ optional
|
|
26
|
+
# @return [Spree::ServiceModule::Result] +{ stock_level_count: N }+, or a
|
|
27
|
+
# failure naming the first row a record refused, by its position in
|
|
28
|
+
# +rows+; nothing is written then
|
|
28
29
|
def perform(store:, rows:)
|
|
29
30
|
@store = store
|
|
30
|
-
rows = resolve(Array(rows).map { |row| row.with_indifferent_access })
|
|
31
|
+
rows = resolve(Array(rows).each_with_index.map { |row, index| row.with_indifferent_access.merge(index: index) })
|
|
31
32
|
keyed = rows.select { |row| row[:variant_id].present? && row[:stock_location_id].present? }
|
|
32
33
|
return success(stock_level_count: 0) if keyed.empty?
|
|
33
34
|
|
|
@@ -38,7 +39,11 @@ module Spree
|
|
|
38
39
|
existing = existing_stock_levels(deduped)
|
|
39
40
|
count = 0
|
|
40
41
|
Spree::StockLevel.transaction do
|
|
41
|
-
deduped.each
|
|
42
|
+
deduped.each do |row|
|
|
43
|
+
count += 1 if apply_row(row, existing)
|
|
44
|
+
rescue ActiveRecord::RecordInvalid => e
|
|
45
|
+
reject_row(row, e.record.errors)
|
|
46
|
+
end
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
success(stock_level_count: count)
|
|
@@ -110,7 +115,7 @@ module Spree
|
|
|
110
115
|
stock_level: stock_level,
|
|
111
116
|
count_on_hand: row[:count_on_hand],
|
|
112
117
|
adjustment: row[:adjustment],
|
|
113
|
-
reason: FEED_REASON
|
|
118
|
+
reason: row[:reason].presence || FEED_REASON
|
|
114
119
|
)
|
|
115
120
|
# A feed that states a figure Spree cannot read means a typo, and a
|
|
116
121
|
# typo must be refused rather than obeyed: `to_i` would zero a shelf
|
|
@@ -119,6 +124,13 @@ module Spree
|
|
|
119
124
|
|
|
120
125
|
result.value.count_on_hand != before
|
|
121
126
|
end
|
|
127
|
+
|
|
128
|
+
# Raised inside the transaction, so every row before this one rolls back.
|
|
129
|
+
def reject_row(row, errors)
|
|
130
|
+
failure(nil, code: 'invalid_stock_levels',
|
|
131
|
+
message: "Row #{row[:index]}: #{errors.full_messages.to_sentence}",
|
|
132
|
+
rows: [{ index: row[:index], errors: errors.messages }])
|
|
133
|
+
end
|
|
122
134
|
end
|
|
123
135
|
end
|
|
124
136
|
end
|
data/config/locales/be.yml
CHANGED
|
@@ -446,7 +446,7 @@ be:
|
|
|
446
446
|
not_locked: не быў заблакаваны
|
|
447
447
|
not_saved:
|
|
448
448
|
many: "%{count} памылак перашкаджаюць захаванню %{resource}:"
|
|
449
|
-
one:
|
|
449
|
+
one: "%{count} памылка перашкаджае захаванню %{resource}:"
|
|
450
450
|
other: "%{count} памылкі перашкаджаюць захаванню %{resource}:"
|
|
451
451
|
number:
|
|
452
452
|
percentage:
|
data/config/locales/en.yml
CHANGED
|
@@ -900,6 +900,7 @@ en:
|
|
|
900
900
|
invalid_status: Invalid status
|
|
901
901
|
invalid_storefront_access: is not a valid storefront access level
|
|
902
902
|
items_not_a_list: items must be a list of objects
|
|
903
|
+
missing_row_type: 'is required (expected one of: %{types})'
|
|
903
904
|
money_preference_too_many_decimals: has more than %{count} decimal places for %{currency}
|
|
904
905
|
must_be_greater_than_min_amount: must be greater than or equal to the minimum
|
|
905
906
|
no_pickup_point_provider: this delivery method has no pickup point provider configured
|
|
@@ -909,6 +910,7 @@ en:
|
|
|
909
910
|
oidc_missing_code: The identity provider did not return an authorization code.
|
|
910
911
|
oidc_requires_redirect: This provider requires signing in through its own login page.
|
|
911
912
|
pickup_point_not_found: pickup point could not be found with this provider
|
|
913
|
+
product_in_review: A product awaiting review is approved or rejected, not moved to another status
|
|
912
914
|
product_not_in_store: must all belong to this store
|
|
913
915
|
profile_does_not_accept_provider: "%{provider} deliveries cannot join the %{profile} profile"
|
|
914
916
|
promotion_discount_not_editable: promotion discounts are managed by recalculation and cannot be edited
|
|
@@ -924,6 +926,7 @@ en:
|
|
|
924
926
|
store_is_already_set: Store is already set
|
|
925
927
|
unknown_calculator_type: "%{type} is not a calculator offered here"
|
|
926
928
|
unknown_custom_field_type: 'is not a known custom field type (expected one of: %{types})'
|
|
929
|
+
unknown_row_type: "%{type} is not a %{family} offered here (expected one of: %{types})"
|
|
927
930
|
unknown_scopes: 'contains unknown scopes: %{scopes}'
|
|
928
931
|
unregistered_actor: is not a registered actor class
|
|
929
932
|
variant_product_mismatch: must belong to the same product as the variant
|
|
@@ -1018,6 +1021,7 @@ en:
|
|
|
1018
1021
|
subject: Invitation to join %{resource_name}
|
|
1019
1022
|
invitation_not_acceptable: Invitation not found, expired, or already accepted.
|
|
1020
1023
|
invitation_role_resource_mismatch: must belong to the same store or seller as the invitation
|
|
1024
|
+
invitation_seller_rejected: This seller was rejected, so nobody can join its team.
|
|
1021
1025
|
iso: ISO Alpha-2
|
|
1022
1026
|
item: Item
|
|
1023
1027
|
items_cannot_be_shipped: We are unable to calculate shipping rates for the selected items.
|
|
@@ -1651,6 +1655,13 @@ en:
|
|
|
1651
1655
|
name: Billing address
|
|
1652
1656
|
complete_profile:
|
|
1653
1657
|
description: Fill in the public profile shoppers see
|
|
1658
|
+
fields:
|
|
1659
|
+
about: a description
|
|
1660
|
+
contact_email: a contact email
|
|
1661
|
+
cover_photo: a cover photo
|
|
1662
|
+
logo: a logo
|
|
1663
|
+
name: a name
|
|
1664
|
+
missing: 'Still missing: %{fields}.'
|
|
1654
1665
|
name: Complete profile
|
|
1655
1666
|
delivery_method:
|
|
1656
1667
|
description: Offer at least one way to ship your orders
|
data/config/locales/fr.yml
CHANGED
|
@@ -418,7 +418,7 @@ fr:
|
|
|
418
418
|
not_found: Non trouvé(e)
|
|
419
419
|
not_locked: n'est pas bloqué
|
|
420
420
|
not_saved:
|
|
421
|
-
one: "%{resource} n'a pu etre sauvegardé à cause
|
|
421
|
+
one: "%{resource} n'a pu etre sauvegardé à cause de %{count} erreur:"
|
|
422
422
|
other: "%{resource} n'a pu etre sauvegardé à cause de %{count} erreurs:"
|
|
423
423
|
number:
|
|
424
424
|
percentage:
|
data/config/locales/lt.yml
CHANGED
|
@@ -418,7 +418,7 @@ lt:
|
|
|
418
418
|
not_found: nerastas
|
|
419
419
|
not_locked: nebuvo užrakinta
|
|
420
420
|
not_saved:
|
|
421
|
-
one:
|
|
421
|
+
one: "%{count} klaida neleido išsaugoti %{resource}:"
|
|
422
422
|
other: "%{count} klaidos neleido išsaugoti %{resource}:"
|
|
423
423
|
number:
|
|
424
424
|
percentage:
|
data/config/locales/ru.yml
CHANGED
|
@@ -426,7 +426,7 @@ ru:
|
|
|
426
426
|
not_locked: не был заблокирован
|
|
427
427
|
not_saved:
|
|
428
428
|
many: "%{count} ошибок препятствуют сохранению %{resource}:"
|
|
429
|
-
one:
|
|
429
|
+
one: "%{count} ошибка препятствует сохранению %{resource}:"
|
|
430
430
|
other: "%{count} ошибки препятствуют сохранению %{resource}:"
|
|
431
431
|
number:
|
|
432
432
|
percentage:
|
data/config/locales/uk.yml
CHANGED
|
@@ -419,7 +419,7 @@ uk:
|
|
|
419
419
|
not_saved:
|
|
420
420
|
few: "%{count} помилки завадили збереженню цього %{resource}:"
|
|
421
421
|
many: "%{count} помилок завадили збереженню цього %{resource}:"
|
|
422
|
-
one:
|
|
422
|
+
one: "%{count} помилка завадила збереженню цього %{resource}:"
|
|
423
423
|
other: "%{count} помилки завадили збереженню цього %{resource}:"
|
|
424
424
|
number:
|
|
425
425
|
percentage:
|
|
@@ -3,22 +3,26 @@ class FixSpreeStockItemUniqueIndex < ActiveRecord::Migration[6.1]
|
|
|
3
3
|
remove_index :spree_stock_items, name: 'stock_item_by_loc_var_id_deleted_at' if index_exists?(:spree_stock_items, [:stock_location_id, :variant_id], name: 'stock_item_by_loc_var_id_deleted_at')
|
|
4
4
|
|
|
5
5
|
unless index_exists?(:spree_stock_items, ['variant_id', 'stock_location_id'], name: 'index_spree_stock_items_unique_without_deleted_at')
|
|
6
|
-
# MySQL
|
|
7
|
-
|
|
6
|
+
# MySQL and MariaDB don't support partial indexes, and MariaDB rejects
|
|
7
|
+
# functional key parts too. Index a stored generated column instead,
|
|
8
|
+
# which both accept.
|
|
9
|
+
if Spree.mysql?
|
|
8
10
|
reversible do |dir|
|
|
9
11
|
dir.up do
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
unless column_exists?(:spree_stock_items, :live_key)
|
|
13
|
+
execute <<-SQL.squish
|
|
14
|
+
ALTER TABLE spree_stock_items
|
|
15
|
+
ADD COLUMN live_key TINYINT
|
|
16
|
+
AS (IF(deleted_at IS NULL, 1, NULL)) STORED
|
|
17
|
+
SQL
|
|
18
|
+
end
|
|
19
|
+
add_index :spree_stock_items, %w[stock_location_id variant_id live_key],
|
|
20
|
+
name: 'index_spree_stock_items_unique_without_deleted_at', unique: true
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
dir.down do
|
|
21
24
|
remove_index :spree_stock_items, name: :index_spree_stock_items_unique_without_deleted_at
|
|
25
|
+
remove_column :spree_stock_items, :live_key if column_exists?(:spree_stock_items, :live_key)
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
else
|
|
@@ -54,19 +54,25 @@ class RenameStockItemsToStockLevels < ActiveRecord::Migration[8.1]
|
|
|
54
54
|
# cannot honour is dropped without complaint, leaving a unique index over the
|
|
55
55
|
# wrong set of rows.
|
|
56
56
|
def rename_partial_uniqueness_index(from:, to:)
|
|
57
|
+
# Hosts that got the index through the generated column keep it as it is.
|
|
58
|
+
# Only the index changes name, as MariaDB cannot rebuild the expression form.
|
|
59
|
+
if column_exists?(:spree_stock_levels, :live_key)
|
|
60
|
+
rename_index :spree_stock_levels, from, to
|
|
61
|
+
return
|
|
62
|
+
end
|
|
63
|
+
|
|
57
64
|
remove_index :spree_stock_levels, name: from
|
|
58
65
|
|
|
59
66
|
if connection.supports_partial_index?
|
|
60
67
|
add_index :spree_stock_levels, %w[variant_id stock_location_id], name: to, unique: true, where: 'deleted_at IS NULL'
|
|
61
68
|
else
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(COALESCE(deleted_at, CAST('1970-01-01' AS DATETIME)))
|
|
68
|
-
);
|
|
69
|
+
# MariaDB rejects an expression in the key, so index a stored generated column.
|
|
70
|
+
execute <<~SQL.squish
|
|
71
|
+
ALTER TABLE spree_stock_levels
|
|
72
|
+
ADD COLUMN live_key TINYINT
|
|
73
|
+
AS (IF(deleted_at IS NULL, 1, NULL)) STORED
|
|
69
74
|
SQL
|
|
75
|
+
add_index :spree_stock_levels, %w[stock_location_id variant_id live_key], name: to, unique: true
|
|
70
76
|
end
|
|
71
77
|
end
|
|
72
78
|
end
|
|
@@ -169,6 +169,10 @@ module Spree
|
|
|
169
169
|
if options[:admin]
|
|
170
170
|
template 'admin_controller_spec.rb.tt',
|
|
171
171
|
"spec/controllers/spree/api/v3/admin/#{plural_name}_controller_spec.rb"
|
|
172
|
+
# Documents the endpoints in openapi/admin.yaml (`spree task
|
|
173
|
+
# openapi:generate`): the SDK request types and the agent tools come
|
|
174
|
+
# from there.
|
|
175
|
+
template 'admin_integration_spec.rb.tt', "spec/integration/admin/#{plural_name}_spec.rb"
|
|
172
176
|
end
|
|
173
177
|
end
|
|
174
178
|
|
|
@@ -297,6 +301,9 @@ module Spree
|
|
|
297
301
|
if options[:store] || options[:admin]
|
|
298
302
|
say " #{store_scoped? ? 5 : 4}. Run the specs: pnpm exec spree test spec/controllers/spree/api/v3/"
|
|
299
303
|
end
|
|
304
|
+
if options[:admin] && !options[:skip_specs]
|
|
305
|
+
say " #{store_scoped? ? 6 : 5}. Document the Admin API (agent tools, SDK types): pnpm exec spree task openapi:generate"
|
|
306
|
+
end
|
|
300
307
|
say ''
|
|
301
308
|
end
|
|
302
309
|
|
|
@@ -344,9 +351,26 @@ module Spree
|
|
|
344
351
|
# Attributes the controller permits on write. By default, every column
|
|
345
352
|
# except references (FKs come through nested), attachments, rich text.
|
|
346
353
|
def permitted_attribute_names
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
354
|
+
writable_attributes.map(&:name)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
# @return [Array<Array(String, Symbol, Boolean)>] each writable attribute,
|
|
358
|
+
# its `request_params` type, and whether creating needs it — the model
|
|
359
|
+
# template validates the presence of every one but booleans
|
|
360
|
+
def request_param_attributes
|
|
361
|
+
writable_attributes.map { |a| [a.name, REQUEST_PARAM_TYPES.fetch(a.type, :string), a.type != :boolean] }
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# Decimal attributes travel as decimal strings (`'1.00'`), never JSON
|
|
365
|
+
# numbers; a money attribute sent as a number is refused.
|
|
366
|
+
#
|
|
367
|
+
# @return [Array<String>]
|
|
368
|
+
def decimal_attribute_names
|
|
369
|
+
writable_attributes.select { |a| a.type == :decimal }.map(&:name)
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
def writable_attributes
|
|
373
|
+
attributes.reject { |a| a.reference? || a.attachment? || a.attachments? || a.rich_text? || a.token? || a.password_digest? }
|
|
350
374
|
end
|
|
351
375
|
end
|
|
352
376
|
|
|
@@ -354,6 +378,14 @@ module Spree
|
|
|
354
378
|
|
|
355
379
|
INITIALIZER_PATH = 'config/initializers/spree.rb'.freeze
|
|
356
380
|
|
|
381
|
+
# A migration column type → the `request_params` type that documents it.
|
|
382
|
+
REQUEST_PARAM_TYPES = {
|
|
383
|
+
string: :string, text: :string, citext: :string,
|
|
384
|
+
integer: :integer, bigint: :integer, float: :number, decimal: :decimal,
|
|
385
|
+
boolean: :boolean, date: :date, datetime: :datetime, timestamp: :datetime,
|
|
386
|
+
json: :hash, jsonb: :hash
|
|
387
|
+
}.freeze
|
|
388
|
+
|
|
357
389
|
def permission_scope_block
|
|
358
390
|
<<~RUBY
|
|
359
391
|
|
|
@@ -9,6 +9,15 @@ module Spree
|
|
|
9
9
|
# existing resource name instead if this endpoint belongs under one.
|
|
10
10
|
scoped_resource :<%= plural_name %>
|
|
11
11
|
|
|
12
|
+
# What create and update accept: the controller permits from it, and
|
|
13
|
+
# the integration spec documents it (`request_body_for`), which is
|
|
14
|
+
# where the SDK request types come from.
|
|
15
|
+
request_params :<%= singular_name %> do |body|
|
|
16
|
+
<% request_param_attributes.each do |name, type, required| -%>
|
|
17
|
+
body.attribute :<%= name %>, :<%= type %><%= ', required: true, on: :create' if required %>
|
|
18
|
+
<% end -%>
|
|
19
|
+
end
|
|
20
|
+
|
|
12
21
|
protected
|
|
13
22
|
|
|
14
23
|
def model_class
|
|
@@ -18,10 +27,6 @@ module Spree
|
|
|
18
27
|
def serializer_class
|
|
19
28
|
Spree::Api::V3::Admin::<%= bare_class_name %>Serializer
|
|
20
29
|
end
|
|
21
|
-
|
|
22
|
-
def resource_permitted_attributes
|
|
23
|
-
[<%= permitted_attribute_names.map { |a| ":#{a}" }.join(', ') %>]
|
|
24
|
-
end
|
|
25
30
|
end
|
|
26
31
|
end
|
|
27
32
|
end
|