Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Keep a blank restatement from sending the provider into the transaction

Damian Legawiec4d82d46085bc
diff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rb
index fa476a9ba8..6c4970c5d3 100644
--- a/spree/core/app/models/spree/order.rb
+++ b/spree/core/app/models/spree/order.rb
@@ -553,7 +553,18 @@ module Spree
tax_provider.estimate(self, fulfillments.to_a, **tax_estimate_inputs) if fulfillments.any?
end
+ # Re-prices every line from the catalog.
+ #
+ # A completed order's money is frozen — re-pricing would rewrite what the
+ # customer was actually charged — so this refuses rather than reporting a
+ # success it did not deliver. Post-placement price changes belong to the
+ # order-change substrate (docs/plans/6.1-order-change-substrate.md).
+ #
+ # @raise [RuntimeError] when the order is already completed
+ # @return [void]
def update_line_item_prices!
+ raise 'cannot re-price a completed order' if completed?
+
transaction do
line_items.reload.each(&:update_price)
save!
diff --git a/spree/core/app/services/spree/carts/price_items.rb b/spree/core/app/services/spree/carts/price_items.rb
index d407d70696..ba21d86d40 100644
--- a/spree/core/app/services/spree/carts/price_items.rb
+++ b/spree/core/app/services/spree/carts/price_items.rb
@@ -58,13 +58,15 @@ module Spree
amount = price.price_including_vat_for(
address: owner&.tax_address, country: owner&.tax_country, market: owner&.market
)
+ # Marked before the blank guard: the provider has already answered,
+ # so a restatement that comes back blank must still not send the
+ # after_save callback back to the provider from inside the caller's
+ # transaction. Only the assign-for-a-coming-save case needs it — a
+ # persisted write goes through update_columns and fires no callbacks.
+ line_item.price_resolved = true unless persist
next if amount.blank?
line_item.assign_attributes(price: amount, price_list_id: price.price_list_id, price_source: source)
- # Only the assign-for-a-coming-save case marks the line: the caller
- # is about to save it, and that save must not re-price. A persisted
- # write goes through update_columns and fires no callbacks.
- line_item.price_resolved = true unless persist
next unless persist && line_item.persisted? && line_item.changed?
line_item.update_columns(line_item.changes.transform_values(&:last).merge(updated_at: Time.current))