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
|
@@ -9,6 +9,7 @@ module Spree
|
|
|
9
9
|
def add_memberships(groups, products)
|
|
10
10
|
group_ids = groups.pluck(:id)
|
|
11
11
|
product_ids = products.pluck(:id)
|
|
12
|
+
existing = membership_class.where(group_key => group_ids, product_id: product_ids).ids
|
|
12
13
|
# Every group's current size in one grouped count, rather than a probe
|
|
13
14
|
# per group for the position to append at.
|
|
14
15
|
sizes = membership_class.where(group_key => group_ids).group(group_key).count
|
|
@@ -24,15 +25,23 @@ module Spree
|
|
|
24
25
|
end
|
|
25
26
|
membership_class.insert_all(rows)
|
|
26
27
|
|
|
28
|
+
created = membership_class.where(group_key => group_ids, product_id: product_ids).where.not(id: existing)
|
|
29
|
+
|
|
27
30
|
refresh_after_membership_change(group_ids, products)
|
|
31
|
+
publish_membership_events(created, 'created')
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
# Removes the products, then re-packs the remaining positions from 1.
|
|
31
35
|
def remove_memberships(groups, products)
|
|
32
36
|
group_ids = groups.pluck(:id)
|
|
37
|
+
product_ids = products.pluck(:id)
|
|
38
|
+
deleted = []
|
|
33
39
|
|
|
34
40
|
ApplicationRecord.transaction do
|
|
35
|
-
|
|
41
|
+
# Ordered so two callers queue for the same rows in the same sequence rather than deadlocking on each other.
|
|
42
|
+
deleted = membership_class.where(group_key => group_ids, product_id: product_ids).order(:id).lock.to_a
|
|
43
|
+
|
|
44
|
+
membership_class.where(group_key => group_ids, product_id: product_ids).delete_all
|
|
36
45
|
|
|
37
46
|
# What survived the delete, for every group in one read.
|
|
38
47
|
remaining = membership_class.where(group_key => group_ids).order(:position).pluck(group_key, :product_id).
|
|
@@ -50,6 +59,17 @@ module Spree
|
|
|
50
59
|
end
|
|
51
60
|
|
|
52
61
|
refresh_after_membership_change(group_ids, products)
|
|
62
|
+
publish_membership_events(deleted, 'deleted')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def publish_membership_events(memberships, action)
|
|
66
|
+
memberships = memberships.to_a
|
|
67
|
+
return if memberships.empty?
|
|
68
|
+
|
|
69
|
+
ActiveRecord::Associations::Preloader.new(records: memberships, associations: { product: :store }).call
|
|
70
|
+
|
|
71
|
+
name = "#{membership_class.model_name.element}.#{action}"
|
|
72
|
+
memberships.each { |membership| membership.publish_event(name) }
|
|
53
73
|
end
|
|
54
74
|
|
|
55
75
|
# Bulk writes skip the join model's callbacks, so counters, caches and the
|
|
@@ -136,8 +136,9 @@ module Spree
|
|
|
136
136
|
scoped_ids = store.products.where(id: product_ids).ids
|
|
137
137
|
return [] if scoped_ids.empty?
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
existing_rows = Spree::ProductCategory.where(product_id: scoped_ids, category_id: category_ids).
|
|
140
|
+
pluck(:id, :product_id, :category_id)
|
|
141
|
+
existing = existing_rows.to_set { |_id, product_id, category_id| [product_id, category_id] }
|
|
141
142
|
|
|
142
143
|
# acts_as_list scopes position per category here (unlike option types,
|
|
143
144
|
# which scope per product), so each category continues its own sequence.
|
|
@@ -160,8 +161,17 @@ module Spree
|
|
|
160
161
|
return [] if rows.empty?
|
|
161
162
|
|
|
162
163
|
Spree::ProductCategory.insert_all(rows)
|
|
164
|
+
publish_categorized_events(scoped_ids, category_ids, existing_rows.map(&:first))
|
|
165
|
+
|
|
163
166
|
rows.pluck(:product_id).uniq
|
|
164
167
|
end
|
|
168
|
+
|
|
169
|
+
def publish_categorized_events(product_ids, category_ids, existing_ids)
|
|
170
|
+
created = Spree::ProductCategory.where(product_id: product_ids, category_id: category_ids).
|
|
171
|
+
where.not(id: existing_ids)
|
|
172
|
+
|
|
173
|
+
created.each { |membership| membership.publish_event('product_category.created') }
|
|
174
|
+
end
|
|
165
175
|
end
|
|
166
176
|
end
|
|
167
177
|
end
|
|
@@ -9,22 +9,28 @@ module Spree
|
|
|
9
9
|
# @param product [Spree::Product]
|
|
10
10
|
# @return [Spree::ServiceModule::Base::Result]
|
|
11
11
|
def call(product:)
|
|
12
|
-
return
|
|
12
|
+
return if product.blank?
|
|
13
13
|
|
|
14
14
|
collections_to_remove = []
|
|
15
15
|
collections_to_add = []
|
|
16
16
|
|
|
17
17
|
# existing memberships that no longer match (tags/prices changed)
|
|
18
|
-
product.collections.automatic.includes(:rules).
|
|
18
|
+
product.collections.automatic.includes(:rules).find_each do |collection|
|
|
19
19
|
collections_to_remove << collection unless collection.products_matching_rules.ids.include?(product.id)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
# Held before the delete: the rows are gone by the time their deleted
|
|
23
|
+
# events can be published.
|
|
24
|
+
removed_rows = []
|
|
25
|
+
|
|
22
26
|
if collections_to_remove.any?
|
|
23
|
-
Spree::ProductCollection.where(collection: collections_to_remove, product: product)
|
|
27
|
+
scope = Spree::ProductCollection.where(collection: collections_to_remove, product: product)
|
|
28
|
+
removed_rows = scope.to_a
|
|
29
|
+
scope.delete_all
|
|
24
30
|
end
|
|
25
31
|
|
|
26
32
|
# automatic collections in the product's store that it now matches
|
|
27
|
-
Spree::Collection.automatic.where(store_id: product.store_id).includes(:rules, :products).
|
|
33
|
+
Spree::Collection.automatic.where(store_id: product.store_id).includes(:rules, :products).find_each do |collection|
|
|
28
34
|
collections_to_add << collection if collection.products.exclude?(product) && collection.products_matching_rules.ids.include?(product.id)
|
|
29
35
|
end
|
|
30
36
|
|
|
@@ -56,11 +62,21 @@ module Spree
|
|
|
56
62
|
Spree::Product.reset_counters(product.id, :product_collections)
|
|
57
63
|
end
|
|
58
64
|
|
|
65
|
+
publish_membership_events(product, removed_rows, collections_to_add)
|
|
66
|
+
|
|
59
67
|
success(product)
|
|
60
68
|
end
|
|
61
69
|
|
|
62
70
|
private
|
|
63
71
|
|
|
72
|
+
def publish_membership_events(product, removed_rows, added_collections)
|
|
73
|
+
removed_rows.each { |row| row.publish_event('product_collection.deleted') }
|
|
74
|
+
return if added_collections.empty?
|
|
75
|
+
|
|
76
|
+
Spree::ProductCollection.where(collection_id: added_collections.map(&:id), product_id: product.id).
|
|
77
|
+
find_each { |row| row.publish_event('product_collection.created') }
|
|
78
|
+
end
|
|
79
|
+
|
|
64
80
|
def product_collection_attributes(collection, product, position)
|
|
65
81
|
{
|
|
66
82
|
collection_id: collection.id,
|
|
@@ -2,14 +2,17 @@ module Spree
|
|
|
2
2
|
module Products
|
|
3
3
|
# @deprecated Automatic taxon matching moved to Spree::Collection in 6.0.
|
|
4
4
|
# Delegates to Spree::Products::AutoMatchCollections (same `product:` signature);
|
|
5
|
-
# removed in 6.
|
|
5
|
+
# removed in 6.3.
|
|
6
6
|
class AutoMatchTaxons
|
|
7
7
|
prepend ::Spree::ServiceModule::Base
|
|
8
8
|
|
|
9
9
|
# @param product [Spree::Product]
|
|
10
10
|
# @return [Spree::ServiceModule::Base::Result]
|
|
11
11
|
def call(product:)
|
|
12
|
-
Spree::Deprecation.warn(
|
|
12
|
+
Spree::Deprecation.warn(
|
|
13
|
+
'Spree::Products::AutoMatchTaxons is deprecated and will be removed in Spree 6.3. ' \
|
|
14
|
+
'Automatic membership moved to collections; use Spree::Products::AutoMatchCollections instead.'
|
|
15
|
+
)
|
|
13
16
|
Spree::Products::AutoMatchCollections.call(product: product)
|
|
14
17
|
end
|
|
15
18
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
module Shipments
|
|
3
|
-
# @deprecated Use {Spree::Fulfillments::Update}; removed in 6.
|
|
3
|
+
# @deprecated Use {Spree::Fulfillments::Update}; removed in 6.3.
|
|
4
4
|
class Update
|
|
5
5
|
def self.call(shipment:, shipment_attributes: {}, &block)
|
|
6
|
-
Spree::Deprecation.warn('Spree::Shipments::Update is deprecated and will be removed in Spree 6.
|
|
6
|
+
Spree::Deprecation.warn('Spree::Shipments::Update is deprecated and will be removed in Spree 6.3. Use Spree::Fulfillments::Update instead.')
|
|
7
7
|
Spree::Fulfillments::Update.call(fulfillment: shipment, fulfillment_attributes: shipment_attributes, &block)
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -3,7 +3,7 @@ module Spree
|
|
|
3
3
|
module StockItems
|
|
4
4
|
# @deprecated Renamed to Spree::StockLocations::StockLevels::Create in 6.0.
|
|
5
5
|
# This shim delegates to the renamed service so host code calling the old
|
|
6
|
-
# name keeps working; removed in 6.
|
|
6
|
+
# name keeps working; removed in 6.3.
|
|
7
7
|
class Create
|
|
8
8
|
prepend Spree::ServiceModule::Base
|
|
9
9
|
|
|
@@ -11,7 +11,10 @@ module Spree
|
|
|
11
11
|
# @param variants_scope [ActiveRecord::Relation]
|
|
12
12
|
# @return [Spree::ServiceModule::Base::Result]
|
|
13
13
|
def call(stock_location:, variants_scope: nil)
|
|
14
|
-
Spree::Deprecation.warn(
|
|
14
|
+
Spree::Deprecation.warn(
|
|
15
|
+
'Spree::StockLocations::StockItems::Create is deprecated and will be removed in Spree 6.3. ' \
|
|
16
|
+
'Use Spree::StockLocations::StockLevels::Create instead.'
|
|
17
|
+
)
|
|
15
18
|
Spree::StockLocations::StockLevels::Create.call(stock_location: stock_location, variants_scope: variants_scope)
|
|
16
19
|
end
|
|
17
20
|
end
|
|
@@ -5,7 +5,9 @@ module Spree
|
|
|
5
5
|
|
|
6
6
|
def call(cart: nil, order: nil)
|
|
7
7
|
if order
|
|
8
|
-
Spree::Deprecation.warn(
|
|
8
|
+
Spree::Deprecation.warn(
|
|
9
|
+
'Calling Spree::StockReservations::Extend with order: is deprecated and will be removed in Spree 6.3. Pass cart: instead.'
|
|
10
|
+
)
|
|
9
11
|
cart ||= order
|
|
10
12
|
end
|
|
11
13
|
return success(cart) unless Spree::StorePreferences.read(cart&.store, :stock_reservations_enabled)
|
|
@@ -5,7 +5,9 @@ module Spree
|
|
|
5
5
|
|
|
6
6
|
def call(cart: nil, order: nil)
|
|
7
7
|
if order
|
|
8
|
-
Spree::Deprecation.warn(
|
|
8
|
+
Spree::Deprecation.warn(
|
|
9
|
+
'Calling Spree::StockReservations::Reserve with order: is deprecated and will be removed in Spree 6.3. Pass cart: instead.'
|
|
10
|
+
)
|
|
9
11
|
cart ||= order
|
|
10
12
|
end
|
|
11
13
|
return success(cart) unless Spree::StorePreferences.read(cart&.store, :stock_reservations_enabled)
|
|
@@ -139,16 +141,19 @@ module Spree
|
|
|
139
141
|
)
|
|
140
142
|
end
|
|
141
143
|
|
|
144
|
+
# Handoff to a draft clears the cart reference. A SQL inequality alone
|
|
145
|
+
# drops those holds instead of counting them against competing checkouts.
|
|
142
146
|
def held_by_others(stock_level_ids, owner)
|
|
143
147
|
return {} if stock_level_ids.empty?
|
|
144
148
|
|
|
145
149
|
owner_column = owner.is_a?(Spree::Cart) ? :cart_id : :order_id
|
|
146
|
-
Spree::StockReservation
|
|
147
|
-
|
|
148
|
-
.
|
|
149
|
-
|
|
150
|
-
.
|
|
151
|
-
|
|
150
|
+
owner_reference = Spree::StockReservation.arel_table[owner_column]
|
|
151
|
+
Spree::StockReservation.
|
|
152
|
+
active.
|
|
153
|
+
where(stock_level_id: stock_level_ids).
|
|
154
|
+
where(owner_reference.eq(nil).or(owner_reference.not_eq(owner.id))).
|
|
155
|
+
group(:stock_level_id).
|
|
156
|
+
sum(:quantity)
|
|
152
157
|
end
|
|
153
158
|
|
|
154
159
|
# One SELECT for all (stock_level_id, line_item_id) pairs we need to
|
|
@@ -57,8 +57,16 @@ module Spree
|
|
|
57
57
|
apply_store_credits(remaining_total, except: payments.map(&:source_id)) if remaining_total.positive?
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
# Allocates credit through an active payment method owned by the order store.
|
|
61
|
+
# No method is required when the outstanding amount is zero or negative.
|
|
62
|
+
#
|
|
63
|
+
# @param remaining_total [Numeric] maximum outstanding amount to allocate
|
|
64
|
+
# @param except [Array<Integer>] credit IDs already applied to this order
|
|
65
|
+
# @return [void]
|
|
60
66
|
def apply_store_credits(remaining_total, except: [])
|
|
61
|
-
|
|
67
|
+
return unless remaining_total.positive?
|
|
68
|
+
|
|
69
|
+
payment_method = @order.store.payment_methods.store_credit.available.first
|
|
62
70
|
raise 'Store credit payment method could not be found' unless payment_method
|
|
63
71
|
|
|
64
72
|
spendable_store_credits.where.not(id: except).oldest_first.each do |credit|
|
|
@@ -2,7 +2,7 @@ module Spree
|
|
|
2
2
|
module Taxons
|
|
3
3
|
# @deprecated Renamed to Spree::Categories::AddProducts in 6.0. This shim keeps
|
|
4
4
|
# the old `taxons:` keyword working by delegating to the renamed service;
|
|
5
|
-
# removed in 6.
|
|
5
|
+
# removed in 6.3.
|
|
6
6
|
class AddProducts
|
|
7
7
|
prepend Spree::ServiceModule::Base
|
|
8
8
|
|
|
@@ -10,7 +10,9 @@ module Spree
|
|
|
10
10
|
# @param products [Array<Spree::Product>]
|
|
11
11
|
# @return [Spree::ServiceModule::Base::Result]
|
|
12
12
|
def call(taxons:, products:)
|
|
13
|
-
Spree::Deprecation.warn(
|
|
13
|
+
Spree::Deprecation.warn(
|
|
14
|
+
'Spree::Taxons::AddProducts is deprecated and will be removed in Spree 6.3. Use Spree::Categories::AddProducts instead.'
|
|
15
|
+
)
|
|
14
16
|
Spree::Categories::AddProducts.call(categories: taxons, products: products)
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -3,14 +3,17 @@ module Spree
|
|
|
3
3
|
# @deprecated Categories are manual in 6.0 and no longer regenerate membership
|
|
4
4
|
# from rules — that behavior moved to Spree::Collection. There is no faithful
|
|
5
5
|
# category target, so this shim warns and no-ops (returns the given taxon).
|
|
6
|
-
# Use Spree::Collections::RegenerateProducts for collections. Removed in 6.
|
|
6
|
+
# Use Spree::Collections::RegenerateProducts for collections. Removed in 6.3.
|
|
7
7
|
class RegenerateProducts
|
|
8
8
|
prepend ::Spree::ServiceModule::Base
|
|
9
9
|
|
|
10
10
|
# @param taxon [Spree::Category] accepted for signature compatibility; ignored
|
|
11
11
|
# @return [Spree::ServiceModule::Base::Result]
|
|
12
12
|
def call(taxon: nil)
|
|
13
|
-
Spree::Deprecation.warn(
|
|
13
|
+
Spree::Deprecation.warn(
|
|
14
|
+
'Spree::Taxons::RegenerateProducts is deprecated and does nothing in Spree 6.0 — categories are manual. ' \
|
|
15
|
+
'Rule-based membership moved to Spree::Collection; use Spree::Collections::RegenerateProducts. Removed in 6.3.'
|
|
16
|
+
)
|
|
14
17
|
success(taxon)
|
|
15
18
|
end
|
|
16
19
|
end
|
|
@@ -2,7 +2,7 @@ module Spree
|
|
|
2
2
|
module Taxons
|
|
3
3
|
# @deprecated Renamed to Spree::Categories::RemoveProducts in 6.0. This shim keeps
|
|
4
4
|
# the old `taxons:` keyword working by delegating to the renamed service;
|
|
5
|
-
# removed in 6.
|
|
5
|
+
# removed in 6.3.
|
|
6
6
|
class RemoveProducts
|
|
7
7
|
prepend Spree::ServiceModule::Base
|
|
8
8
|
|
|
@@ -10,7 +10,9 @@ module Spree
|
|
|
10
10
|
# @param products [Array<Spree::Product>]
|
|
11
11
|
# @return [Spree::ServiceModule::Base::Result]
|
|
12
12
|
def call(taxons:, products:)
|
|
13
|
-
Spree::Deprecation.warn(
|
|
13
|
+
Spree::Deprecation.warn(
|
|
14
|
+
'Spree::Taxons::RemoveProducts is deprecated and will be removed in Spree 6.3. Use Spree::Categories::RemoveProducts instead.'
|
|
15
|
+
)
|
|
14
16
|
Spree::Categories::RemoveProducts.call(categories: taxons, products: products)
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -21,17 +21,6 @@ module Spree
|
|
|
21
21
|
# The read timeout applies to each read, not the whole response, so a
|
|
22
22
|
# slowly trickling answer needs an overall deadline as well.
|
|
23
23
|
TOTAL_TIMEOUT = 2
|
|
24
|
-
# Order-of-magnitude buckets: enough to tell a hobby install from a large
|
|
25
|
-
# merchant, never an exact figure.
|
|
26
|
-
BUCKETS = {
|
|
27
|
-
0..0 => '0',
|
|
28
|
-
1..9 => '1-9',
|
|
29
|
-
10..99 => '10-99',
|
|
30
|
-
100..999 => '100-999',
|
|
31
|
-
1_000..9_999 => '1k-9k',
|
|
32
|
-
10_000..99_999 => '10k-99k'
|
|
33
|
-
}.freeze
|
|
34
|
-
LARGEST_BUCKET = '100k+'.freeze
|
|
35
24
|
|
|
36
25
|
class << self
|
|
37
26
|
# Always false in the test environment and on CI servers (which set
|
|
@@ -77,13 +66,13 @@ module Spree
|
|
|
77
66
|
install_id: Spree.install_id,
|
|
78
67
|
ruby: RUBY_VERSION,
|
|
79
68
|
rails: Rails.version,
|
|
80
|
-
database:
|
|
81
|
-
gems:
|
|
82
|
-
dashboard: dashboard_served?,
|
|
83
|
-
stores: bucket(Spree::Store.count),
|
|
84
|
-
products: bucket(Spree::Product.count),
|
|
85
|
-
orders: bucket(Spree::Order.complete.count),
|
|
86
|
-
sellers: seller_bucket
|
|
69
|
+
database: Diagnostics::Stack.database,
|
|
70
|
+
gems: Diagnostics::Stack.spree_gems.keys.join(','),
|
|
71
|
+
dashboard: Diagnostics::Stack.dashboard_served?,
|
|
72
|
+
stores: Diagnostics::Stack.bucket(Spree::Store.count),
|
|
73
|
+
products: Diagnostics::Stack.bucket(Spree::Product.count),
|
|
74
|
+
orders: Diagnostics::Stack.bucket(Spree::Order.complete.count),
|
|
75
|
+
sellers: Diagnostics::Stack.seller_bucket
|
|
87
76
|
}.compact
|
|
88
77
|
end
|
|
89
78
|
|
|
@@ -142,19 +131,6 @@ module Spree
|
|
|
142
131
|
nil
|
|
143
132
|
end
|
|
144
133
|
|
|
145
|
-
def bucket(count)
|
|
146
|
-
BUCKETS.find { |range, _| range.cover?(count) }&.last || LARGEST_BUCKET
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def seller_bucket
|
|
150
|
-
count = Spree::Seller.count
|
|
151
|
-
bucket(count) if count.positive?
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def dashboard_served?
|
|
155
|
-
(defined?(Spree::Dashboard) && Spree::Dashboard.dist_path.present?) || Spree::Config.dashboard_url.present?
|
|
156
|
-
end
|
|
157
|
-
|
|
158
134
|
def env_flag?(name)
|
|
159
135
|
ActiveModel::Type::Boolean.new.cast(ENV[name].presence) == true
|
|
160
136
|
end
|
|
@@ -101,6 +101,9 @@ module Spree
|
|
|
101
101
|
# product's variants when written — needs that record's id as
|
|
102
102
|
# parent_id on the calls whose route runs under it.
|
|
103
103
|
parent: %i[index create update].lazy.filter_map { |action| entry.parent_key(action) }.first,
|
|
104
|
+
# The records a search can list this resource under with parent_id
|
|
105
|
+
# — products under a category, collection or catalog.
|
|
106
|
+
listed_under: entry.index_parents.keys.sort.presence,
|
|
104
107
|
filterable_fields: entry.filterable_fields,
|
|
105
108
|
# What a generic write accepts, so the model learns the schema here
|
|
106
109
|
# rather than by sending an invalid write and reading the refusal —
|
|
@@ -20,7 +20,7 @@ module Spree
|
|
|
20
20
|
entry = ResourceMap.find(resource)
|
|
21
21
|
return unknown_resource(resource) if entry.nil?
|
|
22
22
|
return { error: "You do not have permission to read #{entry.key}." } unless
|
|
23
|
-
|
|
23
|
+
entry.readable_by?(context)
|
|
24
24
|
|
|
25
25
|
return { error: "#{entry.key} cannot be fetched one at a time." } if entry.api_path(:show).blank?
|
|
26
26
|
|
|
@@ -46,7 +46,7 @@ module Spree
|
|
|
46
46
|
# own words. This check only avoids offering a tool that cannot work
|
|
47
47
|
# — a resource the caller cannot even read.
|
|
48
48
|
return [nil, { error: "You do not have permission to change #{entry.key}." }] unless
|
|
49
|
-
|
|
49
|
+
entry.readable_by?(context)
|
|
50
50
|
|
|
51
51
|
[entry, nil]
|
|
52
52
|
end
|
|
@@ -9,7 +9,8 @@ module Spree
|
|
|
9
9
|
# reported it as a fact.
|
|
10
10
|
class SearchResources < Spree::AgentTool
|
|
11
11
|
DEFAULT_LIMIT = 10
|
|
12
|
-
|
|
12
|
+
# The Admin API's own page ceiling; asking for more returns this many.
|
|
13
|
+
MAX_LIMIT = 100
|
|
13
14
|
|
|
14
15
|
tool_name 'search_resources'
|
|
15
16
|
description 'Search the store. Filters are Ransack predicates ' \
|
|
@@ -24,15 +25,18 @@ module Spree
|
|
|
24
25
|
|
|
25
26
|
param :resource, description: 'Resource key — call describe_resource for the list', required: true
|
|
26
27
|
param :filters, type: :object, description: 'Ransack filter hash, e.g. {"name_cont": "shirt"}'
|
|
27
|
-
param :sort, description: 'Sort, e.g. "created_at
|
|
28
|
-
param :limit, type: :integer,
|
|
28
|
+
param :sort, description: 'Sort field, prefixed with - for descending, e.g. "-created_at" for newest first'
|
|
29
|
+
param :limit, type: :integer,
|
|
30
|
+
description: "Records per page (default #{DEFAULT_LIMIT}, at most #{MAX_LIMIT}). " \
|
|
31
|
+
'When total exceeds count, pass next_page as page to fetch the rest.'
|
|
32
|
+
param :page, type: :integer, description: 'Page number, starting at 1 (default 1)'
|
|
29
33
|
param :parent_id, description: PARENT_ID_DESCRIPTION
|
|
30
34
|
|
|
31
|
-
def call(resource:, filters: nil, sort: nil, limit: nil, parent_id: nil)
|
|
35
|
+
def call(resource:, filters: nil, sort: nil, limit: nil, page: nil, parent_id: nil)
|
|
32
36
|
entry = ResourceMap.find(resource)
|
|
33
37
|
return unknown_resource(resource) if entry.nil?
|
|
34
38
|
return not_searchable(entry) if entry.api_path(:index).blank?
|
|
35
|
-
return forbidden(entry) unless
|
|
39
|
+
return forbidden(entry) unless entry.readable_by?(context)
|
|
36
40
|
|
|
37
41
|
applied = sanitize_filters(filters)
|
|
38
42
|
# Ransack drops a filter it does not recognise and returns the whole
|
|
@@ -44,9 +48,10 @@ module Spree
|
|
|
44
48
|
return invalid_filters(entry, unrecognised) if unrecognised.any?
|
|
45
49
|
|
|
46
50
|
path = entry.path_for(:index, parent_id: parent_id)
|
|
51
|
+
return wrong_parent(entry, parent_id) if path.nil? && parent_id.present? && !entry.nested?(:index)
|
|
47
52
|
return not_searchable(entry) if path.nil?
|
|
48
53
|
|
|
49
|
-
response = dispatch.call(method: :get, path: path, params: query_for(applied, sort, limit))
|
|
54
|
+
response = dispatch.call(method: :get, path: path, params: query_for(applied, sort, limit, page))
|
|
50
55
|
return { error: response.error_message } unless response.success?
|
|
51
56
|
|
|
52
57
|
rows = Array(response.data)
|
|
@@ -59,8 +64,13 @@ module Spree
|
|
|
59
64
|
# for a store holding hundreds.
|
|
60
65
|
total: meta['count'] || rows.size,
|
|
61
66
|
count: rows.size,
|
|
67
|
+
page: meta['page'],
|
|
68
|
+
pages: meta['pages'],
|
|
69
|
+
# Named outright, because a model told only "25 of 88" reports the
|
|
70
|
+
# 25 as the answer.
|
|
71
|
+
next_page: meta['next'],
|
|
62
72
|
records: rows.map { |row| RecordSummary.from_payload(entry: entry, payload: row) }
|
|
63
|
-
}
|
|
73
|
+
}.compact
|
|
64
74
|
end
|
|
65
75
|
|
|
66
76
|
def summary(arguments)
|
|
@@ -81,13 +91,24 @@ module Spree
|
|
|
81
91
|
# Ransack filters travel under `q`, the way every other client sends
|
|
82
92
|
# them — so an unknown one is refused by the API's own filter
|
|
83
93
|
# validation rather than silently widening the search here.
|
|
84
|
-
def query_for(filters, sort, limit)
|
|
85
|
-
params = { limit: capped_limit(limit) }
|
|
94
|
+
def query_for(filters, sort, limit, page)
|
|
95
|
+
params = { limit: capped_limit(limit), page: [page.to_i, 1].max }
|
|
86
96
|
params[:q] = filters if filters.any?
|
|
87
|
-
params[:sort] = sort if sort.present?
|
|
97
|
+
params[:sort] = api_sort(sort) if sort.present?
|
|
88
98
|
params
|
|
89
99
|
end
|
|
90
100
|
|
|
101
|
+
# The API reads `-field` for descending. Models also write Ransack's
|
|
102
|
+
# `field desc`, which reached the API as `field desc asc` and sorted
|
|
103
|
+
# ascending, so a request for the newest records paged through the
|
|
104
|
+
# oldest.
|
|
105
|
+
def api_sort(sort)
|
|
106
|
+
sort.to_s.split(',').map do |part|
|
|
107
|
+
field, direction = part.strip.split(/\s+/, 2)
|
|
108
|
+
direction.to_s.casecmp?('desc') ? "-#{field.delete_prefix('-')}" : field
|
|
109
|
+
end.join(',')
|
|
110
|
+
end
|
|
111
|
+
|
|
91
112
|
# Empty values match everything, so they are dropped — but `false` is a
|
|
92
113
|
# real filter value (`{"out_of_stock": false}`), which `compact_blank`
|
|
93
114
|
# would have thrown away.
|
|
@@ -141,6 +162,17 @@ module Spree
|
|
|
141
162
|
{ error: "You do not have permission to read #{entry.key}." }
|
|
142
163
|
end
|
|
143
164
|
|
|
165
|
+
# A parent the resource is not listed under is refused rather than
|
|
166
|
+
# dropped: dropped, the search listed the whole store and the model
|
|
167
|
+
# reported every claim as the one order's.
|
|
168
|
+
def wrong_parent(entry, parent_id)
|
|
169
|
+
parents = entry.index_parents.keys.sort
|
|
170
|
+
return { error: "#{entry.key} are not listed under another record. Search without parent_id and use filters." } if parents.empty?
|
|
171
|
+
|
|
172
|
+
{ error: "#{entry.key} cannot be listed under #{parent_id}. Pass the id of one of: #{parents.join(', ')}.",
|
|
173
|
+
parents: parents }
|
|
174
|
+
end
|
|
175
|
+
|
|
144
176
|
# A resource reached only under a parent, or one whose controller
|
|
145
177
|
# resolves its scope per request. Named rather than guessed at, because
|
|
146
178
|
# a tool cannot invent the parent id such a path needs.
|
|
@@ -16,11 +16,19 @@ module Spree
|
|
|
16
16
|
# surface only (draft orders); refused once the order is placed.
|
|
17
17
|
def perform(variant:, cart: nil, order: nil, quantity: nil, metadata: {}, options: {}, price: nil)
|
|
18
18
|
if order
|
|
19
|
-
Spree::Deprecation.warn('Calling Spree::Carts::AddItem with order: is deprecated and will be removed in Spree 6.
|
|
19
|
+
Spree::Deprecation.warn('Calling Spree::Carts::AddItem with order: is deprecated and will be removed in Spree 6.3. Pass cart: instead.')
|
|
20
20
|
cart ||= order
|
|
21
21
|
end
|
|
22
22
|
super(cart: cart, variant: variant, quantity: quantity, metadata: metadata, options: options, price: price)
|
|
23
23
|
|
|
24
|
+
# First, before anything is priced or reserved: a cart whose
|
|
25
|
+
# completion is in flight (or retained behind a payment-covered draft
|
|
26
|
+
# or a divided checkout) must not change under the purchase it
|
|
27
|
+
# supplied. The Store API fences this under its cart lock; a direct
|
|
28
|
+
# call to this workflow has to answer the same way rather than fall
|
|
29
|
+
# through to Reserve and report a misleading stock shortage.
|
|
30
|
+
step :guard_completion_claim
|
|
31
|
+
|
|
24
32
|
step :parse_manual_price unless price.nil?
|
|
25
33
|
|
|
26
34
|
# Core behaviour rather than a hook: an agreement's quantity terms are
|
|
@@ -43,6 +51,10 @@ module Spree
|
|
|
43
51
|
external_step :resolve_price if price.nil?
|
|
44
52
|
|
|
45
53
|
ApplicationRecord.transaction do
|
|
54
|
+
# Again under the row lock: the external steps above can take a
|
|
55
|
+
# while, and a completion may have claimed the cart since the
|
|
56
|
+
# first check read it.
|
|
57
|
+
step :guard_completion_claim_in_lock
|
|
46
58
|
step :add_to_line_item
|
|
47
59
|
step :handle_stock_reservations if cart.in_checkout?
|
|
48
60
|
step :recalculate, with: -> { Spree.cart_recalculate_workflow }
|
|
@@ -54,6 +66,45 @@ module Spree
|
|
|
54
66
|
|
|
55
67
|
private
|
|
56
68
|
|
|
69
|
+
# Draft orders (the admin path) carry no completion claim — only a cart
|
|
70
|
+
# does. Read from a fresh copy of the row, not the caller's instance:
|
|
71
|
+
# that one may predate the claim, and may carry in-memory changes the
|
|
72
|
+
# workflow must keep. The error matches the Store API's lock fence so a
|
|
73
|
+
# caller can treat both entry points alike.
|
|
74
|
+
def guard_completion_claim
|
|
75
|
+
return unless guarded_cart?
|
|
76
|
+
return unless completion_holds?(Spree::Cart.find(cart.id))
|
|
77
|
+
|
|
78
|
+
reject_claimed_cart
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Again under the row lock: the external steps can take a while, and a
|
|
82
|
+
# completion may have claimed — or finished — the cart since the first
|
|
83
|
+
# check. A no-op wait on the Store API path, which already holds this
|
|
84
|
+
# lock. +lock.find+ rather than +lock!+, which refuses to discard the
|
|
85
|
+
# caller's in-memory changes (pricing warnings).
|
|
86
|
+
def guard_completion_claim_in_lock
|
|
87
|
+
return unless guarded_cart?
|
|
88
|
+
return unless completion_holds?(Spree::Cart.lock.find(cart.id))
|
|
89
|
+
|
|
90
|
+
reject_claimed_cart
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def guarded_cart?
|
|
94
|
+
cart.is_a?(Spree::Cart) && cart.persisted?
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Finalize clears the claim as it stamps +completed_at+, so a finished
|
|
98
|
+
# cart answers false to +completion_claimed?+ and has to be refused on
|
|
99
|
+
# its own.
|
|
100
|
+
def completion_holds?(fresh_cart)
|
|
101
|
+
fresh_cart.completed_at.present? || fresh_cart.completion_claimed?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def reject_claimed_cart
|
|
105
|
+
failure(cart, code: 'completion_in_progress', message: I18n.t('spree.cart_completion_in_progress'))
|
|
106
|
+
end
|
|
107
|
+
|
|
57
108
|
# finite? is not redundant: BigDecimal parses "NaN" and "Infinity" and
|
|
58
109
|
# neither is negative. reject! rather than failure(cart, message), which
|
|
59
110
|
# would drop the message.
|
|
@@ -110,7 +110,7 @@ module Spree
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
finalize!(cart, result)
|
|
113
|
-
halt!(result)
|
|
113
|
+
halt!(order_group || result)
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
# The split already ran, so the money and the division are settled — what
|
|
@@ -233,6 +233,7 @@ module Spree
|
|
|
233
233
|
ApplicationRecord.transaction do
|
|
234
234
|
order.payments.update_all(order_id: nil, cart_id: cart.id)
|
|
235
235
|
order.payment_sessions.update_all(order_id: nil, cart_id: cart.id)
|
|
236
|
+
repoint_reservation_lines!(order, @copied_line_items.invert)
|
|
236
237
|
order.stock_reservations.update_all(order_id: nil, cart_id: cart.id)
|
|
237
238
|
Spree::CouponCode.where(order_id: order.id).update_all(order_id: nil, cart_id: cart.id)
|
|
238
239
|
order.reload.destroy!
|
|
@@ -284,7 +285,11 @@ module Spree
|
|
|
284
285
|
)
|
|
285
286
|
order.save!
|
|
286
287
|
|
|
288
|
+
# Copied lines validate against the new order, so its own holds must already belong to it.
|
|
289
|
+
cart.stock_reservations.update_all(order_id: order.id, cart_id: nil)
|
|
287
290
|
line_item_map = copy_line_items!(cart, order)
|
|
291
|
+
@copied_line_items = line_item_map
|
|
292
|
+
repoint_reservation_lines!(order, line_item_map)
|
|
288
293
|
fulfillment_map = copy_fulfillments!(cart, order, line_item_map)
|
|
289
294
|
fee_map = copy_typed_lines!(cart, order, line_item_map, fulfillment_map)
|
|
290
295
|
copy_promotions!(cart, order)
|
|
@@ -312,6 +317,14 @@ module Spree
|
|
|
312
317
|
order
|
|
313
318
|
end
|
|
314
319
|
|
|
320
|
+
# Seller splitting follows the copied line ids. Compensation applies the
|
|
321
|
+
# inverse map before deleting those copies, keeping the cart's holds alive.
|
|
322
|
+
def repoint_reservation_lines!(order, line_item_map)
|
|
323
|
+
line_item_map.each do |source, target|
|
|
324
|
+
order.stock_reservations.where(line_item_id: source.id).update_all(line_item_id: target.id)
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
315
328
|
# Freezes the buyer's tax registration onto the order, stamped with which
|
|
316
329
|
# link of the chain won. A copy rather than a reference: the customer can
|
|
317
330
|
# change or withdraw the number later, and the placed order's tax still
|
|
@@ -524,7 +537,6 @@ module Spree
|
|
|
524
537
|
def repoint_money_records!(cart, order)
|
|
525
538
|
cart.payments.update_all(order_id: order.id, cart_id: nil)
|
|
526
539
|
cart.payment_sessions.update_all(order_id: order.id, cart_id: nil)
|
|
527
|
-
cart.stock_reservations.update_all(order_id: order.id, cart_id: nil)
|
|
528
540
|
Spree::CouponCode.where(cart_id: cart.id).update_all(order_id: order.id, cart_id: nil)
|
|
529
541
|
order.payments.reset
|
|
530
542
|
end
|
|
@@ -13,7 +13,7 @@ module Spree
|
|
|
13
13
|
# for callers that are removing a promotion's effects
|
|
14
14
|
def perform(cart: nil, order: nil, line_item: nil, line_item_created: false, options: {})
|
|
15
15
|
if order
|
|
16
|
-
Spree::Deprecation.warn('Calling Spree::Carts::Recalculate with order: is deprecated and will be removed in Spree 6.
|
|
16
|
+
Spree::Deprecation.warn('Calling Spree::Carts::Recalculate with order: is deprecated and will be removed in Spree 6.3. Pass cart: instead.')
|
|
17
17
|
cart ||= order
|
|
18
18
|
end
|
|
19
19
|
super(cart: cart, line_item: line_item, line_item_created: line_item_created, options: options)
|